1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072 |
- <?php
- /**
- * 打印管理控制器类
- * @author jiangfei
- * @date 2015-07-22 17:50:00
- * @company 上海风车教育有限公司.
- */
- class PrintController extends Controller{
- public function actionIndex()
- {
- //初始化
- $exam_group_ids = array();
- $exam_ids = array();
- $_exam_ids = array();
- $_exam_group_ids = array();
- $exam_printer_num = array();
- $exam_use_wp = array();
- $data = array();
- $condition = array();
- $paper_exam = array();
- $class_exam = array();
- $class_ids = array();
- $class_grade_arr = array();
- $paper_arr = array();
- $paper_labelled_type_arr = array();
- //筛选条件
- $printName = Req::get("name");
- $grade = Req::get("grade");
- $labelled = Req::get("labelled");
- $display = Req::get("display");
- $type = Req::get("type");
- $teacherId = Req::get("teacher_id");
- // 发送标注条件
- if($labelled>-1)
- {
- $paper_exam = $this->schoolManager->getPaerLabelledByExam($labelled);
- if($paper_exam)
- {
- foreach($paper_exam as $v)
- {
- $s_exam_ids[$v['exam_id']] = $v['exam_id'];
- }
- }
- unset($paper_exam);
- }
- // 年级条件
- if($grade>0)
- {
- $class_data = $this->schoolManager->getSchoolByGrade($grade,$this->semesterId);
- if($class_data)
- {
- foreach($class_data as $v)
- {
- $class_ids[$v['class_id']] = $v['class_id'];
- }
- $exam_class_data = $this->schoolManager->getClassIdByExam($class_ids);
- if($exam_class_data)
- {
- foreach($exam_class_data as $v)
- {
- if(isset($s_exam_ids[$v['exam_id']]))
- {
- $l_b_exam_ids[$v['exam_id']] = $v['exam_id'];
- }else
- {
- $s_exam_ids[$v['exam_id']] = $v['exam_id'];
- }
- }
- }
- unset($exam_class_data);
- }
- unset($class_data);
- }
- if(isset($l_b_exam_ids))
- {
- if($l_b_exam_ids)
- {
- $condition[] = "e.exam_id in (".implode(',',$l_b_exam_ids).")";
- }else
- {
- $condition[] = "e.exam_id in (0)";
- }
- }else
- {
- if($labelled<0||$grade<1)
- {
- if(isset($s_exam_ids))
- {
- if($s_exam_ids)
- {
- $condition[] = "e.exam_id in (".implode(',',$s_exam_ids).")";
- }else
- {
- $condition[] = "e.exam_id in (0)";
- }
- }
- }else
- {
- $condition[] = "e.exam_id in (0)";
- }
- }
- // 多学科切换条件
- if(in_array($this->subjectId,$this->mathSubjectId)){
- $condition[] = "e.subject_id in (".implode(',',$this->mathSubjectId).")";
- }else{
- $condition[] = "e.subject_id = '{$this->subjectId}'";
- }
- if ( $display == 1) {
- $condition[] = "e.is_display = 1";
- }else
- {
- $condition[] = "e.is_display = 0";
- }
- $TeacherModel=new Teacher();
- // 考试名称条件
- if($printName)
- {
- //查询教师id
- $teacherIds=$TeacherModel->getTeacherIdByName($printName);
- if($teacherIds){
- $condition[] = " (e.name like '%{$printName}%' or eg.teacher_id in(".implode(',',$teacherIds)."))";
- }else{
- $condition[] = "e.name like '%{$printName}%'";
- }
- }
- $condition[] = "eg.is_third = 0";
- $condition[] = "eg.create_type in (0,1,2,3,5,6) ";
- $condition[] = "eg.is_united = 0";
- // $condition[] = "eg.homework = 0";
- $teachers_data = Teacher::model()->findAll();
- $class_teacher_data = array();
- $teacherNames=array();
- if($teachers_data) {
- foreach ($teachers_data as $k => $v) {
- $teacherNames[$v->teacher_id] = $v->teacher_name;
- }
- }
- $gradeCardLength=array();
- $gradeData=SGrade::model()->findAll();
- foreach ($gradeData as $datum){
- if($datum->card_status==1){
- $gradeCardLength[$datum->id]=$datum->card_length;
- }else{
- $gradeCardLength[$datum->id]=0;
- }
- }
- //获取考试列表
- $exam_list = $this->schoolManager->getPrintGroupList($condition,array('e.create_time desc'),12);
- //获取打印班级
- if($exam_list)
- {
- //查询教师
- $ExamModel=new Exam();
- $StudentPaperRelation=new SStudentPaperRelation();
- foreach($exam_list['rs'] as $key=>$v)
- {
- $items = array();
- $tpl_data=array();
- $exam_group_ids[$v['exam_group_id']] = $v['exam_group_id'];
- $exam_list['rs'][$key]['is_tpl'] = 0; // 需要上传模板
- $exam_list['rs'][$key]['is_custom_optional_topic'] = 0;
- $exam_list['rs'][$key]['is_paper_49'] = 0;
- //准考证
- if(!$v['school_card_status']){
- $exam_list['rs'][$key]['school_card_length'] = $gradeCardLength[$v['grade']];
- }
- if(isset($teacherNames[$v['teacher_id']])){
- $exam_list['rs'][$key]['teacher_name'] = $teacherNames[$v['teacher_id']];
- }else{
- $exam_list['rs'][$key]['teacher_name'] = '';
- }
- if(isset($v['tpl_data'])){
- $tpl_data = json_decode($v['tpl_data'],1);
- //标注期望完成时间
- if(isset($tpl_data['estimateTime']))
- {
- $exam_list['rs'][$key]['estimate_time'] = date('Y-m-d H:i:s',$tpl_data["estimateTime"]);
- }
- }
- if(isset($tpl_data['branch'])){
- $exam_list['rs'][$key]['branch'] = $tpl_data['branch'];
- }else{
- $exam_list['rs'][$key]['branch'] =0;
- }
- if(in_array($v['tpl_index'], Yii::app()->params['custom_tpls_ids'])){
- //自定义模板
- $exam_list['rs'][$key]['is_custom_tpl'] = true;
- if(isset($tpl_data['items']) && isset($tpl_data['items'][17])){
- $exam_list['rs'][$key]['is_custom_optional_topic'] = 1;
- }
- $v['is_custom_tpl'] = true;
- }else{
- //非自定义模板
- $exam_list['rs'][$key]['is_custom_tpl'] = false;
- $v['is_custom_tpl'] = false;
- }
- if (in_array($v['tpl_index'], Yii::app()->params['no_template_id']) || $v['is_custom_tpl']) {
- $exam_list['rs'][$key]['is_tpl'] = 1;
- //题卡分离
- $exam_list['rs'][$key]['paper_tpl_type'] = 2;
- }else{
- $exam_list['rs'][$key]['paper_tpl_type'] = 1;
- }
- if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl']))
- {
- $exam_list['rs'][$key]['paper_tpl_type'] = 3;
- if($v['tpl_index'] == 9 )
- {
- $exam_list['rs'][$key]['paper_tpl_type'] = 4;
- }
- }
- if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl_all']))
- {
- $exam_list['rs'][$key]['paper_tpl_type'] = 3;
- if($v['tpl_index'] == 9 )
- {
- $exam_list['rs'][$key]['paper_tpl_type'] = 4;
- }
- }
- if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl7']))
- {
- $exam_list['rs'][$key]['is_paper_49'] = 1;
- }
- if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl8']))
- {
- $exam_list['rs'][$key]['is_paper_49'] = 1;
- }
- if(in_array($v['tpl_index'],Yii::app()->params['template_id_qrcode']))
- {
- $exam_list['rs'][$key]['qrcode'] = 1;
- }else{
- $exam_list['rs'][$key]['qrcode'] = 0;
- }
- //判断是否已上传成绩
- $exam_list['rs'][$key]['is_feedback']=0;
- $exam=$ExamModel->getExamIds($v['exam_group_id']);
- if($exam){
- if($StudentPaperRelation->getStudentFeedBack($exam)){
- $exam_list['rs'][$key]['is_feedback']=1;
- }
- }
- //是否使用在线答题卡
- $exam_list['rs'][$key]['third_card']=0;
- $exam_list['rs'][$key]['online_card']=0;
- $exam_list['rs'][$key]['is_qrcode_online']=0;
- $exam_list['rs'][$key]['marking_papers']=0;
- $studentAnswerOnline=$this->schoolManager->getAnswerSheet($v['exam_group_id']);
- if($studentAnswerOnline){
- if($studentAnswerOnline['online_card']==1){
- $exam_list['rs'][$key]['online_card']=$studentAnswerOnline['online_card'];
- $exam_list['rs'][$key]['is_qrcode_online']=$studentAnswerOnline['is_qrcode_online'];
- $exam_list['rs'][$key]['marking_papers']=$studentAnswerOnline['marking_papers'];
- if($studentAnswerOnline['paper_size']==1){
- $exam_list['rs'][$key]['paper_size']='A3';
- }elseif($studentAnswerOnline['paper_size']==2){
- $exam_list['rs'][$key]['paper_size']='A4';
- }elseif($studentAnswerOnline['paper_size']==3){
- $exam_list['rs'][$key]['paper_size']='16K';
- }elseif($studentAnswerOnline['paper_size']==4){
- $exam_list['rs'][$key]['paper_size']='8K';
- }elseif($studentAnswerOnline['paper_size']==5){
- $exam_list['rs'][$key]['paper_size']='8K';
- }
- }else{
- $exam_list['rs'][$key]['third_card']=1;
- }
- }
- }
- //获取考试ID
- $criteria = new CDbCriteria();
- $criteria->select = 'exam_id,exam_group_id';
- $criteria->addInCondition('exam_group_id',$exam_group_ids);
- $exam_data = Exam::model()->findAll($criteria);
- unset($criteria);
- unset($exam_group_ids);
- if($exam_data)
- {
- foreach($exam_data as $v)
- {
- //$exam_use_wp
- $exam_ids[$v->exam_id] = $v->exam_id;
- $_exam_group_ids[$v->exam_group_id][$v->exam_id] = $v->exam_id;
- $_exam_ids[$v->exam_id] = $v->exam_group_id;
- }
- unset($exam_data);
- //通过考试ID,获取打印班级
- $criteria = new CDbCriteria();
- $criteria->select = 'exam_id,class_id,is_print,is_print_online';
- $criteria->addInCondition('exam_id',$exam_ids);
- $criteria->addCondition('is_print = 1 or is_print_online=1');
- $class_print_data = ClassExamPrinter::model()->findAll($criteria);
- if($class_print_data)
- {
- foreach($class_print_data as $v)
- {
- if( isset($_exam_ids[$v->exam_id]))
- {
- if($v->is_print==1){
- $exam_printer_num['word'][$_exam_ids[$v->exam_id]][$v->exam_id] = $v->exam_id;
- }
- if($v->is_print_online==1){
- $exam_printer_num['online'][$_exam_ids[$v->exam_id]][$v->exam_id] = $v->exam_id;
- }
- }
- }
- }
- unset($criteria);
- unset($class_print_data);
- }
- }
- //获取班级年级
- $class_data = ClassModel::model()->findAll('semester_id=:semester_id',array(':semester_id'=>$this->semesterId));
- if($class_data)
- {
- foreach($class_data as $v)
- {
- $class_grade_arr[$v->class_id] = $v->grade;
- }
- }
- unset($class_data);
- //获取试卷标注状态
- $criteria = new CDbCriteria();
- $criteria->select = 'exam_id,is_labelled,labelled_type';
- $criteria->addInCondition('exam_id',$exam_ids);
- $paper_data = SPaper::model()->findAll($criteria);
- unset($criteria);
- if($paper_data)
- {
- foreach($paper_data as $v)
- {
- if( isset($_exam_ids[$v->exam_id]))
- {
- $paper_arr[$_exam_ids[$v->exam_id]] = $v->is_labelled;
- $paper_labelled_type_arr[$_exam_ids[$v->exam_id]] = $v->labelled_type;
- }
- }
- }
- //获取产品设置版本
- $productEdition=$this->sConn->createCommand("select switch from producut_set_edition where id=1")->queryRow();
- if(!$productEdition || $productEdition['switch']==2){
- $data['productSwitch']=2;
- }else{
- $data['productSwitch']=3;
- }
- // 获取多学科状态
- // $subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId);
- $findSchool = BusinessSchool::model()->find('school_id=:scid',array(':scid'=>Yii::app()->session['coachInfo']['school_id']));
- $data['pages'] = $exam_list['pager'];
- $data['page_total'] = $exam_list['pager']->rowsCount;
- $data['printList'] = $exam_list['rs'];
- $data['printer'] = $exam_printer_num;
- $data['exam_class'] = $_exam_group_ids;
- //$data["subject"] = $subject_exam_data;
- $data["exam_use_wp"] = $findSchool->use_wp;
- $data["display"] = $display;
- $data["labelled"] = $labelled;
- $data["grade"] = $grade;
- $data["printName"] = $printName;
- $data["paper"] = $paper_arr;
- $data["paper_labelled_type"] = $paper_labelled_type_arr;
- $data["class_grade"] = $class_grade_arr;
- $data["printType"] = $type;
- $data['teacherNames']=$teacherNames;
- $data["teacherId"] = $teacherId;
- //获取导出数据白名单
- $data["exportExam"] = $this->schoolManager->getExportExamWhiteList($this->schoolId);;
- $this->render('group_list',$data);
- }
- public function actionClass_exam()
- {
- $condition = array();
- $exam_ids = array();
- $exam_id = '';
- $exam_name = '';
- $class_names = array();
- $class_ids = array();
- $class_print = array();
- $class_online_print = array();
- $data = array();
- $exam_student_up_num = array();
- $exam_student_num = array();
- $student_img_up_num = array();//学生答题原图
- $class_name = Req::get("class_name");
- $exam_group_id = Req::get("exam_group_id");
- $masttype = (int)Req::get("masttype");
- $is_united = (int)Req::get('is_united');
- $grade = Req::get('grade');
- $branch = Req::get('branch');
- $multiple_choice_required=0; //多选题必选数量
- $exam_date=''; //考试日期
- $exam_uploaded=0;
- if($exam_group_id <= 0)
- {
- Yii::app()->jump->error('未找到考试信息!');
- }
- $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- if(!$exam_group_data)
- {
- Yii::app()->jump->error('未找到考试信息!');
- }
- if($exam_group_data->upload_status>0){
- $exam_uploaded=1;
- }
- $condition[] = "exam_group_id = ".$exam_group_id;
- //获取班级信息
- $class_data = $this->schoolManager->getSemesterClasses($this->semesterId);
- $class_types=array();
- if($class_data)
- {
- foreach($class_data as $v)
- {
- if($class_name && $v['class_name'] == $class_name)
- {
- $class_ids[$v['class_id']] = $v['class_id'];
- }
- $class_names[$v['class_id']] = $v['class_name'];
- if($v['class_type']==1){
- $class_types[$v['class_id']]='行政班';
- }elseif($v['class_type']==2){
- $class_types[$v['class_id']]='教学班';
- }
- }
- }
- //debug($class_data);
- if($class_ids)
- {
- $condition[] = "class_id in (".implode(',',$class_ids).") ";
- }
- // 多学科切换条件
- if(in_array($this->subjectId,$this->mathSubjectId)){
- $condition[] = "subject_id in (".implode(',',$this->mathSubjectId).")";
- }else{
- $condition[] = "subject_id = '{$this->subjectId}'";
- }
- if($class_ids)
- {
- $condition[] = "class_id in (".implode(',',$class_ids).") ";
- }
- //获取考试列表
- $exam_data = $this->schoolManager->getExamsByExamGroupIdList($condition,array('exam_id desc'),12);
- if($exam_data['rs'])
- {
- foreach($exam_data['rs'] as $k=>$v)
- {
- $exam_ids[$v['exam_id']] = $v['exam_id'];
- $exam_id = $v['exam_id'];
- $exam_name = $v['print_name'];
- }
- }else
- {
- Yii::app()->jump->error('未找到考试信息!');
- }
- //获取班级考试是否打印
- $criteria = new CDbCriteria();
- $criteria->addInCondition('exam_id',$exam_ids);
- $criteria->addCondition('type = 0');
- $class_print_data = ClassExamPrinter::model()->findAll($criteria);
- if($class_print_data)
- {
- foreach($class_print_data as $v)
- {
- $class_print[$v->exam_id] = $v->is_print;
- $class_online_print[$v->exam_id] = $v->is_print_online;
- }
- }
- unset($criteria);
- unset($class_print_data);
- //获取班级考试的上传成绩
- $criteria = new CDbCriteria();
- $criteria->select= 'student_id,is_feedback,exam_id,student_img_paper';
- $criteria->addInCondition('exam_id',$exam_ids);
- $criteria->addCondition('is_del = 0');
- $student_paper_data = SStudentPaperRelation::model()->findAll($criteria);
- if($student_paper_data)
- {
- foreach($student_paper_data as $v)
- {
- if($v->is_feedback)
- {
- $exam_student_up_num[$v->exam_id][$v->student_id] = $v->student_id;
- }
- $exam_student_num[$v->exam_id][$v->student_id] = $v->student_id;
- if (!isset($student_img_up_num[$v->exam_id])) {
- $student_img_up_num[$v->exam_id] = array();
- }
- if (trim($v['student_img_paper'])) {
- $student_img_up_num[$v->exam_id][$v->student_id] = $v->student_id;
- }
- }
- }
- unset($criteria);
- unset($student_paper_data);
- //获取paper
- $paperIds=array();
- $criteria = new CDbCriteria();
- $criteria->addInCondition('exam_id',$exam_ids);
- $paperData = SPaper::model()->findAll($criteria);
- if($paperData)
- {
- foreach($paperData as $v)
- {
- $paperIds[$v->exam_id] = $v->paper_id;
- }
- }
- unset($criteria);
- unset($exam_ids);
- $student_answer_img_num=array();
- foreach($exam_student_up_num as $eid =>$sids){
- $student_answer_img_num[$eid]=$this->schoolManager->getUpAnswerStudent($paperIds[$eid],$sids,true);
- }
- //获取paper 表数据
- $paper_data = SPaper::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id));
- if(!$paper_data)
- {
- Yii::app()->jump->error('未找到考试信息!');
- }
- //读取试题数据
- $isAllSelect=1; //全部客观题判断
- $paperTopic=SPaperTopicRelation::model()->findAll('paper_id=:paper_id',array(':paper_id'=>$paper_data->paper_id));
- if(!$paperTopic){
- Yii::app()->jump->error('未找到考试信息!');
- }
- //选择题类型判断
- $allSubjectType=array();
- if($exam_group_data['qxk_paper_id']>0){
- $allSubjectType=array(1,2,3,4,12);
- }else{
- $allSubjectType=array(1,2,11);
- }
- foreach ($paperTopic as $item){
- if(!in_array($item->type,$allSubjectType)){
- $isAllSelect=0;
- break;
- }
- }
- $printList = array();
- $has_marked = false;
- $data['online_card'] = 0;
- $data['is_qrcode_online'] = 0;
- if($exam_data["rs"]){
- $studentAnswerOnline=$this->schoolManager->getAnswerSheet($exam_group_id);
- $studentAnswerCardOnline=new SStudentAnswerCardOnline();
- foreach ($exam_data['rs'] as $k=>$v) {
- $printList['is_tpl'] = 0; // 需要上传模板
- $printList['answer_card_uploaded'] = false;
- if(in_array($v['tpl_index'], Yii::app()->params['custom_tpls_ids'])){
- //自定义模板
- $printList['is_custom_tpl'] = true;
- $v['is_custom_tpl'] = true;
- }else{
- //非自定义模板
- $printList['is_custom_tpl'] = false;
- $v['is_custom_tpl'] = false;
- }
- if (in_array($v['tpl_index'], Yii::app()->params['no_template_id']) || $v['is_custom_tpl']) {
- $printList['is_tpl'] = 1;
- if(trim($paper_data->answer_card_src)){
- $printList['answer_card_uploaded'] = true;
- }
- //题卡分离
- $printList['paper_tpl_type'] = 2;
- }else{
- $printList['paper_tpl_type'] = 1;
- }
- if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl']))
- {
- $printList['paper_tpl_type'] = 3;
- if($v['tpl_index'] == 9 )
- {
- $printList['paper_tpl_type'] = 4;
- }
- }
- if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl_all']))
- {
- $printList['paper_tpl_type'] = 3;
- if($v['tpl_index'] == 9 )
- {
- $printList['paper_tpl_type'] = 4;
- }
- }
- //英语题卡分离一
- if($this->subjectId == 8){
- $printList['paper_tpl_type'] = 5;
- }
- if($v['status'] == 1){
- $has_marked = true;
- }
- //判断多选题
- if(!$multiple_choice_required){
- $tpl_data=json_decode($v['tpl_data'],true);
- if(isset($tpl_data['items'][17]) && isset($tpl_data['items'][17]['required']) ){
- $multiple_choice_required=$tpl_data['items'][17]['required'];
- }
- $exam_date=$tpl_data['examDate'];
- }
- //是否使用在线答题卡
- $exam_data['rs'][$k]['online_card']=0;
- $exam_data['rs'][$k]['is_qrcode_online']=0;
- if($studentAnswerOnline){
- $exam_data['rs'][$k]['online_card']=$studentAnswerOnline['online_card'];
- $exam_data['rs'][$k]['is_qrcode_online']=$studentAnswerOnline['is_qrcode_online'];
- $data['online_card'] = $studentAnswerOnline['online_card'];
- $data['is_qrcode_online'] = $studentAnswerOnline['is_qrcode_online'];
- if($studentAnswerOnline['online_card']==1){
- if($studentAnswerOnline['paper_size']==1){
- $exam_data['rs'][$k]['paper_size']='A3';
- }elseif($studentAnswerOnline['paper_size']==2){
- $exam_data['rs'][$k]['paper_size']='A4';
- }elseif($studentAnswerOnline['paper_size']==3){
- $exam_data['rs'][$k]['paper_size']='16K';
- }elseif($studentAnswerOnline['paper_size']==4){
- $exam_data['rs'][$k]['paper_size']='8K';
- }elseif($studentAnswerOnline['paper_size']==5){
- $exam_data['rs'][$k]['paper_size']='8K';
- }
- }
- if($studentAnswerOnline['online_card']==1 && $studentAnswerOnline['is_qrcode_online']==1){
- //查询生成数量
- $studentCardOnline= $studentAnswerCardOnline->getCountByExamId($v['exam_id']);
- if($studentCardOnline){
- $exam_data['rs'][$k]['card_created']=$studentCardOnline['count'];
- }
- }
- }
- }
- }
- //是否能添加班级 FIXME add_class_0924
- //打印中
- $enable_add_class = false;
- if($exam_group_data['status'] == 1 || $exam_group_data['mark_type'] ==0){
- $enable_add_class = true;
- }else{
- //混合阅卷
- if($exam_group_data['mark_type'] == 3){
- $enable_add_class = ($exam_group_data['mark_status']==2 && $exam_group_data['upload_status']== 2) ? false : true;
- }
- //单独阅卷
- if($exam_group_data['mark_type'] == 4){
- $enable_add_class = $has_marked ? false : true;
- }
- }
- //查询还原记录
- $examRestore=SExamRestore::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- if($examRestore){
- $data['restore'] = 1;
- }else{
- $data['restore'] = 0;
- }
- //读取试题推送设置
- $topicPushSettingModel=new SExamPushTopicsSetting();
- $topicPushSetting=$topicPushSettingModel->getTopicSetting($exam_group_id);
- $topicPushSettingRelation=array();
- if($topicPushSetting){
- foreach ($topicPushSetting as $item){
- if($item['topic_ids']){
- $topicSetting=json_decode($item['topic_ids'],true);
- if($topicSetting){
- $topicPushSettingRelation[(string)$item['exam_id']]=1;
- }
- }
- }
- }
- // 获取多学科状态
- //$subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId);
- $this->setIs_new($exam_group_id);
- $data['printList'] = $exam_data['rs'];
- $data['print'] = $printList;
- $data['pages'] = $exam_data['pager'];
- $data['page_total'] = $exam_data['pager']->rowsCount;
- $data["class_name"] = $class_name;
- $data["class_data"] = $class_names;
- $data["class_types"] = $class_types;
- $data["exam_group_data"] = $exam_group_data;
- //$data["subject"] = $subject_exam_data;
- $data["exam_id"] = $exam_id;
- $data["exam_name"] = $exam_name;
- $data["exam_print"] = $class_print;
- $data["exam_online_print"] = $class_online_print;
- $data["exam_student"] = $exam_student_num;
- $data["exam_up_student"] = $exam_student_up_num;
- $data["student_img_up_num"] = $student_img_up_num;
- $data["student_answer_img_num"] = $student_answer_img_num;
- $data["exam_group_id"] = $exam_group_id;
- $data["grade"] = $grade;
- $data["branch"] = $branch;
- $data["enable_add_class"] = $enable_add_class;
- $data["qxk_paper_id"] = $exam_group_data->qxk_paper_id;
- $data['exam_date']=$exam_date;
- $data['exam_uploaded']=$exam_uploaded;
- $data['topic_push_setting']=$topicPushSettingRelation;
- $data['is_all_select']=$isAllSelect;
- $data['qxk_paper_id']=$exam_group_data['qxk_paper_id'];
- //判断全学科白名單
- $data['new_answer_sheet_subject']=0;
- if($data['qxk_paper_id']){
- $rs = http('/cms/api/module-white-list/new_answer_sheet_subject/'.$this->subjectId,'GET',$this->schoolId,array(),'cgi');
- $rs=json_decode($rs,true);
- if(isset($rs['errCode']) && $rs['errCode']=='00' && $rs['data']==true){
- $data['new_answer_sheet_subject']=1;
- }
- }
- $data["subject"]=$this->subjectId;
- if($studentAnswerOnline){
- $data['online_card']=$studentAnswerOnline['online_card'];
- $data['is_qrcode_online']=$studentAnswerOnline['is_qrcode_online'];
- }
- if($multiple_choice_required>1){
- $data['noOnline']=1;
- }elseif(isset($exam_data['rs'][0]['paper_size']) && $exam_data['rs'][0]['paper_size']!='A3'){
- $data['noOnline']=2;
- }elseif($exam_group_data['mark_type']==0) {
- $data['noOnline'] = 3;
- }elseif($printList['paper_tpl_type'] == 1 || $printList['paper_tpl_type'] == 3){
- $data['noOnline'] = 4;
- }else{
- $data['noOnline']=0;
- }
- $data['online_token']=getOnlineToolToken($this->schoolId);
- $_num= '';
- $use_version = '';
- if(isset(Yii::app()->session['coachInfo']->use_version))
- {
- $use_version = Yii::app()->session['coachInfo']->use_version;
- }else
- {
- $use_version = Yii::app()->session['coachInfo']['use_version'];
- }
- if(!$use_version)
- {
- $use_version = 100;
- }
- $version_number = implode('',explode('.',$use_version));
- if(strlen($version_number)<7)
- {
- for($i=0;$i<7-strlen($version_number);$i++)
- {
- $_num.='0';
- }
- }
- $version_number=(int)$version_number.$_num;
- $data['version_number']=$version_number;
- if($is_united==1){
- $this->render('class_exam_united',$data);
- }else{
- $this->render('class_exam2',$data);
- }
- }
- // 打印列表
- public function actionSub_index(){
- Url::clean();
- $printName = Req::get("name");
- $classId = Req::get("classId");
- $printType = Req::get("type");
- $grade = Req::get("grade");
- $labelled = Req::get("labelled");
- $display = Req::get("display");
- $is_print = Req::get("is_print");
- if (empty($printType)) {
- $printType = 'wp';
- $printTypeData = 0;
- } else {
- switch ($printType) {
- case "wp":
- $printTypeData = 0;
- break;
- case "wtb":
- $printTypeData = 1;
- break;
- case "isp":
- $printTypeData = 2;
- break;
- case "studytrend":
- $printTypeData = 3;
- break;
- case "section":
- $printTypeData = 4;
- break;
- case "third_wb": //多学科错题本
- $printTypeData = 1;
- $this->subjectId = Yii::app()->session['session_duoxueke_subject_id'];
- break;
- case "third_isp": //多学科个性化学习宝
- $printTypeData = 3;
- $this->subjectId = Yii::app()->session['session_duoxueke_subject_id'];
- break;
- default:
- $printTypeData = null;
- break;
- }
- }
- $condition = array();
- if($is_print > -1)
- {
- $condition[] = "cep.is_print = '{$is_print}'";
- }else{
- $is_print = -1;
- }
- if($printName)
- $condition[] = "e.name like '%{$printName}%'";
- if(!Str::isBlank($printTypeData))
- $condition[] = "cep.type = '{$printTypeData}'";
- if($classId)
- $condition[] = "c.class_id = '{$classId}'";
- if ($grade) {
- $condition[] = "c.grade = '{$grade}'";
- }
- if (!Str::isBlank($labelled)) {
- $condition[] = "p.is_labelled = '{$labelled}'";
- }
- if ($printType=='wp' && $display != 1) {
- $condition[] = "e.is_display = '0'";
- }
- if(in_array($this->subjectId,$this->mathSubjectId)){
- $condition[] = "e.subject_id in (".implode(',',$this->mathSubjectId).")";
- }else{
- $condition[] = "e.subject_id = '{$this->subjectId}'";
- }
- $condition[] = "eg.create_type in (0,1,2,3,5,6) ";
- //$condition[] = "eg.homework = 0";
- //debug($condition);die;
- if (empty($grade)) {
- $grade = 'ALL';
- }
- $classes = $this->schoolManager->getClasses($grade);
- if($printType=='wp')
- {
- $condition[] = "eg.is_third = 0";
- $resultList = $this->schoolManager->getPrintList($condition,array('e.create_time desc'));
- }else{
- $resultList = $this->schoolManager->getPrintList_ipf($condition,array('e.complete_time desc'));
- }
- $printList = array();
- if($resultList["rs"]){
- foreach ($resultList['rs'] as $k=>$v) {
- $printList[$k] = $v;
- if ($v["type"] == 1) {
- $printList[$k]['print_name']= $v["exam_name"].'"错题本"';
- }
- elseif ($v["type"] == 2) {
- $printList[$k]['print_name']= $v["exam_name"].'"个性化学习方案"';
- }
- elseif ($v["type"] == 3) {
- if($this->subjectId == 8){
- $printList[$k]['print_name']= $v["exam_name"].'"个性化学习宝"';
- }else{
- $printList[$k]['print_name']= $v["exam_name"].'"个性化学习宝"';
- }
- }elseif ($v["type"] == 4) {
- $printList[$k]['print_name']= $v["exam_name"].'"阶段复习个性化学习宝"';
- }
- else {
- $printList[$k]['print_name']= $v["exam_name"];
- }
- $printList[$k]['is_tpl'] = 0; // 需要上传模板
- $printList[$k]['answer_card_uploaded'] = false;
- if(in_array($v['tpl_index'], Yii::app()->params['custom_tpls_ids'])){
- //自定义模板
- $printList[$k]['is_custom_tpl'] = true;
- $v['is_custom_tpl'] = true;
- }else{
- //非自定义模板
- $printList[$k]['is_custom_tpl'] = false;
- $v['is_custom_tpl'] = false;
- }
- if (in_array($v['tpl_index'], Yii::app()->params['no_template_id']) || $v['is_custom_tpl']) {
- $printList[$k]['is_tpl'] = 1;
- if(trim($printList[$k]['answer_card_src'])){
- $printList[$k]['answer_card_uploaded'] = true;
- }
- //题卡分离
- $printList[$k]['paper_tpl_type'] = 2;
- }else{
- $printList[$k]['paper_tpl_type'] = 1;
- }
- if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl']))
- {
- $printList[$k]['paper_tpl_type'] = 3;
- if($v['tpl_index'] == 9 )
- {
- $printList[$k]['paper_tpl_type'] = 4;
- }
- }
- if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl_all']))
- {
- $printList[$k]['paper_tpl_type'] = 3;
- if($v['tpl_index'] == 9 )
- {
- $printList[$k]['paper_tpl_type'] = 4;
- }
- }
- //题卡合一
- }
- }
- //$subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId);
- $data = array();
- $data['printList'] = $printList;
- $data['pages'] = $resultList['pager'];
- $data['page_total'] = $resultList['pager']->rowsCount;
- $data["printType"] = $printType;
- $data["printName"] = $printName;
- $data["classes"] = $classes;
- $data["classId"] = $classId;
- $data["grade"] = $grade;
- $data["labelled"] = $labelled;
- $data["display"] = $display;
- $data["is_print"] = $is_print;
- //$data["subject"] = $subject_exam_data;
- $data['subjectId']=$this->subjectId;
- if(isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue))
- {
- $data["use_zhixue"] = $this->schoolInfo->use_zhixue;
- }else
- {
- $data["use_zhixue"] = 0;
- }
- unset($resultList);
- $this->render('index',$data);
- }
- // 打印试卷、纠错本、个性化学习宝
- public function actionAjaxupdate(){
- $cid = safe_replace($_POST['cid']);
- $eid = safe_replace($_POST['eid']);
- $tid = safe_replace($_POST['tid']);
- $error = array();
- $error['success'] = 0;
- if (empty($cid) || !is_numeric($cid)) {
- $error['message'] = 'classId 错误!';
- echo json_encode($error);exit();
- }
- if (empty($eid) || !is_numeric($eid)) {
- $error['message'] = 'examId 错误!';
- echo json_encode($error);exit();
- }
- if ($tid == 0) { // 打印试卷
- $_num= '';
- $use_version = '';
- if(isset(Yii::app()->session['coachInfo']->use_version))
- {
- $use_version = Yii::app()->session['coachInfo']->use_version;
- }else
- {
- $use_version = Yii::app()->session['coachInfo']['use_version'];
- }
- if(!$use_version)
- {
- $use_version = 100;
- }
- $version_number = implode('',explode('.',$use_version));
- if(strlen($version_number)<7)
- {
- for($i=0;$i<7-strlen($version_number);$i++)
- {
- $_num.='0';
- }
- }
- $version_number=(int)$version_number.$_num;
- self::printPaper_v2($cid,$eid);
- } elseif ($tid == 1) { // 纠错本
- //self::printWrongTopic($cid,$eid);
- self::downloadWrongTopic($cid,$eid);
- } elseif ($tid == 2) { // 个性化学习宝
- self::printRaiseScheme($cid, $eid);
- }
- }
- // 选择需打印试卷的学生
- public function actionChange(){
- Url::clean();
- $sname = Req::get("sname");
- $cid = Req::get("cid");
- $eid = Req::get("eid");
- $tid = Req::get("tid");
- $isFeedback=0;
- $useAnswerCardOnlineQrcode=0;
- switch($tid){
- case "0":
- $printType = 'wp';
- break;
- case "1":
- $printType = 'wb';
- break;
- case "2":
- $printType = 'isp';
- break;
- default:
- $printType = 'wp';
- }
- if($sname)
- { $_student_ids = array();
- $criteria = new CDbCriteria();
- $criteria->select = 'student_id';
- $criteria->addSearchCondition('realname',$sname);
- $student_info_data = SStudentInfo::model()->findAll($criteria);
- if($student_info_data)
- {
- foreach($student_info_data as $v)
- {
- $_student_ids[$v->student_id] = $v->student_id;
- }
- }
- }
- $classInfo = ClassModel::model()->findByPk($cid);
- if (empty($classInfo)) {
- Yii::app()->jump->error('未找到班级!');
- }
- $examInfo = Exam::model()->findByPk($eid);
- if (empty($examInfo)) {
- Yii::app()->jump->error('未找到周周练!');
- }
- $examGroupInfo=ExamGroup::model()->findByPk($examInfo->exam_group_id);
- $getResult = ClassExamPrinter::model()->find('class_id=:cid and exam_id=:eid and type=0',array(':cid'=>$cid,':eid'=>$eid));
- if (empty($getResult)) {
- Yii::app()->jump->error('未找到班级与试卷对应关系!');
- }
- $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid));
- if (empty($paperInfo)) {
- Yii::app()->jump->error('未找到试卷信息!');
- }
- $_num= '';
- $use_version = '';
- if(isset(Yii::app()->session['coachInfo']->use_version))
- {
- $use_version = Yii::app()->session['coachInfo']->use_version;
- }else
- {
- $use_version = Yii::app()->session['coachInfo']['use_version'];
- }
- if(!$use_version)
- {
- $use_version = 100;
- }
- $version_number = implode('',explode('.',$use_version));
- if(strlen($version_number)<7)
- {
- for($i=0;$i<7-strlen($version_number);$i++)
- {
- $_num.='0';
- }
- }
- $version_number=(int)$version_number.$_num;
- $paperData='{}';
- if($examGroupInfo->qxk_paper_id==0){
- $paperData = $this->schoolManager->getPaperWithTopicsDetails_v2($paperInfo->paper_id);
- }
- if(trim($paperInfo->answer_card_src))
- $answerCardUploaded = true;
- else
- $answerCardUploaded = false;
- $tpl = 1;// 需要上传模板
- $tplTwo= 1;
- if (!in_array($examInfo->tpl_index,Yii::app()->params['no_template_id']) ) {
- $paperType = 1;
- if (empty($paperInfo->tpl_doc_src)) {
- $tpl = 2;
- }
- $tplTwo= 2;
- }else{
- $paperType = 2;
- }
- if(in_array($examInfo->tpl_index,Yii::app()->params['merge_topic_tpl']))
- {
- $tpl = 1;
- $paperType = 1;
- $tplTwo= 2;
- }
- if(in_array($examInfo->tpl_index, Yii::app()->params['custom_tpls_ids'])){
- $isCustomTpl = true;
- }
- else{
- $isCustomTpl = false;
- }
- //判断在线答题卡使用情况
- $answerCardOnline=$this->schoolManager->getAnswerSheetOnline($examInfo->exam_group_id);
- if($answerCardOnline && $answerCardOnline['online_card']==1 && $answerCardOnline['is_qrcode_online']==1){
- $useAnswerCardOnlineQrcode=1;
- }
- $relateTopic = SPaperTopicRelation::model()->count('paper_id=:paid',array(':paid'=>$paperInfo->paper_id));
- if (empty($relateTopic)) {
- Yii::app()->jump->error('未找该试卷试题信息!');
- }
- // 获取阅卷类型
- $markType = 0;
- $groupInfo = $this->schoolManager->getExam($eid);
- if (!empty($groupInfo)) {
- $findInfo = SExamGroup::model()->find('exam_group_id=:eg_id',array('eg_id'=>$groupInfo['exam_group_id']));
- if (!empty($findInfo)) {
- $markType = $findInfo->mark_type;
- }
- }
- $result = array();
- if(isset($_student_ids) && !empty($_student_ids))
- {
- $criteria = new CDbCriteria();
- $criteria->select = 'student_id,paper_id,class_id,exam_id,student_card,school_student_card,is_feedback,is_complete';
- $criteria->addCondition('paper_id=:paid');
- $criteria->addCondition('class_id=:caid');
- $criteria->addInCondition('student_id',$_student_ids);
- $criteria->addCondition('is_del=:is_del');
- $criteria->params[':paid'] = $paperInfo->paper_id;
- $criteria->params[':caid'] = $cid;
- $criteria->params[':is_del'] = 0;
- $relateStudent = SStudentPaperRelation::model()->findAll($criteria);
- }else
- {
- $relateStudent = SStudentPaperRelation::model()->findAll(array(
- 'select' => array('student_id','paper_id','class_id','exam_id','student_card','school_student_card','is_feedback','is_complete','student_img_paper'),
- 'condition' => 'paper_id=:paid and class_id=:caid and is_del=:is_del',
- 'params' => array(':paid'=>$paperInfo->paper_id,':caid'=>$cid,':is_del'=>0)));
- }
- //if (empty($relateStudent)) {
- // Yii::app()->jump->error('未找该试卷关联的学生!');
- //} else {
- //$studentModel = StudentInfo::model();
- // 获取学生姓名
- $_student_id = array();
- foreach($relateStudent as $v)
- {
- $_student_id[$v->student_id] = $v->student_id;
- }
- //if(!$_student_id)
- //{
- // Yii::app()->jump->error('未找该试卷关联的学生!');
- //}
- $studentNames = array();
- $b_student_arr = array();
- $b_student_arr = Yii::app()->redis_business_student->hgetAll('redis_business_del_student:'.$this->schoolId);
- if(!$b_student_arr ){
- $array_student = array();
- $b_student_data=$this->schoolManager->getStudentBySchool($this->schoolId);
- if($b_student_data){
- foreach ($b_student_data as $k=>$v){
- $array_student[$v['student_id']] = $v['student_id'];
- $b_student_arr[$v['student_id']]=$v['student_id'];
- }
- }
- Yii::app()->redis_business_student->del('redis_business_del_student:'.$this->schoolId);
- if($array_student){
- Yii::app()->redis_business_student->hmset('redis_business_del_student:'.$this->schoolId,$array_student);
- Yii::app()->redis_business_student->expire('redis_business_del_student:'.$this->schoolId,1296000);
- }
- unset($b_student_data);
- unset($criteria);
- }
- $studentNames = array();
- $criteria = new CDbCriteria();
- $criteria->addInCondition('student_id',$_student_id);
- $studentArray = SStudentInfo::model()->findAll($criteria);
- unset($criteria);
- if (!empty($studentArray)) {
- foreach ($studentArray as $student) {
- $studentNames[$student->student_id] = $student->realname;
- }
- }
- unset($studentArray);
- //查询是否上传答题图片
- $uploadAnswerImgStudent=array();
- $student_answer_img=$this->schoolManager->getUpAnswerStudent($paperInfo->paper_id,$_student_id,false);
-
- if($student_answer_img){
- foreach ($student_answer_img as $val){
- $uploadAnswerImgStudent[(string)$val['student_id']]=$val['student_id'];
- }
- }
- //redis里查询模板是否生成
- $redis_obj = new Redis();
- $server = Yii::app()->params["redis"]["server"];
- $redis_obj->connect($server["host"], $server["port"]);
- if(isset($server["password"])){
- $redis_obj->auth($server["password"]);
- }
- if (YII_ENV == 'pro' || YII_ENV == 'production') {
- $redis_obj->select(0);
- }else{
- $redis_obj->select(10);
- }
- $redisKey = 'zsy:paper_template:'.$this->schoolId.':'.$eid;
- $tempArr = array('0'=>'生成中','1'=>'已生成','2'=>'生成失败','3'=>'未生成');
- $tempCheck = $printCheck = false;
- foreach ($relateStudent as $key=>$val) {
- $result[$key]['clazzName'] = $classInfo->class_name;
- $result[$key]['paperName'] = $examInfo->name;
- $result[$key]['studentCode'] = $val->student_id;
- $result[$key]['student_card'] = $val->student_card;
- $result[$key]['school_student_card'] = $val->school_student_card;
- $result[$key]['studentCode'] = $val->student_id;
- $result[$key]['studentName'] = isset($studentNames[$val->student_id]) ? $studentNames[$val->student_id] : null;
- $result[$key]['is_feedback'] = $val->is_feedback;
- $result[$key]['is_complete'] = $val->is_complete;
- $result[$key]['student_img_paper'] = $val->student_img_paper;
- $result[$key]['upload_answer_img'] =0;
- if($val->is_feedback==1){
- $isFeedback=1;
- if(isset($uploadAnswerImgStudent[(string)$val->student_id])){
- $result[$key]['upload_answer_img'] =1;
- }
- }
- $stuId = (string)$val->student_id;
- $template = $redis_obj->hMGet($redisKey,array($stuId));
- $result[$key]['temp_str'] = '未生成';
- $result[$key]['temp_status'] = 3;
- if(isset($template[$stuId]) && $template[$stuId]){
- $redisData = json_decode($template[$stuId],true);
- if(isset($redisData['status']) && isset($tempArr[$redisData['status']])){
- $result[$key]['temp_str'] = $tempArr[$redisData['status']];
- $result[$key]['temp_status'] = $redisData['status'];
- if($redisData['status'] == 1){
- $printCheck = true;
- }
- if($redisData['status'] == 2){
- $tempCheck = true;
- }
- }else{
- $tempCheck = true;
- }
- }else{
- $tempCheck = true;
- }
- //查询在线答题卡是否生成
- $rs=$this->sConn->createCommand("select answer_card_online_created from student_answer_card_online where exam_id='{$eid}' and student_id='{$val->student_id}' ")->queryRow();
- if($rs && $rs['answer_card_online_created']==1){
- $result[$key]['online_created'] = 1;
- }else{
- $result[$key]['online_created'] = 0;
- }
- //查询学生身份证号
- $studentInfo=SStudentInfo::model()->find('student_id=:s_id',array('s_id'=>$val->student_id));
- if($studentInfo){
- $result[$key]['id_number'] = $studentInfo->id_number;
- }else{
- $result[$key]['id_number'] = '';
- }
- }
- $redis_obj->close();
- unset($relateStudent);
- //}
- $no_paper_student = array();
- $paper_student_array = array();
- $c_paper_student_array = array();
- $class_student_info_data = array();
- $class_student_data = $this->schoolManager->getClassStudentByClassId($cid); //student_class_relation
- $class_student_info_data = $this->schoolManager->getClassStudentInfoByClassId($cid); //student_info
- $paper_student_data = $this->schoolManager->getClassPaperByClassAndPaper($cid,$paperInfo->paper_id,1);//已删除考试学生
- $c_paper_student_data = $this->schoolManager->getClassPaperByClassAndPaper($cid,$paperInfo->paper_id);//考试学生
- if ($paper_student_data) {
- foreach ($paper_student_data as $v) {
- $paper_student_array[$v['student_id']] = $v['student_id'];
- }
- //$class_student_info_data = $this->schoolManager->getStudentByStudentIds($paper_student_array); //student_info
- }
- if ($c_paper_student_data) {
- foreach ($c_paper_student_data as $v) {
- $c_paper_student_array[$v['student_id']] = $v['student_id'];
- }
- //$class_student_info_data = $this->schoolManager->getStudentByStudentIds($paper_student_array); //student_info
- }
- if ($class_student_info_data) {
- foreach ($class_student_info_data as $v) {
- $class_student_info_array[$v['student_id']] = $v['realname'];
- }
- }
- if ($class_student_data) {
- foreach($class_student_data as $v)
- {
- if(!isset($b_student_arr[$v['student_id']]))
- {
- if ($paper_student_array)
- {
- if(isset($paper_student_array[$v['student_id']])){
- $no_paper_student[$v['student_id']] = array(
- 'student_id' => $v['student_id'],
- 'realname' => isset($class_student_info_array[$v['student_id']]) ?$class_student_info_array[$v['student_id']]:'',
- );
- }
- }
- if($c_paper_student_array )
- {
- if(!isset($c_paper_student_array[$v['student_id']]) )
- {
- $no_paper_student[$v['student_id']] = array(
- 'student_id' => $v['student_id'],
- 'realname' => isset($class_student_info_array[$v['student_id']]) ?$class_student_info_array[$v['student_id']]:'',
- );
- }
- }else
- {
- $no_paper_student[$v['student_id']] = array(
- 'student_id' => $v['student_id'],
- 'realname' => isset($class_student_info_array[$v['student_id']]) ?$class_student_info_array[$v['student_id']]:'',
- );
- }
- }
- }
- }
- unset($b_student_arr);
- $data = array();
- $data['no_paper_student'] = $no_paper_student;
- $data['result'] = $result;
- $data["printType"] = $printType;
- $data["sname"] = $sname;
- $data['examInfo'] = $examInfo;
- $data['paper_id'] = $paperInfo->paper_id;
- $data['exam_id'] = $eid;
- $data['class_id'] = $cid;
- $data['exam_group_id'] = $examInfo->exam_group_id;
- $data['type_id'] = $tid;
- $data['tempCheck'] = $tempCheck;
- $data['printCheck'] = $printCheck;
- if(isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue))
- {
- $data["use_zhixue"] = $this->schoolInfo->use_zhixue;
- }else
- {
- $data["use_zhixue"] = 0;
- }
- //$subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId);
- //$data["subject"] = $subject_exam_data;
- $data['wp_type'] = $examInfo->tpl_index;
- $data['className'] = $classInfo->class_name;
- $data['paperName'] = $examInfo->name;
- $data['tpl'] = $tpl;
- $data['tplTwo'] = $tplTwo;
- $data['markType'] = $markType;
- $data['paperType'] = $paperType;
- $data['answerCardUploaded'] = $answerCardUploaded;
- $data['paperData'] = $paperData;
- $data['isCustomTpl'] = $isCustomTpl;
- $data['isFeedback'] = $isFeedback;
- $data['useAnswerCardOnlineQrcode']=$useAnswerCardOnlineQrcode;
- $data['qxkPaperId'] = $examGroupInfo->qxk_paper_id;
- $_num= '';
- $use_version = '';
- if(isset(Yii::app()->session['coachInfo']->use_version))
- {
- $use_version = Yii::app()->session['coachInfo']->use_version;
- }else
- {
- $use_version = Yii::app()->session['coachInfo']['use_version'];
- }
- if(!$use_version)
- {
- $use_version = 100;
- }
- $version_number = implode('',explode('.',$use_version));
- if(strlen($version_number)<7)
- {
- for($i=0;$i<7-strlen($version_number);$i++)
- {
- $_num.='0';
- }
- }
- $version_number=(int)$version_number.$_num;
- $data['version_number']=$version_number;
- $this->render('change2',$data);
- }
- // 选择需打印纠错本的同学
- public function actionChangewrongtopic(){
- $sname = Req::get("sname");
- $cid = Req::get("cid");
- $eid = Req::get("eid");
- $printType = (string)Req::get("printType");
- $classInfo = ClassModel::model()->findByPk($cid);
- if (empty($classInfo)) {
- Yii::app()->jump->error('未找到班级!');
- }
- $semesterId = $classInfo->semester_id;//当前学期id
- $grade = $classInfo->grade;
- $examInfo = Exam::model()->findByPk($eid);
- if (empty($examInfo)) {
- Yii::app()->jump->error('未找到周周练!');
- }
- $getResult = ClassExamPrinter::model()->find('class_id=:cid and exam_id=:eid and type=1',array(':cid'=>$cid,':eid'=>$eid));
- if (empty($getResult)) {
- Yii::app()->jump->error('未找到班级与试卷对应关系!');
- }
- $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid));
- if (empty($paperInfo)) {
- Yii::app()->jump->error('未找到试卷信息!');
- }
- $paperIsLabelled = isset($paperInfo->is_labelled) ? (($paperInfo->is_labelled == 1) ? true : false) : false;
- $printTaskName = "{$classInfo->class_name}{$examInfo->name}\"错题本\"";
- $relateStudent = SStudentPaperRelation::model()->findAll('paper_id=:paid and class_id=:caid',array(':paid'=>$paperInfo->paper_id,':caid'=>$cid));
- //$relateStudent = SStudentPaperRelation::model()->findAll('paper_id=:paid and class_id=:caid and is_wrongbook_pdf=1',array(':paid'=>$paperInfo->paper_id,':caid'=>$cid));
- if (empty($relateStudent)) {
- Yii::app()->jump->error('未找到学生和试卷的对应关系!');
- } else {
- $studentIds = array();
- foreach ($relateStudent as $studentInfo) {
- $studentIds[] = (string)$studentInfo['student_id'];
- }
- $studentNames = SStudentInfo::model()->getStudentNames($studentIds); //求学生名字
- $result = array();
- $no = 1;
- foreach ($relateStudent as $v) {
- $studentId = (string)$v['student_id'];
- $_studentName = isset($studentNames[$studentId])?$studentNames[$studentId]:'';
- $is_html = $v['is_wrongbook_html'];
- $is_pdf = $v['is_wrongbook_pdf'];
- $status = $this->getStatusDesc($is_html, $is_pdf); //错题本状态
- $className = $classInfo->class_name;
- $scoring = $v['scoring'];
- if ($sname ) { //如果写了学生名字,那么返回时只返回该学生的
- if (strpos($_studentName, $sname) !== false) { //是搜索的学生
- $result[$studentId] = array();
- $result[$studentId]['no'] = $no; //序号
- $result[$studentId]['studentId'] = $studentId; //学生id
- $result[$studentId]['studentName'] = $_studentName; //学生名称
- $result[$studentId]['studentCode'] = $studentId; //学生id,即编号
- $result[$studentId]['clazzName'] = $className; //班级名称
- $result[$studentId]['wrongStatus'] = $status; //错题本状态
- $result[$studentId]['scoring'] = $scoring; //得分
- $result[$studentId]['complete_time'] = $v['complete_time']; //完成阅卷时间
- $result[$studentId]['isAbsent'] = $v['is_del']; //是否缺考
- $no += 1;
- } else{
- continue;
- }
- } else {
- $result[$studentId] = array();
- $result[$studentId]['no'] = $no; //序号
- $result[$studentId]['studentId'] = $studentId; //学生id
- $result[$studentId]['studentName'] = $_studentName; //学生名称
- $result[$studentId]['studentCode'] = $studentId; //学生id,即编号
- $result[$studentId]['clazzName'] = $className; //班级名称
- $result[$studentId]['wrongStatus'] = $status; //错题本状态
- $result[$studentId]['scoring'] = $scoring; //得分
- $result[$studentId]['complete_time'] = $v['complete_time']; //完成阅卷时间
- $result[$studentId]['isAbsent'] = $v['is_del']; //是否缺考
- $no += 1;
- }
- }
- }
- $data = array();
- $data['exam_id'] = $eid;
- $data['examName'] = $examInfo["name"];
- $data['class_id'] = $cid;
- $data['className'] = $classInfo->class_name;
- $data['sname'] = $sname;
- $data['paper_id'] = $paperInfo->paper_id;
- $data['printTaskName'] = $printTaskName;
- $data['paperIsLabelled'] = $paperIsLabelled;
- $data['result'] = $result;
- $data['printType'] = $printType;
- $data['stuIspErroMsg'] = $this->stuIspErrorMsg(1,$eid,$studentIds);
- $order_res = $this->getOrderStu($eid, $cid, 1, $relateStudent,$semesterId, $grade);
- if (!$order_res) {
- Yii::app()->jump->error("接口错误");
- }
- $data = array_merge($data, $order_res);
- $this->render('changewrongtopic',$data);
- }
- /**
- * 学生错题本个性化学习宝未生成错题信息
- * @param $productType
- * @param $examId
- * @param array $studentIds
- */
- protected function stuIspErrorMsg($productType,$examId,$studentIds = array())
- {
- $result = array();
- if (!in_array($this->subjectId, $this->mathSubjectId)) {
- return $result;
- }
- if (!$studentIds) {
- return $result;
- }
- //转字符串
- foreach ($studentIds as $k => $_stuId) {
- $studentIds[$k] = '"'.$_stuId.'"';
- }
- //需要显示学生个性化学习宝错误码
- $showErrorCode = Yii::app()->params['show_isp_error_code'];
- //个性化学习宝错误代码信息
- $errorCodeMsg = Yii::app()->params['isp_error_code_msg'];
- $rs = SStudentIspErrorCode::model()->getStudentIspErrorCode($examId, $productType);
- if ($rs) {
- foreach ($rs as $value) {
- if(!in_array($value['error_code'],$showErrorCode)) continue;
- if (!isset($result[$value['student_id']])) {
- $result[$value['student_id']] = array();
- }
- $result[$value['student_id']][$value['error_code']] = isset($errorCodeMsg[$value['error_code']])?$errorCodeMsg[$value['error_code']]:'错误码无信息';
- }
- }
- unset($rs);
- return $result;
- }
- // 处理选择后同学纠错本打印(于20160908使用API接口的方法替换此方案,暂时废弃)
- public function actionChangewrongtopicdo(){
- $cid = Req::get("cid");
- $eid = Req::get("eid");
- $stids = Req::get("stids");
- if (empty($stids) || empty($cid) || empty($eid)) {
- Yii::app()->jump->error('打印纠错本参数有误!');
- }
- $classInfo = ClassModel::model()->findByPk($cid);
- if (empty($classInfo)) {
- Yii::app()->jump->error('未找到班级!');
- }
- $examInfo = Exam::model()->findByPk($eid);
- if (empty($examInfo)) {
- Yii::app()->jump->error('未找到周周练!');
- }
- $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid));
- if (empty($paperInfo)) {
- Yii::app()->jump->error('未找到试卷信息!');
- }
- $filePath = array();
- $getPaths = $this->schoolManager->getStudentsPdfsPaths($paperInfo->paper_id,explode(',',$stids));
- if (empty($getPaths)) {
- Yii::app()->jump->error('正在努力生成纠错本!');
- } else {
- // 下载文件名称
- $fileName = $classInfo->class_name.$examInfo->name.'纠错本.zip';
- // 下载文件路径
- $result = array();
- //$pdfPath = dirname(dirname(dirname(dirname(__FILE__)))).'/api/uploads/';
- $pdfPath = Yii::app()->params['student_wrong_isp_path'];
- foreach ($getPaths as $path) {
- /* if(file_exists(iconv("utf-8", "gbk", $pdfPath.$path->wrongbook_pdf_path))){
- $result[] = $path->wrongbook_pdf_path;
- } */
- if(strpos($path->wrongbook_pdf_path, "data")!==false){
- $paths=$pdfPath.$path->wrongbook_pdf_path;
- }else{
- $paths=$pdfPath."uploads/".$path->wrongbook_pdf_path;
- }
- if(file_exists($paths)){//aaaaaaaaa
- $result[] = $paths;
- }
- }
- if (empty($result)) {
- Yii::app()->jump->error('正在生成学生纠错本!');
- }
- // 下载
- self::downloadStudentFile($fileName,$result);
- }
- }
- // 选择需打印个性化学习宝的同学
- public function actionChangeraisescheme(){
- $sname = Req::get("sname"); //学生名字
- $cid = Req::get("cid"); //班级id
- $eid = Req::get("eid"); //考试id
- $type = Req::get("type"); //2步 还是 3步
- $subjectId = Req::get("subid"); //学科ID
- $planName = "";
- if($type == "isp"){
- $postTypeVal=2;
- if($subjectId == 8){
- $postTypeVal=3;
- $planName = "个性化学习宝";
- }else{
- $planName = "个性化学习方案";
- }
- $typeVal = 2;
- }else if($type == "third_isp"){
- $planName = "个性化学习宝";
- $typeVal = 3;
- if($subjectId == 8){
- $postTypeVal = 3;
- }else{
- $postTypeVal = 2;
- }
- }else if($type == "studytrend"){
- $planName = "个性化学习宝";
- $typeVal = 3;
- $postTypeVal=3;
- }else{
- Yii::app()->jump->error('参数错误!');
- }
- $classInfo = ClassModel::model()->findByPk($cid);
- if (empty($classInfo)) {
- Yii::app()->jump->error('未找到班级!');
- }
- $semesterId = $classInfo->semester_id;//当前学期id
- $grade = $classInfo->grade;
- $examInfo = Exam::model()->findByPk($eid);
- if (empty($examInfo)) {
- Yii::app()->jump->error('未找到周周练!');
- }
- $getResult = ClassExamPrinter::model()->find('class_id=:cid and exam_id=:eid and type='.$typeVal,array(':cid'=>$cid,':eid'=>$eid));
- if (empty($getResult)) {
- Yii::app()->jump->error('未找到班级与试卷对应关系!');
- }
- $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid));
- if (empty($paperInfo)) {
- Yii::app()->jump->error('未找到试卷信息!');
- }
- $paperIsLabelled = isset($paperInfo->is_labelled) ? (($paperInfo->is_labelled == 1) ? true : false) : false;
- $printTaskName = "{$classInfo->class_name}{$examInfo->name}\"{$planName}\"";
- /*$studentIds = array();
- $planNames = array();
- $result = array();
- $ispStatus = array();
- $studentIdsTwo = array();*/
- //$relateStudent = SStudentPaperRelation::model()->findAll('paper_id=:paid and class_id=:caid and is_isp_pdf=1',array(':paid'=>$paperInfo->paper_id,':caid'=>$cid));
- $relateStudent = SStudentPaperRelation::model()->findAll('paper_id=:paid and class_id=:caid ',array(':paid'=>$paperInfo->paper_id,':caid'=>$cid));//所有记录
- if (!$relateStudent) {
- Yii::app()->jump->error('未找到学生和试卷的对应关系!');
- }
- $studentIds = array();
- foreach ($relateStudent as $studentInfo) {
- $studentIds[] = (string)$studentInfo['student_id'];
- }
- $studentNames = SStudentInfo::model()->getStudentNames($studentIds); //求学生名字
- $result = array();
- $no = 1;
- foreach ($relateStudent as $v) {
- $studentId = (string)$v['student_id'];
- $_studentName = isset($studentNames[$studentId])?$studentNames[$studentId]:'';
- if ($type == 'isp') {
- $is_html = $v['is_isp_html'];
- $is_pdf = $v['is_isp_pdf'];
- }elseif ($type == 'studytrend') {
- $is_html = $v['is_wbisp_html'];
- $is_pdf = $v['is_wbisp_pdf'];
- }elseif ($type == 'third_isp') {
- $is_html = $v['is_wbisp_html'];
- $is_pdf = $v['is_wbisp_pdf'];
- }
- $status = $this->getStatusDesc($is_html, $is_pdf); //个性化学习宝状态
- $className = $classInfo->class_name;
- $_planName = $className.$_studentName.$examInfo->name.$planName;
- if ($sname ) { //如果写了学生名字,那么返回时只返回该学生的
- if (strpos($_studentName, $sname) !== false) { //是搜索的学生
- $result[$studentId] = array();
- $result[$studentId]['no'] = $no; //序号
- $result[$studentId]['studentId'] = $studentId; //学生id
- $result[$studentId]['studentName'] = $_studentName; //学生名称
- $result[$studentId]['studentCode'] = $studentId; //学生id,即编号
- $result[$studentId]['clazzName'] = $className; //班级名称
- $result[$studentId]['ispStatus'] = $status; //个性化学习宝状态
- $result[$studentId]['planName'] = $_planName;
- $result[$studentId]['complete_time'] = $v['complete_time']; //完成阅卷时间
- $result[$studentId]['isAbsent'] = $v['is_del']; //是否缺考
- $no += 1;
- } else{
- continue;
- }
- } else {
- $result[$studentId] = array();
- $result[$studentId]['no'] = $no; //序号
- $result[$studentId]['studentId'] = $studentId; //学生id
- $result[$studentId]['studentName'] = $_studentName; //学生名称
- $result[$studentId]['studentCode'] = $studentId; //学生id,即编号
- $result[$studentId]['clazzName'] = $className; //班级名称
- $result[$studentId]['ispStatus'] = $status; //个性化学习宝状态
- $result[$studentId]['planName'] = $_planName;
- $result[$studentId]['complete_time'] = $v['complete_time']; //完成阅卷时间
- $result[$studentId]['isAbsent'] = $v['is_del']; //是否缺考
- $no += 1;
- }
- }
- $data = array();
- $data['exam_id'] = $eid;
- $data['class_id'] = $cid;
- $data['className'] = $grade;
- $data['sname'] = $sname;
- $data['paper_id'] = $paperInfo->paper_id;
- $data['result'] = $result;
- $data['type'] = $type;
- $data['paperIsLabelled'] = $paperIsLabelled;
- $data['printTaskName'] = $printTaskName;
- $data['printType'] = $type;
- $data['subjectId']=$subjectId;
- $data['stuIspErroMsg'] = $this->stuIspErrorMsg($type == 'isp'?2:3,$eid,$studentIds);
- $order_res = $this->getOrderStu($eid, $cid, $postTypeVal, $relateStudent,$semesterId, $grade);
- // debug($order_res);
- if (!$order_res) {
- Yii::app()->jump->error("接口错误");
- }
- $data = array_merge($data, $order_res);
- // debug($data);
- $this->render('changeraisescheme',$data);
- /*// 获取当前试卷提分计划
- $improveScore = StudentImproveScorePlan::model()->findAll('paper_id=:paid and is_created=1',array(':paid'=>$paperInfo->paper_id));
- if (empty($relateStudent)) {
- Yii::app()->jump->error('学生的个性化学习宝还未生成,请等待!');
- } else {
- if($type == "isp"){
- foreach ($relateStudent as $paperStudent) {
- $rs = $this->sConn->createCommand("select exists(select * from student_class_relation where student_id = '{$paperStudent->student_id}')")->queryRow();
- $rs = current($rs);
- if($rs == 0)
- continue;
- $studentIds[] = $paperStudent->student_id;
- $ispStatus[$paperStudent->student_id] = $paperStudent->is_isp_pdf;
- }
- // 获取当前班级需打印周周练的同学
- foreach ($improveScore as $improve) {
- if (in_array($improve->student_id, $studentIds)) {
- $studentIdsTwo[] = $improve->student_id;
- }
- }
- }
- else if($type == "studytrend"){
- foreach ($relateStudent as $paperStudent) {
- $rs = $this->sConn->createCommand("select exists(select * from student_class_relation where student_id = '{$paperStudent->student_id}' )")->queryRow();
- $rs = current($rs);
- if($rs == 0)
- continue;
- $studentIds[] = $paperStudent->student_id;
- $ispStatus[$paperStudent->student_id] = $paperStudent->is_wbisp_pdf;
- }
- // 获取当前班级需打印周周练的同学
- foreach ($improveScore as $improve) {
- if (in_array($improve->student_id, $studentIds)) {
- $studentIdsTwo[] = $improve->student_id;
- }
- }
- }
- }
- if (empty($studentIdsTwo)) {
- Yii::app()->jump->error('当前班级还未生成个性化学习宝');
- } else {
- // 获取有错题的学生姓名
- $studentNames = SStudentInfo::model()->getStudentNames($studentIdsTwo);
- foreach ($studentIdsTwo as $key=>$val) { //val是学生id
- if (empty($sname)) {
- $result[$key]['studentName'] = $studentNames[$val];
- $result[$key]['studentCode'] = $val;
- $result[$key]['clazzName'] = $classInfo->class_name;
- $result[$key]['ispStatus'] = $ispStatus[$val];
- $result[$key]['planName'] = $classInfo->class_name.$studentNames[$val].$examInfo->name.$planName;
- } else {
- if (false !== strpos($studentNames[$val],$sname) ) {
- $result[$key]['studentName'] = $studentNames[$val];
- $result[$key]['studentCode'] = $val;
- $result[$key]['clazzName'] = $classInfo->class_name;
- $result[$key]['ispStatus'] = $ispStatus[$val];
- $result[$key]['planName'] = $classInfo->class_name.$studentNames[$val].$examInfo->name.$planName;
- }
- unset($studentIdsTwo[$key]);
- }
- }
- }*/
- }
- function getStatusDesc($is_html, $is_pdf)
- {
- if ($is_html == 0 || $is_html == 90) {
- $status = 0; // 未生成
- } elseif ($is_html == 1 && $is_pdf == 0) {
- $status = 1; //正在生成中
- } elseif ($is_pdf == 1) {
- $status = 2; //已生成
- } elseif ($is_html == 9 && $is_pdf == 9) {
- $status = 3; //已过期
- } else {
- $status = 4; //未知状态
- }
- return $status;
- }
- function getOrderStu($eid, $cid, $typeVal,$relateStudentRes,$semesterId, $grade)
- {
- $data = array();
- $Sem=new SSemester();
- $code= $Sem->conn->createQuery()
- ->from('semester')
- ->where("semester_id = '".$this->semesterId."'")
- ->limit(1)
- ->query()
- ->read();
- $print_time=ClassExamPrinter::model()->findAll('exam_id=:exam_id and class_id=:classid and type=0',array(':exam_id'=>$eid,':classid'=>$cid));
- $intarr=array(
- "schoolId"=>$this->schoolId,
- "clazzId"=>$cid,
- "semester"=>$code['refer_code'],
- "grade"=>$grade,
- "examTime"=>$print_time[0]->add_time,
- "students"=>array(),
- "classify"=>$typeVal,
- );
- $examInfo = Exam::model()->findByPk($eid);
- $intarr['subject']=$examInfo['subject_id'];
- if(in_array($intarr['subject'],$this->mathSubjectId)){
- $intarr['subject']=3;
- }
- foreach($relateStudentRes as $key => $val){
- $intarr['students'][] = $val['student_id'];
- }
- $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]);
- $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr),$basic));
- if(!$rs){
- //Yii::app()->jump->error("接口错误");
- return false;
- }
- if($rs->errCode!="00"){
- //Yii::app()->jump->error($rs->errMsg);
- //exit();
- return false;
- }
- if(!empty($rs->data)){
- foreach($rs->data as $v){
- $data['limitstu'][$v]=$v;
- }
- }else{
- $data['limitstu']=-1;
- }
- return $data;
- }
- // 选择打印个性化学习宝同学处理(于20160908使用API接口的方法替换此方案,暂时废弃)
- public function actionChangeraiseschemedo(){
- $cid = Req::get("cid");
- $eid = Req::get("eid");
- $stids = Req::get("stids");
- $type = Req::get("type");
- if (empty($stids) || empty($cid) || empty($eid) || empty($type)) {
- Yii::app()->jump->error('打印个性化学习宝参数有误!');
- }
- $classInfo = ClassModel::model()->findByPk($cid);
- if (empty($classInfo)) {
- Yii::app()->jump->error('未找到班级!');
- }
- $examInfo = Exam::model()->findByPk($eid);
- if (empty($examInfo)) {
- Yii::app()->jump->error('未找到周周练!');
- }
- $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid));
- if (empty($paperInfo)) {
- Yii::app()->jump->error('未找到试卷信息!');
- }
- $filePath = array();
- $getPaths = $this->schoolManager->getStudentsPdfsPaths($paperInfo->paper_id,explode(',',$stids));
- if (empty($getPaths)) {
- Yii::app()->jump->error('正在努力生成个性化学习宝!');
- } else {
- $fName = "";
- if($type == "isp")
- $fName = "个性化学习方案";
- else if($type == "studytrend")
- $fName = "个性化学习宝";
- // 下载文件名称
- $fileName = $classInfo->class_name.$examInfo->name.$fName.'.zip';
- // 下载文件路径
- $result = array();
- //$pdfPath = dirname(dirname(dirname(dirname(__FILE__)))).'/api/uploads/';
- $pdfPath = Yii::app()->params['student_wrong_isp_path'];
- foreach ($getPaths as $path) {
- /* if(file_exists(iconv("utf-8", "gbk//IGNORE", $pdfPath.$path->isp_pdf_path))){
- $result[] = $path->isp_pdf_path;
- } */
- if($type == "isp"){
- if(strpos($path->isp_pdf_path,'data')!==false){
- $paths=$pdfPath.$path->isp_pdf_path;
- }else{
- $paths=$pdfPath."uploads/".$path->isp_pdf_path;
- }
- $result[] = $paths;
- }
- else if($type == "studytrend" ){
- if(strpos($path->isp_pdf_path,'data')!==false){
- $paths=$pdfPath.$path->wbisp_pdf_path;
- }else{
- $paths=$pdfPath."uploads/".$path->wbisp_pdf_path;
- }
- $result[] = $paths;
- }
- }
- if (empty($result)) {
- Yii::app()->jump->error('正在生成学生个性化学习宝!');
- }
- // 下载
- self::downloadStudentFile($fileName,$result);
- }
- }
- // 打印试卷
- private function printPaper($cid,$eid){
- $error = array();
- $error['success'] = 0;
- $classInfo = ClassModel::model()->findByPk($cid);
- if (empty($classInfo)) {
- $error['message'] = '未找到班级!';
- echo json_encode($error);exit();
- }
- $examInfo = Exam::model()->findByPk($eid);
- if (empty($examInfo)) {
- $error['message'] = '未找到周周练!';
- echo json_encode($error);exit();
- }
- $getResult = ClassExamPrinter::model()->find('class_id=:cid and exam_id=:eid and type=0',array(':cid'=>$cid,':eid'=>$eid));
- if (empty($getResult)) {
- $error['message'] = '未找到班级与试卷对应关系!';
- echo json_encode($error);exit();
- }
- $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid));
- if (empty($paperInfo)) {
- $error['message'] = '未找到试卷信息!';
- echo json_encode($error);exit();
- }
- if (!in_array($examInfo->tpl_index,Yii::app()->params['no_template_id']) && !in_array($examInfo->tpl_index, Yii::app()->params['custom_tpls_ids'])) {
- if (empty($paperInfo->tpl_doc_src)) {
- $error['message'] = '未上传模板,请先上传模板!';
- echo json_encode($error);exit();
- }
- }
- // 获取阅卷类型
- $markType = 0;
- $groupInfo = $this->schoolManager->getExam($eid);
- if (!empty($groupInfo)) {
- $findInfo = SExamGroup::model()->find('exam_group_id=:eg_id',array('eg_id'=>$groupInfo['exam_group_id']));
- if (!empty($findInfo)) {
- $markType = $findInfo->mark_type;
- }
- }
- $relateTopic = SPaperTopicRelation::model()->count('paper_id=:paid',array(':paid'=>$paperInfo->paper_id));
- if (empty($relateTopic)) {
- $error['message'] = '未找该试卷试题信息!';
- echo json_encode($error);exit();
- }
- $result = array();
- $relateStudent = SStudentPaperRelation::model()->findAll('paper_id=:paid and class_id=:caid and is_del=:is_del',array(':paid'=>$paperInfo->paper_id,':caid'=>$cid,'is_del'=>0));
- if (empty($relateStudent)) {
- $error['message'] = '未找该试卷关联的学生!';
- echo json_encode($error);exit();
- } else {
- // 组装json数据发到客户端
- $studentModel = StudentInfo::model();
- $paperData = $this->schoolManager->getPaperWithTopicsDetails($paperInfo->paper_id, "ARR");
- foreach ($relateStudent as $key=>$val) {
- $result[$key]['clazzName'] = $classInfo->class_name;
- $result[$key]['paperId'] = $paperInfo->paper_id;
- $result[$key]['paperName'] = $examInfo->name;
- $result[$key]['schoolId'] = Yii::app()->session['school_id'];
- $result[$key]['studentCode'] = $val->student_id;
- $result[$key]['studentName'] = $studentModel->findByPk($val->student_id)->realname;
- $result[$key]['wpCode'] = $eid;
- $result[$key]['wpType'] = $examInfo->tpl_index;
- $result[$key]['markType'] = $markType;
- if(isset($paperData["object"]["topicsCount"])){
- $result[$key]['selectQTNub'] = $paperData["object"]["topicsCount"]["singleChoice"];
- $result[$key]['completionNub'] = $paperData["object"]["topicsCount"]["blankFilling"];
- $result[$key]['questionSNub'] = $paperData["object"]["topicsCount"]["shortAnswer"];
- }
- else{
- $result[$key]['selectQTNub'] = 0;
- $result[$key]['completionNub'] = 0;
- $result[$key]['questionSNub'] = 0;
- }
- }
- }
- if (empty($result)) {
- $error['message'] = '没有打印信息!';
- echo json_encode($error);exit();
- } else {
- // 更新试卷打印状态、时间
- $getResult->is_print = 1;
- $getResult->print_time = time();
- $getResult->save();
- $error['success'] = 1;
- $error['message'] = $result;
- echo json_encode($error);exit();
- }
- }
- private function printPaper_v2($cid,$eid){
- $error = array();
- $error['success'] = 0;
- $classInfo = ClassModel::model()->findByPk($cid);
- if (empty($classInfo)) {
- $error['message'] = '未找到班级!';
- echo json_encode($error);exit();
- }
- $examInfo = Exam::model()->findByPk($eid);
- if (empty($examInfo)) {
- $error['message'] = '未找到周周练!';
- echo json_encode($error);exit();
- }
- $getResult = ClassExamPrinter::model()->find('class_id=:cid and exam_id=:eid and type=0',array(':cid'=>$cid,':eid'=>$eid));
- if (empty($getResult)) {
- $error['message'] = '未找到班级与试卷对应关系!';
- echo json_encode($error);exit();
- }
- $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid));
- if (empty($paperInfo)) {
- $error['message'] = '未找到试卷信息!';
- echo json_encode($error);exit();
- }
- if (!in_array($examInfo->tpl_index,Yii::app()->params['no_template_id']) && !in_array($examInfo->tpl_index, Yii::app()->params['custom_tpls_ids'])) {
- if (empty($paperInfo->tpl_doc_src)) {
- $error['message'] = '未上传模板,请先上传模板!';
- echo json_encode($error);exit();
- }
- }
- // 获取阅卷类型
- $markType = 0;
- $groupInfo = $this->schoolManager->getExam($eid);
- if (!empty($groupInfo)) {
- $findInfo = SExamGroup::model()->find('exam_group_id=:eg_id',array('eg_id'=>$groupInfo['exam_group_id']));
- if (!empty($findInfo)) {
- $markType = $findInfo->mark_type;
- }
- }
- $relateTopic = SPaperTopicRelation::model()->count('paper_id=:paid',array(':paid'=>$paperInfo->paper_id));
- if (empty($relateTopic)) {
- $error['message'] = '未找该试卷试题信息!';
- echo json_encode($error);exit();
- }
- $result = array();
- $relateStudent = SStudentPaperRelation::model()->findAll('paper_id=:paid and class_id=:caid and is_del=:is_del',array(':paid'=>$paperInfo->paper_id,':caid'=>$cid,'is_del'=>0));
- if (empty($relateStudent)) {
- $error['message'] = '未找该试卷关联的学生!';
- echo json_encode($error);exit();
- } else {
- // 组装json数据发到客户端
- $studentModel = StudentInfo::model();
- $paperData = $this->schoolManager->getPaperWithTopicsDetails_v2($paperInfo->paper_id, "ARR");
- foreach ($relateStudent as $key=>$val) {
- $studentInfo=$studentModel->findByPk($val->student_id);
- $result[$key]['clazzName'] = $classInfo->class_name;
- $result[$key]['paperId'] = $examInfo->exam_group_id;
- $result[$key]['paperName'] = $examInfo->name;
- $result[$key]['schoolId'] = Yii::app()->session['school_id'];
- $result[$key]['studentCode'] = $val->student_id;
- $result[$key]['studentName'] = $studentInfo->realname;
- $result[$key]['wpCode'] = $eid;
- $result[$key]['wpType'] = $examInfo->tpl_index;
- $result[$key]['markType'] = $markType;
- $result[$key]['idNumber'] = $studentInfo->id_number;
- if(isset($paperData["object"]["topicsCount"])){
- $result[$key]['selectQTNub'] = $paperData["object"]["topicsCount"]["singleChoice"];
- $result[$key]['completionNub'] = $paperData["object"]["topicsCount"]["blankFilling"];
- $result[$key]['questionSNub'] = $paperData["object"]["topicsCount"]["shortAnswer"];
- }
- else{
- $result[$key]['selectQTNub'] = 0;
- $result[$key]['completionNub'] = 0;
- $result[$key]['questionSNub'] = 0;
- }
- }
- }
- if (empty($result)) {
- $error['message'] = '没有打印信息!';
- echo json_encode($error);exit();
- } else {
- // 更新试卷打印状态、时间
- $getResult->is_print = 1;
- $getResult->print_time = time();
- $getResult->save();
- $error['success'] = 1;
- $error['message'] = $result;
- echo json_encode($error);exit();
- }
- }
- // 下载全班学生纠错本
- public function actionDownloadwrongtopic() {
- $cid = Req::get("cid");
- $eid = Req::get("eid");
- $classInfo = ClassModel::model()->findByPk($cid);
- if (empty($classInfo)) {
- Yii::app()->jump->error('未找到班级!');
- }
- $examInfo = Exam::model()->findByPk($eid);
- if (empty($examInfo)) {
- Yii::app()->jump->error('未找到周周练!');
- }
- $getResult = ClassExamPrinter::model()->find('class_id=:cid and exam_id=:eid and type=1',array(':cid'=>$cid,':eid'=>$eid));
- if (empty($getResult)) {
- Yii::app()->jump->error('未找到班级与纠错本对应关系!');
- }
- $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid));
- if (empty($paperInfo)) {
- Yii::app()->jump->error('未找到试卷信息!');
- }
- $result = array();
- $relateStudent = SStudentPaperRelation::model()->findAll('paper_id=:paid and class_id=:caid and is_wrongbook_pdf=1 and is_del=:is_del',array(':is_del'=>0,':paid'=>$paperInfo->paper_id,':caid'=>$cid));
- if (empty($relateStudent)) {
- Yii::app()->jump->error('正在努力生成纠错本!');
- } else {
- $studentIdArray = array();
- // 获取当前考试所有学生ID
- foreach ($relateStudent as $key=>$val) {
- $studentIdArray[] = $val->student_id;
- }
- }
- $filePath = array();
- $getPaths = $this->schoolManager->getStudentsPdfsPaths($paperInfo->paper_id,$studentIdArray);
- if (empty($getPaths)) {
- Yii::app()->jump->error('正在生成纠错本!');
- } else {
- // 下载文件名称
- $fileName = $classInfo->class_name.$examInfo->name.'错题本.zip';
- // 下载文件路径
- $result = array();
- //$pdfPath = dirname(dirname(dirname(dirname(__FILE__)))).'/api/uploads/';
- $pdfPath = Yii::app()->params['student_wrong_isp_path'];
- foreach ($getPaths as $path) {
- /* if(file_exists(iconv("utf-8", "gbk//IGNORE", $pdfPath.$path->wrongbook_pdf_path))){
- $result[] = $path->wrongbook_pdf_path;
- } */
- if(strpos($path->wrongbook_pdf_path,"data")!==false){
- $pathstr=$pdfPath.$path->wrongbook_pdf_path;
- }else{
- $pathstr=$pdfPath."uploads/".$path->wrongbook_pdf_path;
- }
- if(file_exists($pathstr)){
- $result[] = $pathstr;
- }
- }
- if (empty($result)) {
- Yii::app()->jump->error('正在生成学生纠错本!');
- }
- // 下载
- self::downloadStudentFile($fileName,$result);
- }
- }
- // 下载全班学生个性化学习宝
- public function actionDownloadraisescheme($cid,$eid,$type){
- if(!in_array($type, array(2, 3)))
- Yii::app()->jump->error('缺少参数!');
- $classInfo = ClassModel::model()->findByPk($cid);
- if (empty($classInfo)) {
- Yii::app()->jump->error('未找到班级!');
- }
- $examInfo = Exam::model()->findByPk($eid);
- if (empty($examInfo)) {
- Yii::app()->jump->error('未找到周周练!');
- }
- $getResult = ClassExamPrinter::model()->find('class_id=:cid and exam_id=:eid and type=1',array(':cid'=>$cid,':eid'=>$eid));
- if (empty($getResult)) {
- Yii::app()->jump->error('未找到班级与纠错本对应关系!');
- }
- $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid));
- if (empty($paperInfo)) {
- Yii::app()->jump->error('未找到试卷信息!');
- }
- if($type == 2){
- $field = "is_isp_pdf";
- $check = "ISP";
- }
- else{
- $field = "is_wbisp_pdf";
- $check = "WB_ISP";
- }
- $relateStudent = SStudentPaperRelation::model()->findAll("paper_id=:paid and class_id=:caid and {$field}=1 and is_del=0",array(':paid'=>$paperInfo->paper_id,':caid'=>$cid));
- if (empty($relateStudent)) {
- Yii::app()->jump->error('正在努力生成个性化学习宝!');
- } else {
- $studentIdArray = array();
- // 获取当前考试所有学生ID
- foreach ($relateStudent as $key=>$val) {
- $studentIdArray[] = $val->student_id;
- }
- }
- $filePath = array();
- $getPaths = $this->schoolManager->getStudentsPdfsPaths($paperInfo->paper_id,$studentIdArray, $check);
- if (empty($getPaths)) {
- Yii::app()->jump->error('正在努力生成个性化学习宝!');
- } else {
- $fName = $type == 2 ? "个性化学习方案" : "个性化学习宝";
- // 下载文件名称
- $fileName = $classInfo->class_name.$examInfo->name."{$fName}.zip";
- // 下载文件路径
- $result = array();
- //$pdfPath = dirname(dirname(dirname(dirname(__FILE__)))).'/api/uploads/';
- $pdfPath = Yii::app()->params['student_wrong_isp_path'];
- foreach ($getPaths as $path) {
- /* if(file_exists(iconv("utf-8", "gbk//IGNORE", $pdfPath.$path->isp_pdf_path))){
- $result[] = $path->isp_pdf_path;
- } */
- if($type == 2){
- if(strpos($path->wrongbook_pdf_path,"data")!==false){
- $pathstr=$pdfPath.$path->isp_pdf_path;
- }else{
- $pathstr=$pdfPath."uploads/".$path->isp_pdf_path;
- }
- if(is_file($pathstr)){
- $result[] = $pathstr;
- }
- }
- else if($type == 3){
- if(strpos($path->wrongbook_pdf_path,"data")!==false){
- $pathstr=$pdfPath.$path->wbisp_pdf_path;
- }else{
- $pathstr=$pdfPath."uploads/".$path->wbisp_pdf_path;
- }
- if(is_file($pathstr)){
- $result[] = $pathstr;
- }
- }
- }
- if (empty($result)) {
- Yii::app()->jump->error('正在生成学生个性化学习宝!');
- }
- // 下载
- self::downloadStudentFile($fileName,$result);
- }
- }
- // 下载学生纠错本、个性化学习宝PDF
- function downloadStudentFile($fileName,$result) {
- if (empty($fileName) || empty($result)) {
- return false;
- }
- $downName = mb_convert_encoding($fileName, 'gbk', 'utf-8');
- $filename = dirname(dirname(dirname(__FILE__))).'/upload/'. uniqid().".zip"; //最终生成的文件名(含路径)
- $zip = new ZipArchive();//使用本类,linux需开启zlib,windows需取消php_zip.dll前的注释
- if ($zip->open($filename, ZIPARCHIVE::OVERWRITE)!==TRUE) {
- Yii::app()->jump->error('无法打开文件,或者文件创建失败');
- }
- //$pdfPath = dirname(dirname(dirname(dirname(__FILE__)))).'/api/uploads/';
- // $pdfPath = Yii::app()->params['student_wrong_isp_path'];
- foreach ($result as $val) {
- $res=$zip->addFile($val,mb_convert_encoding(preg_replace('/^.+[\\\\\\/]/', '', $val), 'GBK', 'UTF-8'));
- }
- $zip->close();//关闭
- if (is_file($filename)){
- if (FALSE!== ($handler = fopen($filename, 'r')))
- {
- header('Content-Description: File Transfer');
- header('Content-Type: application/octet-stream');
- header('Content-Disposition: attachment; filename='.$downName);
- header('Content-Transfer-Encoding: chunked'); //changed to chunked
- header('Expires: 0');
- header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
- header('Pragma: public');
- while (!feof($handler)) {
- file_put_contents("php://output", fread($handler, 4096));
- }
- fclose($handler);
- unlink($filename);
- }
- exit;
- }
- }
- // 获取周周练试卷详情(生成模板使用、打印答案解析使用)
- public function actionCreatetempelate(){
- $wpcode = Req::post("eid");
- $flag = Req::post("flag");
- $error['success'] = 0;
- if (empty($wpcode)) {
- $error['message'] = '么有周周练id!';
- echo json_encode($error);exit();
- }
- $_num= '';
- $use_version = '';
- if(isset(Yii::app()->session['coachInfo']->use_version))
- {
- $use_version = Yii::app()->session['coachInfo']->use_version;
- }else
- {
- $use_version = Yii::app()->session['coachInfo']['use_version'];
- }
- if(!$use_version)
- {
- $use_version = 100;
- }
- $version_number = implode('',explode('.',$use_version));
- if(strlen($version_number)<7)
- {
- for($i=0;$i<7-strlen($version_number);$i++)
- {
- $_num.='0';
- }
- }
- $version_number=(int)$version_number.$_num;
- $getRes = apiPost(Yii::app()->params['get_api_url'].'/coachio/iointerface_v2/getWpPapers', 'wpCode='.$wpcode);
- $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$wpcode));
- //获取本次考试的examids
- $exam_ids = array();
- if($exam_data)
- {
- $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id));
- $index_tpl = 0;
- if($exam_group_data)
- {
- foreach($exam_group_data as $v)
- {
- $exam_ids[$v->exam_id] = $v->exam_id;
- $index_tpl = $v->tpl_index;
- }
- }
- if(in_array($index_tpl,Yii::app()->params['print_topic_tpl']))
- {
- $flag = 0;
- }
- if($flag==3 || $flag==4 || $flag == 12)
- {
- $criteria = new CDbCriteria();
- $criteria->addInCondition('exam_id',$exam_ids);
- $criteria->addCondition('type=:type');
- $criteria->params[':type'] = 0;
- $getResult = ClassExamPrinter::model()->findAll($criteria);
- if (!empty($getResult)) {
- ClassExamPrinter::model()->updateAll(array('is_print'=>1,'print_time'=>time()),$criteria);
- }
- }
- if($flag==2 || $flag==11){
- $this->schoolManager->saveExamProcess($exam_data->exam_group_id,14,time());
- }else{
- $this->schoolManager->saveExamProcess($exam_data->exam_group_id,9,time());
- }
- }
- echo $getRes;die;
- }
- // 验证试卷是否已上传模板
- public function actionVerifyTpl(){
- $eid = Req::post('eid');
- $error['success'] = 0;
- if (empty($eid)) {
- $error['message'] = '考试信息不存在!';
- echo json_encode($error);exit();
- }
- $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid));
- if (empty($paperInfo)) {
- $error['message'] = '未找到试卷信息!';
- echo json_encode($error);exit();
- }
- if (empty($paperInfo->tpl_doc_src)) {
- $error['message'] = '未上传模板!';
- echo json_encode($error);exit();
- } else {
- $error['success'] = 1;
- $error['message'] = '已上传模板!';
- echo json_encode($error);exit();
- }
- //$getRes = apiPost(Yii::app()->params['get_api_url'].'/coachio/iointerface/getpapertpl', 'paperId='.$paperInfo->paper_id);
- //echo $getRes;
- }
- public function actionCheckAnswerCard(){
- $eid = Req::post('eid');
- $error['success'] = 0;
- if (empty($eid)) {
- $error['message'] = '考试信息不存在!';
- echo json_encode($error);exit();
- }
- $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid));
- if (empty($paperInfo)) {
- $error['message'] = '未找到试卷信息!';
- echo json_encode($error);exit();
- }
- if (empty($paperInfo->answer_card_src)) {
- $error['message'] = '未上传模板!';
- echo json_encode($error);exit();
- } else {
- $error['success'] = 1;
- $error['message'] = '已上传模板!';
- echo json_encode($error);exit();
- }
- }
- // 上传试卷模板
- public function actionUploadTpl(){
- $eid = Req::post('eid');
- $type = Req::post("type");
- $error['success'] = 0;
- if (empty($eid)) {
- $error['message'] = '周周练id不存在!';
- echo json_encode($error);exit();
- }
- $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid));
- if (empty($paperInfo)) {
- $error['message'] = '未找到试卷信息333!';
- echo json_encode($error);exit();
- }
- $examInfo = Exam::model()->findByPk($eid);
- if(empty($examInfo)){
- $error['message'] = '未找到统考信息!';
- echo json_encode($error);exit();
- }
- if (empty($_FILES['word_file'])) {
- $error['message'] = '未找到上传文件!';
- echo json_encode($error);exit();
- }
- if(!is_uploaded_file($_FILES['word_file']['tmp_name'])){
- $error['message'] = '非法上传!';
- echo json_encode($error);exit();
- }
- if ($_FILES['word_file']['error'] > 0) {
- switch ($_FILES['word_file']['error']) {
- case 1:
- $error['message'] = '文件大小超出了服务器的空间大小!';
- break;
- case 2:
- $error['message'] = '要上传的文件大小超出浏览器限制!';
- break;
- case 3:
- $error['message'] = '文件只有部分被上传!';
- break;
- case 4:
- $error['message'] = '没有找到要上传的文件!';
- break;
- case 5:
- $error['message'] = '服务器临时文件夹丢失!';
- break;
- case 6:
- $error['message'] = '文件写入到临时文件夹出错!';
- break;
- }
- echo json_encode($error);exit();
- }
- // 保存上传文件至服务器
- $pathName = dirname(dirname(dirname(__FILE__))).'/upload/tmpDir/word/'. date('Y') .'/'. date('m') . '/';
- if (!file_exists($pathName)) {
- mkdir($pathName, 0777, true);
- }
- $extName = substr($_FILES['word_file']['name'],strrpos($_FILES['word_file']['name'],'.'));
- $fileName = uniqid() . $extName;
- if (!move_uploaded_file($_FILES['word_file']['tmp_name'], $pathName.$fileName)) {
- $error['message'] = '上传文件失败!';
- echo json_encode($error);exit();
- }
- $param['tpl_name'] = $_FILES['word_file']['name'];
- $param['paperId'] = $paperInfo->paper_id;
- $param['templetA'] = $_FILES['word_file']['type'];
- $param['path_tpl'] = $pathName.$fileName;
- $fileSrc = $pathName.$fileName;
- //FIXME 20191224
- if(file_exists($fileSrc)){
- $rename = 'zsyas2/uploadTpl/'.$this->schoolId.'/'. date('Y') . '/' . date('m') . '/' . date('d').'/'. uniqid() . '/' . $extName;
- $ucloud = new HuaweiCloud();
- $uploadInfo = $ucloud->putFile($rename, $fileSrc);
- @unlink($fileSrc);
- if ($uploadInfo['status'] == 0) {
- $error['message'] = '上传文件失败!';
- echo json_encode($error);exit();
- }else{
- $examModel = new Exam();
- $examIds = $examModel->getExamIds($examInfo['exam_group_id']);
- if(empty($examIds)){
- $error['message'] = '上传文件失败!';
- echo json_encode($error);exit();
- }
- $uploadInfo['url'] = str_replace("%2F","/",$uploadInfo['url']);
- if($type == 1){
- $this->sConn->createCommand("update paper set tpl_doc_src = '{$uploadInfo['url']}' where exam_id in (".implode(',',$examIds).") ")->execute();
- }
- else if($type == 2){
- $this->sConn->createCommand("update paper set answer_card_src = '{$uploadInfo['url']}' where exam_id in (".implode(',',$examIds).") ")->execute();
- }
- else{
- $error['message'] = '上传文件失败!';
- echo json_encode($error);exit();
- }
- $error['success'] = 1;
- $error['message'] = '上传成功!';
- echo json_encode($error);exit();
- }
- }else{
- $error['message'] = '上传文件失败!';
- echo json_encode($error);exit();
- }
- }
- public function actionExportExcel(){
- $classId = Req::get("classId");
- $examId = Req::get("examId");
- $class = $this->schoolManager->getClass($classId);
- $exam = $this->schoolManager->getExam($examId);
- $className = $class ? $class["class_name"] : "";
- $wpName = $exam ? $exam["name"] : "";
- $report = $this->schoolManager->getExamRsByClass($examId, $classId, array(), "EXCEL");
- $excel = new Excel();
- $fileName = "{$className}-{$wpName}报告";
- $excel->export($report, $fileName);
- }
- public function actionReplaceIspTopicAct(){
- $planId = Req::post("planId");
- $previousTopicId = Req::post("previousTopicId");
- $newTopicId = Req::post("newTopicId");
- $rs = $this->schoolManager->replaceIspTopic($planId, $previousTopicId, $newTopicId);
- echo json_encode($rs);exit;
- }
- public function actionIspCheck(){
- $planId = Req::get("planId");
- $isp = $this->schoolManager->getIspInfo($planId);
- if(!$isp)
- Yii::app()->jump->error('个性化学习宝不存在');
- $topics = $this->schoolManager->getIspTopics($planId);
- $sections = $this->schoolManager->composeIspTopics($planId, $topics);
- unset($topics);
- $paper = $this->schoolManager->getExamPaper($isp["exam_id"]);
- $ispTopicsIds = $this->schoolManager->getIspTopicsIds($planId);
- $this->render("ispcheck", array(
- "topicSections" => $sections,
- "isp" => $isp,
- "planId" => $planId,
- "examId" => $isp["exam_id"],
- "paperId" => $paper ? $paper["paper_id"] : null,
- "ispTopicsIds" => implode(",", $ispTopicsIds),
- ));
- }
- public function actionAjaxGetPaperTopicReplace()
- {
- $error = array();
- $result = array();
- if ( ! Yii::app()->request->isAjaxRequest OR ! Yii::app()->request->isPostRequest)
- {
- $error[] = '错误的来源!';
- }
- else
- {
- $examId = Yii::app()->request->getPost('examId');
- $paperId = Yii::app()->request->getPost('paperId');
- $topicType = (int)Yii::app()->request->getPost('topicType');
- $topicId = (int)Yii::app()->request->getPost('topicId');
- $methodId = (int)Yii::app()->request->getPost('methodId');
- $methodDifficulty = (int)Yii::app()->request->getPost('methodDifficulty');
- $notIncludeTopicId = (int)Yii::app()->request->getPost('notIncludeTopicId');
- $num = (int)Yii::app()->request->getPost('num', 1);
- $isArray = (int)Yii::app()->request->getPost('isArray');
- $isFind = (int)Yii::app()->request->getPost('isFind');
- $notInTopicsIds = Req::post('notInTopicsIds');
- if ( ! $paperId OR ! is_numeric($paperId))
- {
- $error[] = '必须指定paperId';
- }
- else
- {
- $paperCls = new SPaper();
- $paperDetail = $paperCls->getDetailByPaperId($paperId);
- if ( ! $paperDetail)
- {
- $error[] = '未找到指定的 试卷';
- }
- }
- if ($topicType <= 0)
- {
- $error[] = '必须指定 topicType';
- }
- elseif ( ! in_array($topicType, array(1, 5, 7)))
- {
- $error[] = '不允许的 topicType';
- }
- if ($topicId <= 0)
- {
- $error[] = '必须指定 topicId';
- }
- if (empty($methodId))
- {
- $error[] = '必须指定 methodId';
- }
- if ($methodDifficulty <= 0 OR $methodDifficulty > 3)
- {
- $error[] = '不允许的 methodDifficulty';
- }
- if ($num <= 0) $num = 1;
- }
- if ( ! $error)
- {
- $paperTopicRelationCls = new SPaperTopicRelation();
- $paperTopicRelationDetail = $paperTopicRelationCls->getDetailByPaperId_TopicId($paperId, $topicId);
- if ( ! $paperTopicRelationDetail)
- {
- $error[] = '未找到指定的试题';
- }
- else
- {
- $topicScore = $paperTopicRelationDetail['score'];
- }
- }
- if ( ! $error)
- {
- $methodId = explode(",", $methodId);
- $notInTopicsIds = explode(",", $notInTopicsIds);
- $topicRule = array(
- 'num' => $num,
- 'score' => $topicScore,
- 'types' => $topicType,
- 'difficultys' => $methodDifficulty,
- 'methods' => $methodId,
- );
- // if ( ! $isFind)
- // {
- // $topicRule['difficultys'] = $methodDifficulty;
- // }
- $topicItem = $this->apiPost('/smart/pull', array(
- 'subjectId' => Yii::app()->params['subject_id'],
- 'notInTopicsIds' => $notInTopicsIds,
- 'rules' => array($topicRule),
- ));
- if (isset($topicItem->error))
- {
- $error[] = $topicItem->error;
- }
- else
- {
- if ( ! $isArray AND $num == 1)
- {
- $result = $topicItem[0];
- }
- else
- {
- $result = $topicItem;
- }
- }
- }
- if ( ! $error)
- {
- if ( ! $result)
- {
- $error[] = '未找到符合的题';
- }
- }
- //header('Content-Type: application/json');
- if ($error)
- {
- echo json_encode(array('status' => 0, 'error'=> implode('<br/>', $error)));exit;
- }
- else
- {
- $result = Obj::toArr($result);
- $topic = $this->schoolManager->getTopic($topicId);
- $topicMethosCount = isset($topic["specials"]) ? count($topic["specials"]) : 0;
- $matchTopics = array();
- foreach($result as $key => $val){
- $sameCount = 0;
- $diffCount = 0;
- if(isset($val["specials"]) && isset($topic["specials"])){
- $diff1 = Arr::diff($val["specials"], $topic["specials"]);
- $diff2 = Arr::diff($topic["specials"], $val["specials"]);
- if(!$diff1 && !$diff2){
- $matchTopics[] = $val;
- unset($result[$key]);
- continue;
- }
- if($diff1)
- $diffCount = count($diff1);
- $same = Arr::intersect($topic["specials"], $val["specials"]);
- if($same)
- $sameCount = count($same);
- }
- $result[$key]["methods_same_count"] = $sameCount;
- $result[$key]["methods_diff_count"] = $diffCount;
- }
- //按照考点不同点升序排序
- Arr::sortByField($result, "methods_diff_count");
- //按照考点相同点降序排序
- Arr::sortByField($result, "methods_same_count", "DESC");
- //合并完全匹配考点和部分匹配考点的题 完全匹配在前
- $result = Arr::merge($matchTopics, $result);
- echo json_encode($result);exit;
- }
- }
- public function actionSetPrintTransChecked(){
- $planId = Req::post("planId");
- $classId = Req::post("classId");
- $examId = Req::post("examId");
- $studentId = $this->schoolManager->getStudentIdByIspId($planId);
- $this->schoolManager->setStudentIspChecked($planId);
- $this->schoolManager->setPrintTransChecked($classId, $examId);
- $arr=array(
- 'cate' => 3,
- 'schoolId' => $this->schoolId,
- 'examId' => $examId,
- 'studentId'=>$studentId
- );
- $send_json=json_encode($arr);
- $stompconn = new Stomp(Yii::app()->params["activeMq"]["server"]);
- $stompconn->send("wb_isp_html", $send_json);
- unset($stompconn);
- $redis_obj = new Redis();
- $server = Yii::app()->params["redis"]["server"];
- $redis_obj->connect($server["host"], $server["port"]);
- $redis_obj->auth($server["password"]);
- $redis_obj->select(2);
- $redis_obj->set('activeMq.wb_isp_consumer.producer_time',time());
- $this->redirect($this->createUrl("print/studentsispslist?classId={$classId}&examId={$examId}"));
- }
- public function actionIspsList(){
- $getName = safe_replace(Yii::app()->request->getQuery('printName'));
- $getStatus = safe_replace(Yii::app()->request->getQuery('status'));
- $statusArray= array();
- if ($getStatus !== '') {
- $statusArray= array($getStatus);
- }
- // 打印任务处理
- $ExamModel = Exam::model();
- $ClassModel = ClassModel::model();
- $printList = array();
- // 获取当前学期班级并组装
- $class_array= ClassModel::model()->findAll('semester_id='.Yii::app()->session['session_semester_id']);
- $ccArray = array();
- $ccName = array();
- foreach ($class_array as $cc=>$ca) {
- array_push($ccArray, $ca->class_id);
- $ccName[$ca->class_id] = $ca->class_name;
- }
- if(Yii::app()->session['coachInfo']['leader'] == 1) {
- $resultList = $this->schoolManager->getPrintList(array("cep.type = 2"));
- }
- else{
- $resultList = $this->schoolManager->getPrintListOfCoach($this->coachId, array("cep.type = 2"));
- }
- if($resultList["rs"]){
- foreach ($resultList['rs'] as $k=>$v) {
- $printList[$k] = $v;
- $printList[$k]['class_name'] = @$ccName[$v["class_id"]];
- $pname = @$ExamModel->getExamName($v["exam_id"]); // 周周练名称
- if ($v["type"] == 1) {
- $printList[$k]['print_name']= $pname.'"纠错本"打印任务!';
- } elseif ($v["type"] == 2) {
- $printList[$k]['print_name']= $pname.'"个性化学习宝"打印任务!';
- } else {
- $printList[$k]['print_name']= $pname.'打印任务!';
- }
- }
- }
- $data = array();
- $data['getName'] = $getName;
- $data['status'] = $getStatus;
- $data['printList'] = $printList;
- $data['pages'] = $resultList['pager'];
- $data['page_total'] = $resultList['pager']->rowsCount;
- unset($resultList);
- $this->render("ispslist", $data);
- }
- public function actionStudentsIspsList(){
- $classId = Req::get("classId");
- $examId = Req::get("examId");
- $isps = $this->schoolManager->getClassStudentsIspsList($classId, $examId);
- $this->render("studentsispslist", array(
- "isps" => $isps,
- ));
- }
- public function actionUploadConfirm()
- {
- $error = array();
- if (Yii::app()->request->getIsPostRequest())
- {
- $classId = safe_replace(Yii::app()->request->getPost('classId'));
- $examId = safe_replace(Yii::app()->request->getPost('examId'));
- if ( ! $classId AND ! is_numeric($classId))
- {
- $error[] = 'Params: classId error.';
- }
- if ( ! $examId AND ! is_numeric($examId))
- {
- $error[] = 'Params: examId error.';
- }
- }
- else
- {
- $error[] = 'Must post request.';
- }
- if ( ! $error)
- {
- /*$relations = $this->schoolManager->getExamClassesRelations($examId);
- $uploadedRelations = $this->schoolManager->getExamClassesRelationsFilteredByUploadStatus($examId, 2);
- if (count($relations) == count($uploadedRelations))
- {*/
- $this->schoolManager->changeExamStatus($examId, 4);
- $this->schoolManager->changeExamUploadStatus($examId, 2);
- //}
- if (!$error && ($examGroupId = $this->schoolManager->getExamGroupIdByExamId($examId)))
- {
- $examIds = $this->schoolManager->getExamsIdsByExamGroupId($examGroupId);
- if ($examIds)
- {
- $exams = getAttributes(Exam::model()->findAll("exam_id IN (". implode(',', $examIds) .") AND upload_status = '2'"));
- if (count($examIds) == count($exams))
- {
- $examGroup = SExamGroup::model()->find('exam_group_id = :examGroupId', array(
- ':examGroupId' => $examGroupId
- ));
- $examGroup->upload_status = 2;
- $examGroup->save();
- }
- }
- }
- }
- if ($error)
- {
- echo json_encode(array('status' => 0, 'error' => implode(PHP_EOL, $error)));exit;
- }
- else
- {
- echo json_encode(array('status' => 1, 'error' => ''));exit;
- }
- }
- // // 更新试卷打印状态、时间
- public function actionUpdatepaperprinttime() {
- $cid = Req::post("cid");
- $eid = Req::post("eid");
- $type = Req::post("type");
- $getResult = ClassExamPrinter::model()->find('class_id=:cid and exam_id=:eid and type=:type',array(':cid'=>$cid,':eid'=>$eid,':type'=>$type));
- if (!empty($getResult)) {
- $getResult->is_print = 1;
- $getResult->print_time = time();
- if ($getResult->save()) {
- exit('1');
- } else {
- exit('2');
- }
- }
- }
- /* public function actionDownstudentexcel() {
- $filename="导入学生示例.xls";
- $path = dirname(dirname(__FILE__)).'/data/';
- $file=fopen($path.$filename,"r");
- Header("Content-type:application/octet-stream");
- Header("Accept-Ranges:bytes");
- header("Content-Type:application/msexcel");
- Header("Accept-Length:".filesize($path.$filename));
- Header("Content-Disposition:attachment;filename=".$filename);
- echo fread($file,filesize($path.$filename));
- fclose($file);
- } */
- /**
- * 发送/取消/重新发送标注
- */
- public function actionSendLabelTask(){
- $examId = Req::post("examId");
- $examName = Req::post("examName");
- $createTime = Req::post("createTime");
- $type = Req::post('type');
- $status = Req::post('status');
- $remark = Req::post('remark');
- $isTagging = Req::post('isTagging'); //新方法宝发送标注
- $estimate= Req::post('estimate'); //期望时间
- if(!$examId || !$examName || !$type){
- echo json_encode(array("success" => 0, "message" => "缺少必要参数"));
- exit();
- }
- if(!($paper = $this->schoolManager->getExamPaper($examId))){
- echo json_encode(array("success" => 0, "message" => "找不到试卷"));
- exit();
- }
- if(!($topicsRecords = $this->schoolManager->getPaperTopicsRecords($paper["paper_id"]))){
- echo json_encode(array("success" => 0, "message" => "找不到试卷题目"));
- exit();
- }
- $labelledType=$paper['labelled_type']; //标注类型
- $subjectId = 0;
- $examTime = time();
- if(($exam = $this->schoolManager->getExam($examId)) && isset($exam["tpl_data"]) && ($tplData = json_decode($exam["tpl_data"], true))){
- $subjectId = $this->schoolManager->getSubjectIdByTplData($tplData);
- if(isset($tplData["examDate"]))
- $examTime = strtotime($tplData["examDate"]);
- }
- //取消和重新发送的时候判断题库那边是否已经标注完成
- $sql = "select is_third,qxk_paper_id,is_tagging from exam_group where exam_group_id = '{$exam['exam_group_id']}'";
- $examGroup = $this->sConn->createCommand($sql)->queryRow();
- if ($status==='2' || $status==='4' || $status==='3'){
- $is_labelled = $paper['is_labelled'];
- if ($is_labelled==='1'){
- echo json_encode(array(
- 'success' => 2,
- 'message' => '已经标注完成,点击确定后刷新状态。'
- ));
- exit;
- }
- }
- $this->setIs_new($exam['exam_group_id']);
- if ($type=='cancel'){
- $title = '取消标注';
- }elseif ($type=='resend'){
- $title = '重新发送标注';
- }else{
- $title = '发送标注';
- }
- //操作日志
- if(Yii::app()->params['handle_log_on_off'])
- {
- writeFileLog(jsonEncode(array(
- "exam_group_id" => (string)$exam['exam_group_id'],
- "operate_project" => 'zsyas2',
- "title" => $title,
- "school_id" => $this->schoolId,
- "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')
- )));
- }
- //判断学科
- if($subjectId==8 && !$isTagging){
- $topics = array();
- foreach($topicsRecords as $topicRecord){
- $topics[$topicRecord["stem_id"]] = array(
- "topic_id" => $topicRecord["stem_id"],
- "school_id" => $topicRecord["mode"] ? $this->schoolId : 0,
- "topic_type" => $topicRecord["type"],
- "no" => $topicRecord["no"],
- );
- }
- $jsonArr = array();
- $jsonArr['exam_name'] = $examName;
- $jsonArr['school_id'] = $this->schoolId;
- $jsonArr['exam_group_id'] = $exam['exam_group_id'];
- $jsonArr['exam_time'] = $examTime;
- $jsonArr['origin'] = 'zxhx'; //校本课程平台试卷
- $jsonArr['exam_topic'] = $topics; //校本课程平台试卷
- if($type=='send' || $type=='resend'){
- $result = Curl::http_post_json(Yii::app()->params['english_send_mark'], json_encode($jsonArr));
- $resultArr=json_decode($result,true);
- if($resultArr['status'] == 1) {
- $sql = "select exam_id from exam where exam_group_id = '{$exam['exam_group_id']}'";
- $examAll = $this->sConn->createCommand($sql)->queryAll();
- $examArr = array();
- if ($examAll) {
- foreach ($examAll as $k => $v) {
- $examArr[] = $v['exam_id'];
- }
- $transcation = $this->sConn->beginTransaction();
- try {
- $this->sConn->createCommand("update paper set is_labelled = 3,labelled_type=1,send_labelled_time='".time()."' where exam_id in (" . implode(',', $examArr) . ")")->execute();
- $transcation->commit();
- $rs['success'] = 1;
- $rs = json_encode($rs);
- } catch (Exception $e) {
- $transcation->rollback();
- $error['message'] = '更新失败!';
- $error['success'] = 0;
- echo json_encode($error);
- exit();
- }
- } else {
- $error['message'] = '考试信息错误!';
- $error['success'] = 0;
- echo json_encode($error);
- exit();
- }
- }elseif($resultArr['status'] == 2){ //完成标注
- $rs['success'] = 1;
- $rs = json_encode($rs);
- }else{
- $error['message'] = $resultArr['message'];
- $error['success']=0;
- echo json_encode($error);exit();
- }
- }else{
- if($labelledType==2){
- if($this->schoolManager->sendLabelToTeacher($exam['exam_group_id'],'cancel')){
- $error['message'] = '取消成功';
- $error['success']=1;
- echo json_encode($error);exit();
- }else{
- $error['message'] = '取消失败';
- $error['success']=0;
- echo json_encode($error);exit();
- }
- }else{
- $result = Curl::http_post_json(Yii::app()->params['english_cancel_mark'], json_encode($jsonArr));
- $resultArr=json_decode($result,true);
- if($resultArr['status'] == 1){
- $error['message'] = '取消成功';
- $error['success']=1;
- echo json_encode($error);exit();
- }else{
- $error['message'] = $resultArr['message'];
- $error['success']=0;
- echo json_encode($error);exit();
- }
- }
- }
- }else if($subjectId==12 || Yii::app()->params['section']==0 || $isTagging){
- $topics = array();
- if($type=='send' && Yii::app()->params['section']==1){
- if(!$estimate){
- echo json_encode(array("success" => 0, "message" => "期望时间不能为空"));
- exit();
- }
- if(strtotime($estimate)<time()){
- echo json_encode(array("success" => 0, "message" => "期望时间不正确"));
- exit();
- }
- }
- if(!$isTagging && $examGroup['is_third']){
- if(!($topicsRecords = $this->schoolManager->getPaperTopicsRecordsByTopic($paper["paper_id"]))){
- echo json_encode(array("success" => 0, "message" => "找不到试卷题目"));
- exit();
- }
- foreach($topicsRecords as $topicRecord){
- $topics[] = array(
- "topic_id" => $topicRecord["topic_id"],
- "school_id" => $topicRecord["mode"] ? $this->schoolId : 0,
- "topic_type_id" => $topicRecord["bank_type"],
- );
- }
- }else{
- foreach($topicsRecords as $topicRecord){
- if($topicRecord["stem_id"]){
- $topics[(string)$topicRecord["stem_id"]] = array(
- "topic_id" => $topicRecord["stem_id"],
- "school_id" => $topicRecord["mode"] ? $this->schoolId : 0,
- "topic_type_id" => $topicRecord["logic_type"],
- );
- }else{
- $topics[] = array(
- "topic_id" => $topicRecord["topic_id"],
- "school_id" => $topicRecord["mode"] ? $this->schoolId : 0,
- "topic_type_id" => $topicRecord["logic_type"],
- );
- }
- }
- }
- $topics=array_values($topics);
- $orderType=array(); //学生订单类型
- if($type=='send' || $type=='resend'){
- //判断权限
- if(!in_array($this->schoolId,array(476,353,3922,3865))){
- if($isTagging && $this->subjectId==3) {
- $checkRs = $this->checkProductOrderDetail($exam['exam_group_id'], $subjectId, array(31, 1, 2, 3,66));
- }elseif($isTagging && $this->subjectId==8){
- $checkRs = $this->checkProductOrderDetail($exam['exam_group_id'], $subjectId, array(3,1));
- }elseif($isTagging){
- $checkRs=$this->checkProductOrderDetail($exam['exam_group_id'],$subjectId,array(31));
- }else{
- $checkRs=$this->checkLabelTaskOrderDetail($exam['exam_group_id'],$subjectId);
- }
- if($checkRs==-1){
- $error['message'] = '接口异常';
- $error['success']=0;
- echo json_encode($error);exit();
- }elseif($checkRs==-2){
- $error['message'] = '考试参数异常';
- $error['success']=0;
- echo json_encode($error);exit();
- }elseif(!$checkRs){
- $error['message'] = '参加本次考试的班级所有学生没有订购产品,不能发送标注';
- $error['success']=0;
- echo json_encode($error);exit();
- }
- $orderType=$checkRs;
- }
- }
- if(in_array($subjectId,$this->mathSubjectId) && $examGroup['qxk_paper_id']==0 && Yii::app()->params['section']==1){
- $orderType=array();
- $orderType[]=array(
- 'goodsTypeId'=>31,
- 'goodsTypeName'=>'方法宝'
- );
- }
- //读取班级相同题配置
- $isPushSameTrain=0;
- if($this->findExamClassSameTrain($exam['exam_group_id'],$subjectId)){
- $isPushSameTrain=1;
- }
- //计算预计时间
- $realEstimate=$this->ComputeCompleteTime($exam['exam_group_id']);
- if($estimate){
- $estimate=strtotime($estimate);
- if($estimate>$realEstimate['estimate']){
- $realEstimate['estimate']=$estimate;
- }
- }
- $classExamPinter = new SClassExamPrinter();
- $isNewLabel = $classExamPinter->getNewLabel($createTime);
- $classInfo=SClass::model()->getClassInfo($exam['class_id']);
- $gradeName=Yii::app()->params['grade_list'][$classInfo['grade']]['grade_name'];
- $provinceName=$this->schoolManager->getProvince($this->schoolInfo['province_id']);
- if($examGroup['is_third']){
- $examType='第三方';
- }else{
- $examType='云题库';
- }
- //是否百万校接口
- $is_bw=$this->checkSchoolBW();
- if ($type=='send'){
- $rs = Curl::post(Yii::app()->params['get_api_url'].'/rest/task_exam/index', array(
- "schoolId" => $this->schoolId,
- "subjectId" => $subjectId,
- "examGroupId" => (string)$exam['exam_group_id'],
- "examName" => $examName,
- "coachName" => isset($this->coachInfo['real_name'])?$this->coachInfo['real_name']:'',//助教名称
- "schoolName" => isset($this->schoolInfo['school_name'])?$this->schoolInfo['school_name']:'',//学校名称
- "examTopics" => $topics,
- "isTagging"=>$isTagging,
- 'isVariant'=>$isPushSameTrain,
- 'remark'=>$remark,
- 'testTime'=>$examTime,
- 'testNumber'=>$realEstimate['studentNumber'],
- 'isNewSchool'=>$isNewLabel,
- 'isMillionSchool'=>$is_bw,
- 'predictCompleteTime'=>$realEstimate['estimate'],
- 'qxkPaperId'=>$examGroup['qxk_paper_id'],
- 'orderType'=>$orderType,
- 'gradeName'=>$gradeName,
- 'provinceName'=>$provinceName,
- 'examType'=>$examType,
- ));
- $tplData['estimateTime']=$realEstimate['estimate'];
- $this->schoolManager->updateEstimateTime($exam['exam_group_id'],jsonEncode($tplData));
- }else{
- $rs = Curl::post(Yii::app()->params['get_api_url'].'/rest/task_exam/update_paper_status', array(
- "updateType" => $status,
- "schoolId" => $this->schoolId,
- "subjectId" => $subjectId,
- "examGroupId" => (string)$exam['exam_group_id'],
- "isTagging"=>$isTagging
- ));
- $apiReturn=json_decode($rs,1);
- }
- }else{
- $topics = array();
- foreach($topicsRecords as $topicRecord){
- $topics[] = array(
- "topic_id" => $topicRecord["topic_id"],
- "school_id" => $topicRecord["mode"] ? $this->schoolId : 0,
- "topic_type" => $topicRecord["type"],
- "is_null_method" => empty($topicRecord["method_ids"]) ? 1 : 0,
- );
- }
- if($type=='send' || $type=='resend'){
- //判断权限
- if(!in_array($this->schoolId,array(476,353))){
- $checkRs=$this->checkLabelTaskOrder($exam['exam_group_id'],$subjectId);
- if($checkRs==-1){
- $error['message'] = '接口异常';
- $error['success']=0;
- echo json_encode($error);exit();
- }elseif($checkRs==-2){
- $error['message'] = '考试参数异常';
- $error['success']=0;
- echo json_encode($error);exit();
- }elseif(!$checkRs){
- $error['message'] = '参加本次考试的班级所有学生没有订购产品,不能发送标注';
- $error['success']=0;
- echo json_encode($error);exit();
- }
- }
- }
- //读取班级相同题配置
- $isPushSameTrain=0;
- if($this->findExamClassSameTrain($exam['exam_group_id'])){
- $isPushSameTrain=1;
- }
-
- $classExamPinter = new SClassExamPrinter();
- $isNewLabel = $classExamPinter->getNewLabel($createTime);
- //统计班级和人数
- $is_bw =0; //是否百万校
- $class_number=0; //班级数量
- $student_number=0; //学生数量
- $countExamStudent=$this->schoolManager->countExamsAndStudents($exam['exam_group_id']);
- if($countExamStudent){
- if(isset($countExamStudent['classes'])){
- $class_number=$countExamStudent['classes'];
- }
- if(isset($countExamStudent['students'])){
- $student_number=$countExamStudent['students'];
- }
- }
- //是否百万校接口
- $is_bw=$this->checkSchoolBW();
- if (($labelledType==2 && $type=='resend') || $type=='send'){
- if($labelledType==2){
- $this->schoolManager->updatePaperLabelledType($exam['exam_group_id'],1);
- }
- $rs = Curl::post(Yii::app()->params['get_api_url'].'/rest/task_exam_topic/index', array(
- "schoolId" => $this->schoolId,
- "examId" => $examId,
- "examName" => $examName,
- "subjectId" => $subjectId,
- "examTime" => $createTime,
- "testTime" => $examTime,
- "exam_topic" => $topics,
- "exam_group_id" => (string)$exam['exam_group_id'],
- "real_name" => isset($this->coachInfo['real_name'])?$this->coachInfo['real_name']:'',//助教名称
- "create_time" => isset($this->coachInfo['create_time'])?$this->coachInfo['create_time']:'',//助教创建时间
- "is_new_label" => $isNewLabel,
- "remark" => $remark,//发送备注
- 'class_number'=>$class_number,
- 'student_number'=>$student_number,
- 'is_bw'=>$is_bw,
- 'isVariant'=>$isPushSameTrain,
- 'qxkPaperId'=>$examGroup['qxk_paper_id']
- ));
- }else{
- if($labelledType==2 && $type=='cancel'){
- if($this->schoolManager->sendLabelToTeacher($exam['exam_group_id'],'cancel')){
- $error['message'] = '取消成功';
- $error['success']=1;
- echo json_encode($error);exit();
- }else{
- $error['message'] = '取消失败';
- $error['success']=0;
- echo json_encode($error);exit();
- }
- }else{
- if($labelledType==2){
- $this->schoolManager->updatePaperLabelledType($exam['exam_group_id'],1);
- }
- $rs = Curl::post(Yii::app()->params['get_api_url'].'/rest/task_exam_topic/set_paper_status', array(
- "status" => $status,
- "schoolId" => $this->schoolId,
- "examId" => $examId,
- "exam_group_id" => (string)$exam['exam_group_id'],
- "real_name" => isset($this->coachInfo['real_name'])?$this->coachInfo['real_name']:'',//助教名称
- "create_time" => isset($this->coachInfo['create_time'])?$this->coachInfo['create_time']:'',//助教创建时间
- "is_new_label" => $isNewLabel,
- "remark" => $remark,//发送备注
- 'class_number'=>$class_number,
- 'student_number'=>$student_number,
- 'is_bw'=>$is_bw
- ));
- }
- }
- }
- $this->schoolManager->saveExamProcess($exam['exam_group_id'],1,time());
- echo $rs;exit;
- }
- //发送标注到教师端
- public function actionSendLabelToTeacher(){
- $examId = Req::post("examId");
- $type = Req::post('type');
- $status = Req::post('status');
- $remark = Req::post('remark');
- if(!$examId || !$type){
- echo json_encode(array("success" => 0, "message" => "缺少必要参数"));
- exit();
- }
- if(!($paper = $this->schoolManager->getExamPaper($examId))){
- echo json_encode(array("success" => 0, "message" => "找不到试卷"));
- exit();
- }
- if(!($topicsRecords = $this->schoolManager->getPaperTopicsRecords($paper["paper_id"]))){
- echo json_encode(array("success" => 0, "message" => "找不到试卷题目"));
- exit();
- }
- //取消和重新发送的时候判断题库那边是否已经标注完成
- if ($status==='2' || $status==='4' || $status==='3'){
- $is_labelled = $paper['is_labelled'];
- if ($is_labelled==='1'){
- echo json_encode(array(
- 'success' => 2,
- 'message' => '教师端已经标注完成,点击确定后刷新状态。'
- ));
- exit;
- }
- }
- if(($exam = $this->schoolManager->getExam($examId)) && isset($exam["tpl_data"]) && ($tplData = json_decode($exam["tpl_data"], true))){
- $subjectId = $this->schoolManager->getSubjectIdByTplData($tplData);
- }
- $this->setIs_new($exam['exam_group_id']);
- if ($type=='cancel'){
- $title = '取消标注';
- }elseif ($type=='resend'){
- $title = '重新发送标注';
- }else{
- $title = '发送标注';
- }
- //操作日志
- if(Yii::app()->params['handle_log_on_off'])
- {
- writeFileLog(jsonEncode(array(
- "exam_group_id" => (string)$exam['exam_group_id'],
- "operate_project" => 'zsyas2',
- "title" => $title,
- "school_id" => $this->schoolId,
- "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')
- )));
- }
- //判断学科
- if($type=='send' || $type=='resend'){
- //判断权限
- if(!in_array($this->schoolId,array(476,353))){
- $checkRs=$this->checkLabelTaskOrder($exam['exam_group_id'],$subjectId);
- if($checkRs==-1){
- $error['message'] = '接口异常';
- $error['success']=0;
- echo json_encode($error);exit();
- }elseif($checkRs==-2){
- $error['message'] = '考试参数异常';
- $error['success']=0;
- echo json_encode($error);exit();
- }elseif(!$checkRs){
- $error['message'] = '参加本次考试的班级所有学生没有订购产品,不能发送标注';
- $error['success']=0;
- echo json_encode($error);exit();
- }
- }
- }
- if($this->schoolManager->sendLabelToTeacher($exam['exam_group_id'],$type)){
- $error['message'] = '操作成功';
- $error['success']=1;
- $this->schoolManager->saveExamProcess($exam['exam_group_id'],1,time());
- echo json_encode($error);exit();
- }else{
- $error['message'] = '发送失败';
- $error['success']=0;
- echo json_encode($error);exit();
- }
- }
- //检查学生订单权限
- public function checkLabelTaskOrder($exam_group_id,$subjectId){
- $examData=$this->schoolManager->getExamsIdsByExamGroupId($exam_group_id);
- if(!$examData){
- return -2;
- }
- $examIds=array();
- foreach ($examData as $val){
- $examIds[]=$val;
- }
- $print_time=ClassExamPrinter::model()->findAll('exam_id=:exam_id and type=0',array(':exam_id'=>$examIds[0]));
- $studentIds=array();
- $rs = $this->sConn->createCommand("select student_id,class_id from student_paper_relation where exam_id in ( ".implode(',',$examIds)." ) and is_del=0")->queryAll();
- if(!$rs){
- return -2;
- }
- $class_id=0;
- foreach ($rs as $val){
- if(!$class_id){
- $class_id=$val['class_id'];
- }
- $studentIds[]=$val['student_id'];
- }
- $classinfo= ClassModel::model()->find("class_id=:id",array(":id"=>$class_id));
- if(in_array($subjectId,$this->mathSubjectId) && Yii::app()->params['section']==1){
- $subjectId=3;
- }
- $intarr=array(
- "subject"=>$subjectId,
- "grade"=>$classinfo->grade,
- "examTime"=>$print_time[0]->add_time,
- "students"=>$studentIds,
- );
- $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]);
- $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_all_limit_url"], json_encode($intarr),$basic),true);
- if(!$rs){
- return -1;
- }
- if(isset($rs['errCode']) && $rs['errCode']=="00" && isset($rs['data']['hasAnyPermit'])){
- if($rs['data']['hasAnyPermit']){
- return 1;
- }else{
- return 0;
- }
- }else{
- return -1;
- }
- }
- //检查指定产品学生订单权限
- public function checkProductOrder($exam_group_id,$subjectId,$classify=array()){
- $examData=$this->schoolManager->getExamsIdsByExamGroupId($exam_group_id);
- if(!$examData){
- return -2;
- }
- $examIds=array();
- foreach ($examData as $val){
- $examIds[]=$val;
- }
- $print_time=ClassExamPrinter::model()->findAll('exam_id=:exam_id and type=0',array(':exam_id'=>$examIds[0]));
- $studentIds=array();
- $rs = $this->sConn->createCommand("select student_id,class_id from student_paper_relation where exam_id in ( ".implode(',',$examIds)." ) and is_del=0")->queryAll();
- if(!$rs){
- return -2;
- }
- $class_id=0;
- foreach ($rs as $val){
- if(!$class_id){
- $class_id=$val['class_id'];
- }
- $studentIds[]=$val['student_id'];
- }
- $classinfo= ClassModel::model()->find("class_id=:id",array(":id"=>$class_id));
- if(in_array($subjectId,$this->mathSubjectId) && Yii::app()->params['section']==1){
- $subjectId=3;
- }
- if($classify){
- foreach ($classify as $item){
- $intarr[]=array(
- "subject"=>$subjectId,
- "grade"=>$classinfo->grade,
- "examTime"=>$print_time[0]->add_time,
- "students"=>$studentIds,
- 'clazzId'=>'',
- 'semester'=>$this->semesterId,
- 'classify'=>$item
- );
- }
- }
- $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]);
- $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_product_limit_url"], json_encode($intarr),$basic),true);
- if(!$rs){
- return -1;
- }
- if(isset($rs['errCode']) && $rs['errCode']=="00" && isset($rs['data']) && $rs['data']){
- foreach ($rs['data'] as $r){
- if(count($r)>0){
- return 1;
- }
- }
- return 0;
- }else{
- return -1;
- }
- }
- //检查指定产品学生订单权限并返回订单详细
- //examIds 用于添加删除班级判断订单,由于事务还没提交,所以直接查exam表数据不对
- public function checkProductOrderDetail($exam_group_id,$subjectId,$classify=array(),$notUpdateExamIds=array()){
- $examIds=array();
- if($notUpdateExamIds){
- $examIds=$notUpdateExamIds;
- }else{
- $examData=$this->schoolManager->getExamsIdsByExamGroupId($exam_group_id);
- if(!$examData){
- return -2;
- }
- foreach ($examData as $val){
- $examIds[]=$val;
- }
- }
- $print_time=ClassExamPrinter::model()->findAll('exam_id=:exam_id and type=0',array(':exam_id'=>$examIds[0]));
- $studentIds=array();
- $rs = $this->sConn->createCommand("select student_id,class_id from student_paper_relation where exam_id in ( ".implode(',',$examIds)." ) and is_del=0")->queryAll();
- if(!$rs){
- return -2;
- }
- $class_id=0;
- foreach ($rs as $val){
- if(!$class_id){
- $class_id=$val['class_id'];
- }
- $studentIds[]=$val['student_id'];
- }
- $classinfo= ClassModel::model()->find("class_id=:id",array(":id"=>$class_id));
- if(in_array($subjectId,$this->mathSubjectId) && Yii::app()->params['section']==1){
- $subjectId=3;
- }
- if($classify){
- foreach ($classify as $item){
- $intarr[]=array(
- "subject"=>$subjectId,
- "grade"=>$classinfo->grade,
- "examTime"=>$print_time[0]->add_time,
- "students"=>$studentIds,
- 'clazzId'=>'',
- 'semester'=>$this->semesterId,
- 'classify'=>$item
- );
- }
- }
- $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]);
- $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_product_limit_detail_url"], json_encode($intarr),$basic),true);
- if(!$rs){
- return -1;
- }
- if(isset($rs['errCode']) && $rs['errCode']=="00" && isset($rs['data'])){
- if( $rs['data']){
- return $rs['data'];
- }else{
- return 0;
- }
- }else{
- return -1;
- }
- }
- //检查学生订单权限,并返回学生订单类型
- public function checkLabelTaskOrderDetail($exam_group_id,$subjectId){
- $examData=$this->schoolManager->getExamsIdsByExamGroupId($exam_group_id);
- if(!$examData){
- return -2;
- }
- $examIds=array();
- foreach ($examData as $val){
- $examIds[]=$val;
- }
- $print_time=ClassExamPrinter::model()->findAll('exam_id=:exam_id and type=0',array(':exam_id'=>$examIds[0]));
- $studentIds=array();
- $rs = $this->sConn->createCommand("select student_id,class_id from student_paper_relation where exam_id in ( ".implode(',',$examIds)." ) and is_del=0")->queryAll();
- if(!$rs){
- return -2;
- }
- $class_id=0;
- foreach ($rs as $val){
- if(!$class_id){
- $class_id=$val['class_id'];
- }
- $studentIds[]=$val['student_id'];
- }
- $classinfo= ClassModel::model()->find("class_id=:id",array(":id"=>$class_id));
- if(in_array($subjectId,$this->mathSubjectId) && Yii::app()->params['section']==1){
- $subjectId=3;
- }
- $intarr=array(
- "subject"=>$subjectId,
- "grade"=>$classinfo->grade,
- "examTime"=>$print_time[0]->add_time,
- "students"=>$studentIds,
- );
- $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]);
- $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_product_any_limit_detail_url"], json_encode($intarr),$basic),true);
- if(!$rs){
- return -1;
- }
- if(isset($rs['errCode']) && $rs['errCode']=="00" && isset($rs['data'])){
- if($rs['data']){
- return $rs['data'];
- }else{
- return 0;
- }
- }else{
- return -1;
- }
- }
- public function actionGetImproveFile(){
- $examId = Req::get("examId");
- $classId = Req::get("classId");
- $type = Req::get("type");
- $studentsIds = Req::get("studentsIds");
- $printType = Req::get("printType");
- $students_ids = array();
- $is_isp_student_ids = array();
- $is_wbisp_student_ids = array();
- $is_wrongbook_student_ids = array();
- if(!$examId || !$classId || !$type){
- echo json_encode(array("success" => 0, "message" => "缺少参数"));
- exit();
- }
- if(!in_array($type, array(1, 2, 3))){
- echo json_encode(array("success" => 0, "message" => "参数错误[1]"));
- exit();
- }
- $groupInfo = Exam::model()->getGroupInfo($examId);
- if(empty($groupInfo)) exit(json_encode(array("success" => 0, "message" => "考试信息错误")));
- $typeRel = array('1'=>'wb_group_id','2'=>'isp_group_id','3'=>'wbisp_group_id');
- $groupId = $groupInfo[$typeRel[$type]];
- if(!empty($groupId)){
- $apiUrl = isset(Yii::app()->params["improve_url"][$groupId]) ? Yii::app()->params["improve_url"][$groupId] : null;
- }else{
- $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
- }
- //$apiUrl = isset(Yii::app()->params["improve_url"][$groupId]) ? Yii::app()->params["improve_url"][$groupId] : null;
- // $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
- // echo $apiUrl;exit;
- //$apiUrl = isset(Yii::app()->params["improve_url"][0]) ? Yii::app()->params["improve_url"][0] : null;
- if(!$apiUrl){
- echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
- exit();
- }
- $params = array(
- "schoolId" => $this->schoolId,
- "examId" => $examId,
- "classId" => $classId,
- "type" => $type,
- "studentIds" => array(),
- );
- $classinfo= ClassModel::model()->find("class_id=:id",array(":id"=>$classId));
- $Sem=new SSemester();
- $code= $Sem->conn->createQuery()
- ->from('semester')
- ->where("semester_id = '".$classinfo['semester_id']."'")
- ->limit(1)
- ->query()
- ->read();
- $print_time=ClassExamPrinter::model()->findAll('exam_id=:exam_id and class_id=:classid and type=0',array(':exam_id'=>$examId,':classid'=>$classId));
- $intarr=array(
- "schoolId"=>$this->schoolId,
- "clazzId"=>$classId,
- "semester"=>$code['refer_code'],
- "grade"=>$classinfo['grade'],
- "students"=>array(),
- "examTime"=>$print_time[0]->add_time,
- "classify"=>$type,
- );
- //判断学科
- $examInfo = Exam::model()->findByPk($examId);
- $intarr['subject']=$examInfo['subject_id'];
- if($intarr['subject']==6){
- $intarr['subject']=3;
- }
- if(in_array($intarr['subject'],$this->mathSubjectId)){
- $intarr['subject']=3;
- }
- if ($studentsIds) {
- $studentsIds = explode(",", $studentsIds);
- foreach ($studentsIds as $key => $val) {
- $val = trim($val);
- if ($val == null) {
- unset($studentsIds[$key]);
- continue;
- }
- $students_ids[$val] = $val;
- $studentsIds[$key] = $val;
- }
- $intarr['students'] = $studentsIds;
- $stu = SStudentPaperRelation::model()->findAll("exam_id=:eid", array(":eid" => $examId));
- foreach ($stu as $key => $val) {
- if (isset($students_ids[$val->student_id])) {
- if ($val->is_isp_pdf == 1) {
- $is_isp_student_ids[$val->student_id] = $val->student_id;
- }
- if ($val->is_wbisp_pdf == 1) {
- $is_wbisp_student_ids[$val->student_id] = $val->student_id;
- }
- if ($val->is_wrongbook_pdf == 1) {
- $is_wrongbook_student_ids[$val->student_id] = $val->student_id;
- }
- }
- }
- } else {
- $stu = SStudentPaperRelation::model()->findAll("class_id=:class_id and exam_id=:eid", array(":class_id" => $classId, ":eid" => $examId));
- foreach ($stu as $key => $val) {
- $intarr['students'][] = $val->student_id;
- if ($val->is_isp_pdf == 1) {
- $is_isp_student_ids[$val->student_id] = $val->student_id;
- }
- if ($val->is_wbisp_pdf == 1) {
- $is_wbisp_student_ids[$val->student_id] = $val->student_id;
- }
- if ($val->is_wrongbook_pdf == 1) {
- $is_wrongbook_student_ids[$val->student_id] = $val->student_id;
- }
- }
- }
- $limitinfo="";
- //third_wb第三方多学科和英语不需要权限
- // $subject_id = isset(Yii::app()->session['session_subject_id'])?Yii::app()->session['session_subject_id']:0;
- // $params["subjectId"] = $subject_id;
- // if($printType == 'third_wb' || $printType == 'third_isp' || $subject_id == 8){
- // if($printType == 'third_isp'){
- // $params["subjectId"] = 8;
- // $params["type"] = 2;
- // }
- // if($intarr["students"]){
- // $params["studentIds"] = $intarr["students"];
- // }
- // }else{
- $_schoolId = isset(Yii::app()->session['coachInfo']['school_id'])?Yii::app()->session['coachInfo']['school_id']:0;
- if($printType == 'third_isp'){
- $params["subjectId"] = 8;
- $params["type"] = 3;
- }
- if ($_schoolId) {
- $schoolInfo = BusinessSchool::model()->find('school_id=:school_id', array(':school_id' => $_schoolId));
- }
- // if(isset(Yii::app()->session['testFlag']) && (Yii::app()->session['testFlag']==1)){
- if(isset($schoolInfo['is_allow_download']) && ($schoolInfo['is_allow_download']==1)){
- if($studentsIds){
- $params["studentIds"] = $studentsIds;
- }
- }else{
- if(Yii::app()->params["limit_open"]){
- $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]);
- $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr),$basic));
- if(!$rs){
- Yii::app()->jump->error("接口错误");
- }
- if($rs->errCode!="00"){
- echo json_encode(array("success" => 0, "message" => $rs->errMsg));
- exit();
- }
- if(!empty($rs->data)){
- $params["studentIds"]=$rs->data;
- if(count($rs->data)<count($intarr['students'])){
- $limitinfo="购买过的".count($intarr['students'])-count($rs->data)."位学生可下载";
- }
- } else{
- echo json_encode(array("success" => 0, "message" =>"请先购买商品"));
- exit();
- }
- }else{
- if($studentsIds){
- $params["studentIds"] = $studentsIds;
- }
- }
- }
- // }
- $rs = Curl::post($apiUrl."/rest/download_pdf/index", $params);
- if(!($rs = json_decode($rs))){
- $rs = array(
- "success" => 0,
- "message" => "请求接口失败",
- );
- }
- if($printType != 'third_wb'){
- if($limitinfo!=""&&$rs->success!=0){
- $rs->success=2;
- $rs->limitinfo=$limitinfo;
- }
- }
- if($type==1)
- {
- $criteria = new CDbCriteria();
- $_students = array();
- if(!is_array($params["studentIds"]) && $params["studentIds"]==1)
- {
- $_students = $is_wrongbook_student_ids;
- }else
- {
- foreach($params["studentIds"] as $v)
- {
- if(isset($is_wrongbook_student_ids[$v]))
- {
- $_students[] = $v;
- }
- }
- }
- if($_students){
- $criteria->addInCondition('student_id',$_students);
- }else{
- $criteria->addCondition('(is_complete = :is_complete and is_feedback = :is_complete) or is_del = :is_complete ');
- $criteria->params[':is_complete'] = 1;
- $criteria->params[':is_feedback'] = 1;
- $criteria->params[':is_del'] = 1;
- }
- if($studentsIds || count($studentsIds)>0)
- {
- $criteria->addInCondition('student_id',$studentsIds);
- }else
- {
- $criteria->addCondition('class_id=:class_id');
- $criteria->params[':class_id'] = $classId;
- }
- $criteria->addCondition('exam_id=:exam_id');
- $criteria->addCondition('is_wrongbook_download=:is_wrongbook_download');
- $criteria->params[':exam_id'] = $examId;
- $criteria->params[':is_wrongbook_download'] = 0;
- SStudentPaperRelation::model()->updateAll(array('is_wrongbook_download'=>1,'download_wrongbook_time'=>time()),$criteria);
- }
- if($type==2)
- {
- $criteria = new CDbCriteria();
- $_students = array();
- if(!is_array($params["studentIds"]) && $params["studentIds"]==1)
- {
- $_students = $is_isp_student_ids;
- }else
- {
- foreach($params["studentIds"] as $v)
- {
- if(isset($is_isp_student_ids[$v]))
- {
- $_students[] = $v;
- }
- }
- }
- if($_students){
- $criteria->addInCondition('student_id',$_students);
- }else{
- $criteria->addCondition('(is_complete = :is_complete and is_feedback = :is_complete) or is_del = :is_complete ');
- $criteria->params[':is_complete'] = 1;
- $criteria->params[':is_feedback'] = 1;
- $criteria->params[':is_del'] = 1;
- }
- if($studentsIds || count($studentsIds)>0)
- {
- $criteria->addInCondition('student_id',$studentsIds);
- }else
- {
- $criteria->addCondition('class_id=:class_id');
- $criteria->params[':class_id'] = $classId;
- }
- $criteria->addCondition('exam_id=:exam_id');
- $criteria->addCondition('is_two_isp_download=:is_two_isp_download');
- $criteria->params[':exam_id'] = $examId;
- $criteria->params[':is_two_isp_download'] = 0;
- SStudentPaperRelation::model()->updateAll(array('is_two_isp_download'=>1,'download_two_isp_time'=>time()),$criteria);
- }
- if($type==3)
- {
- $criteria = new CDbCriteria();
- $_students = array();
- if(!is_array($params["studentIds"]) && $params["studentIds"]==1)
- {
- $_students = $is_wbisp_student_ids;
- }else
- {
- foreach($params["studentIds"] as $v)
- {
- if(isset($is_wbisp_student_ids[$v]))
- {
- $_students[] = $v;
- }
- }
- }
- if($_students){
- $criteria->addInCondition('student_id',$_students);
- }else{
- $criteria->addCondition('(is_complete = :is_complete and is_feedback = :is_complete) or is_del = :is_complete ');
- $criteria->params[':is_complete'] = 1;
- $criteria->params[':is_feedback'] = 1;
- $criteria->params[':is_del'] = 1;
- }
- if($studentsIds || count($studentsIds)>0)
- {
- $criteria->addInCondition('student_id',$studentsIds);
- }else
- {
- $criteria->addCondition('class_id=:class_id');
- $criteria->params[':class_id'] = $classId;
- }
- $criteria->addCondition('exam_id=:exam_id');
- $criteria->addCondition('is_three_isp_download=:is_three_isp_download');
- $criteria->params[':exam_id'] = $examId;
- $criteria->params[':is_three_isp_download'] = 0;
- SStudentPaperRelation::model()->updateAll(array('is_three_isp_download'=>1,'download_three_isp_time'=>time()),$criteria);
- }
- if($groupId && isset($rs->downloadPath)){
- if (YII_ENV == 'pro' || YII_ENV == 'production') {
- $rs->downloadPath = preg_replace('/http\:\/\/zstatic\d{1,2}/','http://zstatic'.$groupId,$rs->downloadPath);
- }
- }
- echo json_encode($rs);exit;
- }
- public function setIs_new($exam_group_id)
- {
- if($exam_group_id)
- {
- Exam::model()->updateAll(array('is_new'=>1),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- }
- }
- public function actionSetPaperSize(){
- $examId = Req::post("examId");
- $paperSize = Req::post("paperSize");
- $mark_type = Req::post("mark_type");
- $tpl_index = Req::post("tpl_index");
- $exam_ids = array();
- if(!$examId)
- $this->output(0, "参数错误[1]");
- if(!$paperSize)
- $this->output(0, "参数错误[2]");
- if(!in_array($paperSize, array("A3", "A4", "8K", "16K")))
- $this->output(0, "参数错误[3]");
- $paper_data = SPaper::model()->find('exam_id=:exam_id',array(':exam_id'=>$examId));
- $paper_topic_m_data = array();
- if($paper_data)
- {
- $paper_topic_data = SPaperTopicRelation::model()->findAll('paper_id=:paper_id',array(':paper_id'=>$paper_data->paper_id));
- if($paper_topic_data)
- {
- foreach($paper_topic_data as $v)
- {
- $paper_topic_m_data[$v->type][] = $v->topic_id;
- }
- //30 ,30 15
- if(((isset($paper_topic_m_data[1]) && count($paper_topic_m_data[1])>30 && in_array($paperSize, array("A4", "8K", "16K"))) || (isset($paper_topic_m_data[5]) && count($paper_topic_m_data[5])>30 && in_array($paperSize, array("A4", "8K", "16K"))) || (isset($paper_topic_m_data[7]) && count($paper_topic_m_data[7])>15 && in_array($paperSize, array("A4", "8K", "16K")))))
- {
- $this->output(0, "题数太多,无法切换");
- }
- }
- }
- $paperSizesAndTplIndexesRelations = array(
- "A3" => 12,
- "A4" => 13,
- "8K" => 14,
- "16K" => 15,
- );
- if(in_array($tpl_index,Yii::app()->params["merge_topic_tpl"]))
- {
- $paperSizesAndTplIndexesRelations = array(
- "A3" => 16,
- "A4" => 17,
- "8K" => 18,
- "16K" => 19,
- );
- }
- if(in_array($tpl_index,Yii::app()->params["merge_topic_tpl1"]))
- {
- $paperSizesAndTplIndexesRelations = array(
- "A3" => 2012,
- "A4" => 2013,
- "8K" => 2014,
- "16K" => 2015,
- );
- }
- if(in_array($tpl_index,Yii::app()->params["merge_topic_tpl2"]))
- {
- $paperSizesAndTplIndexesRelations = array(
- "A3" => 2016,
- "A4" => 2017,
- "8K" => 2018,
- "16K" => 2019,
- );
- }
- if(in_array($tpl_index,Yii::app()->params["merge_topic_tpl3"]))
- {
- $paperSizesAndTplIndexesRelations = array(
- "A3" => 1012,
- "A4" => 1013,
- "8K" => 1014,
- "16K" => 1015,
- );
- }
- if(in_array($tpl_index,Yii::app()->params["merge_topic_tpl4"]))
- {
- $paperSizesAndTplIndexesRelations = array(
- "A3" => 1016,
- "A4" => 1017,
- "8K" => 1018,
- "16K" => 1019,
- );
- }
- if(in_array($tpl_index,Yii::app()->params["merge_topic_tpl5"]))
- {
- $paperSizesAndTplIndexesRelations = array(
- "A3" => 3016,
- "A4" => 3017,
- "8K" => 3018,
- "16K" => 3019,
- );
- }
- if(in_array($tpl_index,Yii::app()->params["merge_topic_tpl6"]))
- {
- $paperSizesAndTplIndexesRelations = array(
- "A3" => 3012,
- "A4" => 3013,
- "8K" => 3014,
- "16K" => 3015,
- );
- }
- if(in_array($tpl_index,Yii::app()->params["merge_topic_tpl7"]))
- {
- $paperSizesAndTplIndexesRelations = array(
- "A3" => 4016,
- "A4" => 4017,
- "8K" => 4018,
- "16K" => 4019,
- );
- }
- if(in_array($tpl_index,Yii::app()->params["merge_topic_tpl8"]))
- {
- $paperSizesAndTplIndexesRelations = array(
- "A3" => 4012,
- "A4" => 4013,
- "8K" => 4014,
- "16K" => 4015,
- );
- }
- $exam_row = Exam::model()->find(array(
- 'select'=>array('exam_id,exam_group_id'),
- 'condition' => 'exam_id=:exam_id',
- 'params' => array(':exam_id'=>$examId)
- ));
- if($exam_row)
- {
- $exam_data = Exam::model()->findAll(array(
- 'select'=>array('exam_id,exam_group_id'),
- 'condition' => 'exam_group_id=:exam_group_id',
- 'params' => array(':exam_group_id'=>$exam_row->exam_group_id)
- ));
- if($exam_data)
- {
- foreach($exam_data as $v)
- {
- $exam_ids[$v->exam_id] = $v->exam_id;
- }
- if($exam_ids)
- {
- $exam_group_array = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_row->exam_group_id));
- if(!$exam_group_array )
- {
- $this->output(0, "非法数据");
- }
- if($exam_group_array->upload_status>0)
- {
- $this->output(0, "无法修改,已上传数据");
- }
- //操作日志
- if(Yii::app()->params['handle_log_on_off'])
- {
- writeFileLog(jsonEncode(array(
- "exam_group_id" => (string)$exam_row->exam_group_id,
- "operate_project" => 'zsyas2',
- "school_id" => $this->schoolId,
- "title" => '更改试卷阅卷与纸张',
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $this->getRoute(),
- "operate_sql" => json_encode(array('update'=>array(
- 'ExamGroup'=>array('mark_type'=>$mark_type),
- 'exam'=>array('tpl_index'=>$paperSizesAndTplIndexesRelations[$paperSize],'update_time'=>time()),
- ))),
- "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
- "date"=>date('Y-m-d H:i:s')
- )));
- }
- $this->setIs_new($exam_row->exam_group_id);
- if(is_null($mark_type))
- {
- $mark_type = $exam_group_array->mark_type;
- }
- if(is_numeric($mark_type))
- {
- $transaction = $this->sConn->beginTransaction();
- try{
- if($exam_group_array->mark_type==4)
- {
- $this->sConn->createCommand("update exam set tpl_index = '{$paperSizesAndTplIndexesRelations[$paperSize]}',update_time =".time()." where exam_id in (".implode(',',$exam_ids).") and tpl_index in (".implode(',',$paperSizesAndTplIndexesRelations).")")->execute();
- }else
- {
- if($mark_type==4)
- {
- $this->sConn->createCommand("update exam set tpl_index = '{$paperSizesAndTplIndexesRelations[$paperSize]}',update_time =".time()." where exam_id in (".implode(',',$exam_ids).") and tpl_index in (".implode(',',$paperSizesAndTplIndexesRelations).")")->execute();
- }
- if($mark_type!=4 && $exam_group_array->mark_type!=4)
- {
- if($exam_group_array->mark_status == 0 )
- {
- ExamGroup::model()->updateAll(array('mark_type'=>$mark_type),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_row->exam_group_id));
- $this->sConn->createCommand("update exam set tpl_index = '{$paperSizesAndTplIndexesRelations[$paperSize]}',update_time =".time()." where exam_id in (".implode(',',$exam_ids).") and tpl_index in (".implode(',',$paperSizesAndTplIndexesRelations).")")->execute();
- }else
- {
- //ExamGroup::model()->updateAll(array('mark_type'=>$mark_type),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_row->exam_group_id));
- $this->sConn->createCommand("update exam set tpl_index = '{$paperSizesAndTplIndexesRelations[$paperSize]}' where exam_id in (".implode(',',$exam_ids).") and tpl_index in (".implode(',',$paperSizesAndTplIndexesRelations).")")->execute();
- }
- }
- }
- $transaction->commit();
- }catch(Exception $e)
- {
- $transaction->rollBack();
- $this->output(0, "更改失败");
- }
- }
- }
- }
- }
- $this->output(1, "更改成功");
- }
- /**
- * 设置阅卷方式
- */
- public function actionSetmasktype(){
- $exam_group_id = Req::post("exam_group_id");
- $mark_type = Req::post("mark_type");
- $tpl_index = Req::post("tpl_index");
- $exam_ids = array();
- if(!$exam_group_id)
- $this->output(0, "参数错误[1]");
- $exam_group_array = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- if(!$exam_group_array )
- {
- $this->output(0, "非法数据");
- }
- if($exam_group_array['upload_status']>0){
- $this->output(0, "已上传成绩不能修改阅卷方式");
- }
- $thirdAnswerSheet=SThirdAnswerSheet::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- if($exam_group_array['is_third']==1 || $exam_group_array['is_scan_changed']==1){
- if($thirdAnswerSheet && $thirdAnswerSheet['online_card']==0 && $mark_type==0){
- $this->output(0, "切割模板考试不能切换线下阅卷");
- }
- }
- if($thirdAnswerSheet && $thirdAnswerSheet['online_card']==1 && $mark_type==0){
- //判断答题卡评阅类型
- $check = $this->sConn->createCommand("select `marking_papers` from online_card_multiplex where multiplex_id='{$thirdAnswerSheet['multiplex_id']}'")->queryRow();
- if($check['marking_papers']!=1){
- $this->output(0, "当前在线答题卡的评阅方式为网阅,不支持修改为线下阅卷,请进入在线答题卡修改评阅方式为手批后再更改阅卷方式!");
- }
- }
- if(!in_array($mark_type,array(0,3,4))) $this->output(0, "阅卷方式不正确");
- $transaction = $this->sConn->beginTransaction();
- try{
- if($exam_group_array['mark_type']==4 || $mark_type==4){
- $this->sConn->createCommand("delete from marking_topic where exam_group_id='{$exam_group_id}'")->execute();
- }
- if($mark_type==4){
- $exam=$this->sConn->createCommand("select exam_id,tpl_data,subject_id from exam where exam_group_id='{$exam_group_id}'")->queryRow();
- $paper=$this->sConn->createCommand("select paper_id from paper where exam_id='{$exam['exam_id']}'")->queryRow();
- $paperTopic=$this->sConn->createCommand("select `order`,question_count,`type`,topic_id,score from paper_topic_relation where paper_id='{$paper['paper_id']}' and `type` not in(1,2,11)")->queryAll();
- if($paperTopic){
- $topicAutoType=array();
- if($exam['subject_id']==8){
- $tplData=json_decode($exam['tpl_data'],true);
- if(isset($tplData['new_items'])){
- foreach ($tplData['new_items'] as $item){
- $topicAutoType[$item['id']]=$item['logic_type'];
- }
- }
- }
- foreach ($paperTopic as $item){
- $autoType=0;
- if(isset($topicAutoType[$item['order']])){
- if(in_array($topicAutoType[$item['order']],array(13,16,17)) && $item['question_count']==0){
- $autoType=1;
- }elseif($item['type']==5){
- $autoType=2;
- }
- }
- $this->sConn->createCommand()->insert('marking_topic', array(
- 'exam_group_id' => $exam_group_id,
- 'topic_id' => $item['topic_id'],
- 'topic_type' => $item['type'],
- 'topic_index' =>$item['order'],
- 'topic_no' =>$item['order'],
- 'topic_score' =>$item['score'],
- 'auto_type'=>$autoType
- ));
- }
- }
- ExamGroup::model()->updateAll(array('mark_type'=>$mark_type,'mark_status'=>1),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- }else{
- ExamGroup::model()->updateAll(array('mark_type'=>$mark_type,'mark_status'=>0),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- }
- $transaction->commit();
- }catch(Exception $e)
- {
- $transaction->rollBack();
- if(Yii::app()->params['handle_log_on_off'])
- {
- writeFileLog(jsonEncode(array(
- "exam_group_id" => (string)$exam_group_id,
- "operate_project" => 'zsyas2',
- "school_id" => $this->schoolId,
- "title" => '更改阅卷方式失败',
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $this->getRoute(),
- "operate_sql" => json_encode(array('update'=>array(
- 'ExamGroup'=>array('mark_type'=>$mark_type),
- ))),
- "error"=>$e->getMessage(),
- "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
- "date"=>date('Y-m-d H:i:j')
- )));
- }
- $this->output(0, "更改失败");
- }
- if(Yii::app()->params['handle_log_on_off'])
- {
- writeFileLog(jsonEncode(array(
- "exam_group_id" => (string)$exam_group_id,
- "operate_project" => 'zsyas2',
- "school_id" => $this->schoolId,
- "title" => '更改阅卷方式',
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $this->getRoute(),
- "operate_sql" => json_encode(array('update'=>array(
- 'ExamGroup'=>array('mark_type'=>$mark_type),
- ))),
- "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
- "date"=>date('Y-m-d H:i:j')
- )));
- }
- $this->output(1, "更改成功");
- }
- // 操作周周练显示状态
- public function actionOprateexam(){
- $exam_groupId = Req::post("exam_groupId");
- $flag = Req::post("flag");
- $error['success'] = 0;
- if (empty($exam_groupId)) {
- $error['message'] = '操作失败!';
- echo json_encode($error);exit();
- }
- $this->setIs_new($exam_groupId);
- if ($this->schoolManager->oprateExamDisplay($exam_groupId,$flag)) {
- $error['success'] = 1;
- $error['message'] = '操作成功!';
- } else {
- $error['message'] = '操作失败!';
- }
- echo json_encode($error);exit();
- }
- // 根据年级获取班级
- public function actionGetGradeClass(){
- $grade = Req::post('grade');
- $subjectId = Req::post('subjectId');
- $filterHide=Req::post('filterHide');
- if(!$filterHide){
- $filterHide=0;
- }else{
- $filterHide=1;
- }
- $error['success'] = 0;
- if (empty($grade)) {
- $error['message'] = '未找到年级!';
- echo json_encode($error);exit();
- }
- $classes=array();
- //判断走班设置
- if($subjectId){
- $classified=$this->schoolManager->getSubjectByGrade($grade,$subjectId,Yii::app()->session['session_semester_id']);
- if($classified){
- $classes=$this->schoolManager->getClassifiedBySubjectId($grade,$subjectId,Yii::app()->session['session_semester_id']);
- }else{
- $classes = $this->schoolManager->getSchoolByGrade($grade,Yii::app()->session['session_semester_id']);
- }
- }else{
- $classes = $this->schoolManager->getSchoolByGrade($grade,Yii::app()->session['session_semester_id']);
- }
- if ($classes) {
- $error['success'] = 1;
- $error['message'] = $classes;
- } else {
- $error['message'] = '未找到班级!';
- }
- echo json_encode($error);exit();
- }
- // 根据年级获取班级
- public function actionGetGradeClassForExport(){
- $grade = Req::post('grade');
- $subjectId = Req::post('subjectId');
- $error['success'] = 0;
- if (empty($grade)) {
- $error['message'] = '未找到年级!';
- echo json_encode($error);exit();
- }
- $classes=array();
- $classes = $this->schoolManager->getSchoolByGrade($grade,Yii::app()->session['session_semester_id']);
- if ($classes) {
- $error['success'] = 1;
- $error['message'] = $classes;
- } else {
- $error['message'] = '未找到班级!';
- }
- echo json_encode($error);exit();
- }
- /**
- * 作者:刘红伟
- * 需求:删除本次考试,但已经考完的学生不能删除
- * 时间:2016-10-25
- */
- public function actionDelPaperStudent()
- {
- $studentsIds = Req::post('studentsIds');
- $exam_id = Req::post('exam_id');
- $paper_id = Req::post('paper_id');
- $class_id = Req::post('class_id');
- if(!$studentsIds || !$exam_id || !$paper_id)
- {
- echo json_encode(array('status'=>0));exit;
- }
- $studentsIds = explode(',',$studentsIds);
- if($this->schoolManager->getStudentByStudentIdsAndParperIdAndExamId($studentsIds,$paper_id,$exam_id))
- {
- echo json_encode(array('status'=>2));exit;
- };
- if($this->schoolManager->delStudentPaperByStudentAndPaperAndExamId($studentsIds,$paper_id))
- {
- $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id));
- //操作日志
- if(Yii::app()->params['handle_log_on_off'])
- {
- writeFileLog(jsonEncode(array(
- "exam_group_id" => (string)$exam_data->exam_group_id,
- "operate_project" => 'zsyas2',
- "school_id" => $this->schoolId,
- "title" => '删除考试的学生',
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $this->getRoute(),
- "operate_sql" => json_encode(array('delete'=>array(
- 'student_paper_relation'=>array('student_id'=>$studentsIds)))),
- "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
- "date"=>date('Y-m-d H:i:j')
- )));
- }
- //发送学生端消息
- //
- $sendJsonArr=array(
- 'school_id'=>$this->schoolId,
- 'send_type'=>'zsyas',
- 'update_type'=>2,
- 'exam_group_id'=>$exam_data->exam_group_id,
- 'exam_id_arr'=>array($exam_id),
- 'student_id_arr'=>$studentsIds
- );
- sendStudentCacheQueue($sendJsonArr);
- $kafkaData=array(
- 'schoolId'=>$this->schoolId,
- 'examGroupId'=>$exam_data->exam_group_id,
- 'generateTime'=>time()*1000
- );
- sendDataToKafka("xbkc-academic-offline-generate-report",$kafkaData);
- echo json_encode(array('status'=>1));exit;
- }
- echo json_encode(array('status'=>0));exit;
- }
- public function actionDelPaperStudentAll()
- {
- $exam_id = Req::post('exam_id');
- $paper_id = Req::post('paper_id');
- $class_id = Req::post('class_id');
- $studentsIds = array();
- if(!$exam_id || !$paper_id)
- {
- echo json_encode(array('status'=>0));exit;
- }
- $student_data = SStudentPaperRelation::model()->findAll('paper_id=:paper_id and exam_id=:exam_id and is_feedback=:is_feedback and is_del=0',array(':paper_id'=>$paper_id,':exam_id'=>$exam_id,':is_feedback'=>0));
- if($student_data)
- {
- foreach($student_data as $v)
- {
- $studentsIds[$v->student_id] = $v->student_id;
- }
- }
- if(!$studentsIds){
- echo json_encode(array('status'=>2));exit;
- }
- if($this->schoolManager->delStudentPaperByStudentAndPaperAndExamId($studentsIds,$paper_id))
- {
- $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id));
- $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id));
- //操作日志
- if(Yii::app()->params['handle_log_on_off'])
- {
- writeFileLog(jsonEncode(array(
- "exam_group_id" => (string)$exam_data->exam_group_id,
- "operate_project" => 'zsyas2',
- "school_id" => $this->schoolId,
- "title" => '清空本次考试的学生',
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $this->getRoute(),
- "operate_sql" => json_encode(array('delete'=>array(
- 'student_paper_relation'=>array('student_id'=>$studentsIds)))),
- "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
- "date"=>date('Y-m-d H:i:s')
- )));
- }
- //发送学生端消息
- $sendJsonArr = array(
- 'school_id' => $this->schoolId,
- 'send_type' => 'zsyas',
- 'update_type' => 2,
- 'exam_group_id' => $exam_data->exam_group_id,
- 'exam_id_arr' => array($exam_id),
- 'student_id_arr' => $studentsIds
- );
- sendStudentCacheQueue($sendJsonArr);
- echo json_encode(array('status'=>1));exit;
- }
- echo json_encode(array('status'=>0));exit;
- }
- public function actionAddPaperStudent()
- {
- $studentsIds = Req::post('studentsIds');
- $exam_id = Req::post('exam_id');
- $paper_id = Req::post('paper_id');
- $class_id = Req::post('class_id');
- $exam_ids = array();
- $student_ids = array();
- $student_names = array();
- $add_student_paper = array();
- $del_student_paper = array();
- $student_cards = array();
- $school_student_cards = array();
- if(!$exam_id || !$paper_id || !$class_id || !$studentsIds || !$this->semesterId)
- {
- echo json_encode(array('status'=>0));exit;
- }
- if($this->schoolManager->getStudentByStudentIdsAndParperId($studentsIds,$paper_id))
- {
- echo json_encode(array('status'=>2));exit;
- }
- $student_array = explode(',',$studentsIds);
- /* $student_paper_del_data = $this->schoolManager->getStudentByStudentIdsAndParperId($studentsIds,$paper_id,1);
- if($student_paper_del_data)
- {
- foreach($student_paper_del_data as $v)
- {
- $del_student_paper[$v['student_id']] = $v['student_id'];
- }
- }
- $add_student_paper = array_diff($student_array,$del_student_paper);*/
- /**
- *加入准考证号
- */
- $criteria = new CDbCriteria();
- $criteria->addInCondition('student_id',$student_array);
- $criteria->addCondition('status = 0');
- $business_student_data = BusinessStudent::model()->findAll($criteria);
- if($business_student_data)
- {
- foreach($business_student_data as $v)
- {
- $student_cards[$v->student_id] = $v->student_card;
- $school_student_cards[$v->student_id] = $v->school_student_card;
- }
- }
- if(!$student_cards)
- {
- echo json_encode(array('status'=>0));exit;
- }
- $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id));
- if($exam_data)
- {
- $class_data = ClassModel::model()->find('class_id=:class_id and semester_id=:semester_id',array(':class_id'=>$exam_data->class_id,':semester_id'=>$this->semesterId));
- if($class_data)
- {
- $grade_data = SGrade::model()->find('id=:id',array(':id'=>$class_data->grade));
- }
- $group_exam_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id));
- if($group_exam_data)
- {
- foreach($group_exam_data as $v)
- {
- $exam_ids[$v->exam_id] = $v->exam_id;
- }
- $student_paper_data = $this->schoolManager->getStudentsByStudentIdsAndExam_ids(implode(',',$exam_ids),$studentsIds);
- if($student_paper_data)
- {
- foreach($student_paper_data as $v)
- {
- $student_ids[$v['student_id']] = $v['student_id'];
- }
- $criteria = new CDbCriteria();
- $criteria->addInCondition('student_id',$student_ids);
- $student_data = SStudentInfo::model()->findAll($criteria);
- unset($criteria);
- if($student_data)
- {
- foreach ($student_data as $v)
- {
- $student_names[$v->student_id] = $v->realname;
- }
- }
- echo json_encode(array('status'=>3,'result'=>implode(',',$student_names)));exit;
- }
- }
- }
- if($this->schoolManager->addAndUpdateStudentPaper($class_id,$student_array,$exam_id,$this->semesterId,$paper_id,$student_cards,$school_student_cards))
- {
- //发送学生端消息
- $sendJsonArr=array(
- 'school_id'=>$this->schoolId,
- 'send_type'=>'zsyas',
- 'update_type'=>1,
- 'exam_group_id'=>$exam_data->exam_group_id,
- 'exam_id_arr'=>array($exam_id),
- 'student_id_arr'=>$studentsIds
- );
- sendStudentCacheQueue($sendJsonArr);
- echo json_encode(array('status'=>1));exit;
- };
- echo json_encode(array('status'=>0));exit;
- }
- public function actionSetExamStudentCard()
- {
- $exam_id = Req::post('exam_id');
- $school_card_status = Req::post('school_card_status');
- $school_card_length = 8;
- if($this->schoolId>999){
- $school_card_length = 9;
- }
- $exam_ids = array();
- if(!$exam_id)
- {
- echo json_encode(array('status'=>0));exit;
- }
- $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id));
- if($exam_data)
- {
- $class_data = ClassModel::model()->find('class_id=:class_id and semester_id=:semester_id',array(':class_id'=>$exam_data->class_id,':semester_id'=>$this->semesterId));
- if($class_data)
- {
- $grade_data = SGrade::model()->find('id=:id',array(':id'=>$class_data->grade));
- }
- $group_exam_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id));
- if($group_exam_data && $grade_data)
- {
- foreach($group_exam_data as $v)
- {
- $exam_ids[$v->exam_id] = $v->exam_id;
- }
- if($school_card_status==1)
- {
- $school_card_length = $grade_data->card_length;
- }
- $criteria = new CDbCriteria();
- $criteria->addInCondition('exam_id',$exam_ids);
- if(false!==Exam::model()->updateAll(array('school_card_status'=>$school_card_status,'school_card_length'=>$school_card_length),$criteria))
- {
- echo json_encode(array('status'=>1));exit;
- }
- }
- }
- echo json_encode(array('status'=>0));exit;
- }
- public function actionDelexam()
- {
- $exam_id = Req::post('examId');
- $class_id = Req::post('classId');
- $is_third = Req::post('is_third');
- $student_ids = array();
- $exam_id_array = array();
- if(!$exam_id || !$class_id)
- {
- echo json_encode(array('status'=>0));exit;
- }
- if($is_third){
- $exam_data = $this->schoolManager->ExamStatusAndUploadStatusArr($exam_id, array(2,3),0);
- }else {
- $exam_data = $this->schoolManager->ExamStatusAndUploadStatus($exam_id, 3, 0);
- }
- if($exam_data)
- {
- $examGroupId = $exam_data['exam_group_id'];
- $examIds = $this->schoolManager->getExamsIdsByExamGroupId($examGroupId);
- if($examIds)
- {
- $exams_data = getAttributes(Exam::model()->findAll("exam_id IN (". implode(',', $examIds) .") AND upload_status = 2"));
- if($exams_data){
- foreach($exams_data as $v)
- {
- $exam_id_array[$v['exam_id']] = $v['exam_id'];
- }
- }
- $all_num = count($examIds);
- $finish_num = count($exams_data);
- if(($all_num-$finish_num) == 1 && !isset($exam_id_array[$exam_id]))
- {
- SExamGroup::model()->updateAll(array('upload_status'=>2,'mark_status'=>2),'exam_group_id = :examGroupId', array(
- ':examGroupId' => $examGroupId
- ));
- }
- }
- $transaction = $this->sConn->beginTransaction();
- try{
- Exam::model()->deleteAll('exam_id=:exam_id',array(':exam_id'=>$exam_id)) ;
- $paper_list = $this->sConn->createCommand("select paper_id from paper where exam_id='" . $exam_id . "'")->queryAll();
- foreach ($paper_list as $paper){
- SPaperTopicRelation::model()->deleteAll('paper_id=:paper_id',array(':paper_id'=>$paper['paper_id']));
- SPaperTopicLarge::model()->deleteAll('paper_id=:paper_id',array(':paper_id'=>$paper['paper_id']));
- STopicUse::model()->deleteAll('paper_id=:paper_id',array(':paper_id'=>$paper['paper_id']));
- }
- SPaper::model()->deleteAll('exam_id=:exam_id',array(':exam_id'=>$exam_id));
- $studentIds=array();
- $student_paper_relation_list = SStudentPaperRelation::model()->findAll('exam_id=:exam_id',array(':exam_id'=>$exam_id));
- $studentIds=array();
- foreach ($student_paper_relation_list as $student_paper_relation){
- $studentIds[]=$student_paper_relation->student_id;
- }
- SStudentPaperRelation::model()->deleteAll('exam_id=:exam_id',array(':exam_id'=>$exam_id));
- SStudentPaperRelationProperty::model()->deleteAll('exam_id=:exam_id',array(':exam_id'=>$exam_id));
- SClassExamPrinter::model()->deleteAll('exam_id=:exam_id',array(':exam_id'=>$exam_id));
- SMarkingGroupModel::model()->deleteAll('class_id=:class_id and exam_group_id=:exam_group_id',array(':class_id'=>$class_id,'exam_group_id'=>$examGroupId));
- //发送学生端消息
- $sendJsonArr=array(
- 'school_id'=>$this->schoolId,
- 'send_type'=>'zsyas',
- 'update_type'=>4,
- 'exam_group_id'=>$examGroupId,
- 'exam_id_arr'=>array($exam_id),
- 'student_id_arr'=>$studentIds
- );
- sendStudentCacheQueue($sendJsonArr);
- $transaction->commit();
- }catch(Exception $e){
- $transaction->rollBack();
- echo json_encode(array('status'=>0));exit;
- }
- //操作日志
- if(Yii::app()->params['handle_log_on_off'])
- {
- writeFileLog(jsonEncode(array(
- "exam_group_id" => (string)$exam_data['exam_group_id'],
- "operate_project" => 'zsyas2',
- "school_id" => $this->schoolId,
- "title" => '删除考试班级',
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $this->getRoute(),
- "operate_sql" => json_encode(array('update'=>array(
- 'ExamGroup'=>array('upload_status'=>1),
- ),
- array('delete'=>array(
- 'Exam'=>array('exam_id'=>$exam_id),
- 'paper'=>array('exam_id'=>$exam_id),
- 'student_paper_relation'=>array('exam_id'=>$exam_id),
- ))
- )),
- "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
- "date"=>date('Y-m-d H:i:s')
- )));
- }
- echo json_encode(array('status'=>1));exit;
- }
- echo json_encode(array('status'=>0));exit;
- }
- public function actionRestore()
- {
- $examName=Req::get('exam_name');
- $page=intval(Req::get('page'));
- $pageLimit=10;
- if(!$page) $page=1;
- $examRestore=new SExamRestore();
- $result=$examRestore->getList($examName,$page,$pageLimit);
- $viewData=array(
- 'pageTotal' =>$result['pageTotal'],
- 'dataList' =>$result['data'],
- 'page' =>$page,
- 'totalCount' =>$result['totalCount'],
- 'examName' =>$examName
- );
- $this->render('restore',$viewData);
- }
- public function actionRestoreExam()
- {
- $exam_group_id = Req::post('examId');
- $exam_ids = array();
- $paper_ids = array();
- $result=array();
- $result['status']=0;
- if($exam_group_id>0)
- {
- $exam_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- if($exam_data)
- {
- foreach($exam_data as $v)
- {
- $exam_ids[$v->exam_id] = $v->exam_id;
- }
- if($exam_ids)
- {
- $criteria = new CDbCriteria();
- $criteria->addInCondition('exam_id',$exam_ids);
- $paper_data = SPaper::model()->findAll($criteria);
- unset($criteria);
- if($paper_data)
- {
- foreach($paper_data as $v)
- {
- $paper_ids[$v->paper_id] = $v->paper_id;
- }
- }
- }
- $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- if($exam_group_data)
- {
- $examStatus=3;
- if($exam_group_data->is_third==1){
- $examStatus=2;
- }
- if($exam_group_data->mark_type>0)
- {
- $transaction = $this->sConn->beginTransaction();
- try{
- $criteria = new CDbCriteria();
- $criteria->addInCondition('exam_id',$exam_ids);
- $flags=SStudentPaperRelation::model()->updateAll(array(
- 'complete_count'=>0,
- 'right_count'=>0,
- 'partial_right_count'=>0,
- 'wrong_count'=>0,
- 'scoring'=>0.0,
- 'lost_score'=>0.0,
- 'compare'=>0.0000,
- 'report_created'=>0,
- 'report_data'=>'',
- 'is_feedback'=>0,
- 'feedback_time'=>0,
- 'is_scoring'=>0,
- 'scoring_img'=>'',
- 'is_isp_html'=>0,
- 'isp_html_path'=>'',
- 'isp_html_time'=>0,
- 'is_wrongbook_html'=>0,
- 'wrongbook_html_path'=>'',
- 'wrongbook_html_time'=>0,
- 'is_isp_pdf'=>0,
- 'isp_pdf_path'=>'',
- 'isp_pdf_time'=>0,
- 'is_wrongbook_pdf'=>0,
- 'wrongbook_pdf_path'=>'',
- 'wrongbook_pdf_time'=>0,
- 'file_src'=>'',
- 'is_wbisp_html'=>0,
- 'is_wbisp_pdf'=>0,
- 'wbisp_html_path'=>'',
- 'wbisp_pdf_path'=>'',
- 'wbisp_html_time'=>0,
- 'wbisp_pdf_time'=>0,
- 'is_studytrend_img'=>0,
- 'studytrend_img_path'=>'',
- 'is_complete'=>0,
- 'complete_time'=>0,
- 'is_plan_created'=>0,
- 'plan_id'=>NULL,
- 'plan_topic_time'=>0,
- 'studytrend_exam_name'=>'',
- 'wb_page_num'=>0,
- 'isp_page_num'=>0,
- 'is_assigned'=>0,
- 'is_three_isp_download'=>0,
- 'is_two_isp_download'=>0,
- 'is_wrongbook_download'=>0,
- 'studytrend_img_time'=>0,
- 'download_three_isp_time'=>0,
- 'download_two_isp_time'=>0,
- 'download_wrongbook_time'=>0,
- 'is_wrong_plan_created'=>0,
- 'wrong_plan_topic_time'=>0,
- 'wrong_plan_id'=>null,
- 'wbisp_page_num'=>0
- ),$criteria);
- unset($criteria);
- //del paper_topic_rs
- $criteria = new CDbCriteria();
- $criteria->addInCondition('paper_id',$paper_ids);
- SStudentPaperTopicRs::model()->deleteAll($criteria);
- unset($criteria);
- //del marking
- if($exam_group_data->mark_type!=4)
- {
- SMarkingGroupModel::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- SMarkingTaskModel::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- SMarkingNewTaskModel::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- SMarkingTeacherModel::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- //SMarkingTopicModel::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_one_data->exam_group_id));
- SMarkingArbitrationModel::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- //update exam
- $criteria = new CDbCriteria();
- $criteria->addInCondition('exam_id',$exam_ids);
- Exam::model()->updateAll(array(
- 'status'=>$examStatus,
- 'upload_status'=>0,
- 'is_topwb_html'=>0,
- 'is_topwb_pdf'=>0,
- 'is_academicr_html'=>0,
- ),$criteria);
- unset($criteria);
- //update exam_group
- ExamGroup::model()->updateAll(array(
- 'mark_status'=>0,
- 'upload_status'=>0,
- 'init_time'=>0,
- 'status'=>1,
- 'score_bar'=>'',
- 'is_marking_stop'=>0,
- ),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- }else
- {
-
- SMarkingTaskModel::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- SMarkingNewTaskModel::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- // SMarkingTopicModel::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_one_data->exam_group_id));
- SMarkingTeacherModel::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- SMarkingArbitrationModel::model()->deleteAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- //update exam
- $criteria = new CDbCriteria();
- $criteria->addInCondition('exam_id',$exam_ids);
- Exam::model()->updateAll(array(
- 'status'=>$examStatus,
- 'upload_status'=>0,
- 'is_topwb_html'=>0,
- 'is_topwb_pdf'=>0,
- 'is_academicr_html'=>0,
- ),$criteria);
- unset($criteria);
- //update exam_group
- ExamGroup::model()->updateAll(array(
- 'mark_status'=>1,
- 'upload_status'=>0,
- 'score_bar'=>'',
- 'status'=>1,
- 'is_marking_stop'=>0,
- ),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- }
- $this->sConn->createCommand("delete from exam_product_status where exam_id in(".implode(',',$exam_ids).")")->execute();
- $this->sConn->createCommand("update exam_restore set status=2 where exam_group_id='{$exam_group_id}'")->execute();
- $rs = http('/qxk/marking/exam/reset/'.$exam_group_id,'PUT',$this->schoolId,array(),'cgi');
- $rs=json_decode($rs,true);
- if(isset($rs['errCode']) && $rs['errCode']=='00'){
- //sendDataToKafka('xbkc-marking-reback-exam',array('examGroupId'=>$exam_group_id,'schoolId'=>$this->schoolId));
- $transaction->commit();
- }else{
- throw new Exception($rs['errMsg']);
- }
-
- }catch(Exception $e){
- $transaction->rollBack();
- //操作日志
- if(Yii::app()->params['handle_log_on_off'])
- {
- writeFileLog(jsonEncode(array(
- "exam_group_id" => (string)$exam_group_id,
- "operate_project" => 'zsyas2',
- "school_id" => $this->schoolId,
- "title" => '还原考试失败',
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $this->getRoute(),
- "operate_sql" =>'',
- "error"=>$e->getMessage(),
- "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
- "date"=>date('Y-m-d H:i:s')
- )));
- }
- $result['msg']="还原失败";
- exit(json_encode($result));
- }
- //操作日志
- if(Yii::app()->params['handle_log_on_off'])
- {
- writeFileLog(jsonEncode(array(
- "exam_group_id" => (string)$exam_group_id,
- "operate_project" => 'zsyas2',
- "school_id" => $this->schoolId,
- "title" => '还原考试',
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $this->getRoute(),
- "operate_sql" =>'',
- "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
- "date"=>date('Y-m-d H:i:s')
- )));
- }
- $result['status']=1;
- $result['msg']="还原成功";
- exit(json_encode($result));
- }else
- {
- //线下阅卷
- $transaction = $this->sConn->beginTransaction();
- try{
- $criteria = new CDbCriteria();
- $criteria->addInCondition('exam_id',$exam_ids);
- $flags=SStudentPaperRelation::model()->updateAll(array(
- 'complete_count'=>0,
- 'right_count'=>0,
- 'partial_right_count'=>0,
- 'wrong_count'=>0,
- 'scoring'=>0.0,
- 'lost_score'=>0.0,
- 'compare'=>0.0000,
- 'report_created'=>0,
- 'report_data'=>'',
- 'is_feedback'=>0,
- 'feedback_time'=>0,
- 'is_scoring'=>0,
- 'scoring_img'=>'',
- 'is_isp_html'=>0,
- 'isp_html_path'=>'',
- 'isp_html_time'=>0,
- 'is_wrongbook_html'=>0,
- 'wrongbook_html_path'=>'',
- 'wrongbook_html_time'=>0,
- 'is_isp_pdf'=>0,
- 'isp_pdf_path'=>'',
- 'isp_pdf_time'=>0,
- 'is_wrongbook_pdf'=>0,
- 'wrongbook_pdf_path'=>'',
- 'wrongbook_pdf_time'=>0,
- 'file_src'=>'',
- 'is_wbisp_html'=>0,
- 'is_wbisp_pdf'=>0,
- 'wbisp_html_path'=>'',
- 'wbisp_pdf_path'=>'',
- 'wbisp_html_time'=>0,
- 'wbisp_pdf_time'=>0,
- 'is_studytrend_img'=>0,
- 'studytrend_img_path'=>'',
- 'is_complete'=>0,
- 'complete_time'=>0,
- 'is_plan_created'=>0,
- 'plan_id'=>NULL,
- 'plan_topic_time'=>0,
- 'studytrend_exam_name'=>'',
- 'wb_page_num'=>0,
- 'isp_page_num'=>0,
- 'wbisp_page_num'=>0
- ),$criteria);
- unset($criteria);
- //del paper_topic_rs
- $criteria = new CDbCriteria();
- $criteria->addInCondition('paper_id',$paper_ids);
- SStudentPaperTopicRs::model()->deleteAll($criteria);
- unset($criteria);
- //update exam
- $criteria = new CDbCriteria();
- $criteria->addInCondition('exam_id',$exam_ids);
- Exam::model()->updateAll(array(
- 'status'=>$examStatus,
- 'upload_status'=>0,
- 'is_topwb_html'=>0,
- 'is_topwb_pdf'=>0,
- 'is_academicr_html'=>0,
- ),$criteria);
- unset($criteria);
- //update exam_group
- ExamGroup::model()->updateAll(array(
- 'mark_status'=>0,
- 'upload_status'=>0,
- 'init_time'=>0,
- 'score_bar'=>'',
- 'status'=>1
- ),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- $this->sConn->createCommand("update exam_restore set status=2 where exam_group_id='{$exam_group_id}'")->execute();
- $transaction->commit();
- }catch(Exception $e)
- {
- $transaction->rollBack();
- $result['msg']="还原失败";
- //操作日志
- if(Yii::app()->params['handle_log_on_off'])
- {
- writeFileLog(jsonEncode(array(
- "exam_group_id" => (string)$exam_group_id,
- "operate_project" => 'zsyas2',
- "school_id" => $this->schoolId,
- "title" => '还原考试失败',
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $this->getRoute(),
- "operate_sql" =>'',
- "error"=>$e->getMessage(),
- "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
- "date"=>date('Y-m-d H:i:s')
- )));
- }
- exit(json_encode($result));
- }
- //操作日志
- if(Yii::app()->params['handle_log_on_off'])
- {
- writeFileLog(jsonEncode(array(
- "exam_group_id" => (string)$exam_group_id,
- "operate_project" => 'zsyas2',
- "school_id" => $this->schoolId,
- "title" => '还原考试',
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $this->getRoute(),
- "operate_sql" =>'',
- "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
- "date"=>date('Y-m-d H:i:j')
- )));
- }
- $result['status']=1;
- $result['msg']="还原成功";
- exit(json_encode($result));
- }
- }
- }
- }
- $result['msg']="考试参数异常";
- exit(json_encode($result));
- }
- public function actionSetSubjectId()
- {
- $subjectId = Req::post("subjectId");
- if($subjectId)
- {
- Yii::app()->session['session_subject_id'] = $subjectId;
- Yii::app()->session['session_duoxueke_subject_id'] = $subjectId;
- // $this->subjectId = $subjectId;
- echo 1;exit;
- }else
- {
- echo 0;exit;
- }
- }
- public function actionSend_ruanyun_pdf()
- {
- $exam_id = Req::post('examId');
- $paper_id = '';
- $student_ids = array();
- $class_id = '';
- $data = array();
- $topic_ids = array();
- $topic_score = array();
- $topic_QuestionId = array();
- if($exam_id)
- {
- $student_paper_relations = SStudentPaperRelation::model()->findAll('exam_id=:exam_id and is_del=:is_del',array(':exam_id'=>$exam_id,':is_del'=>0));
- if($student_paper_relations)
- {
- foreach($student_paper_relations as $v)
- {
- $paper_id = $v->paper_id;
- $student_ids[$v->student_id] = $v->student_id;
- $class_id = $v->class_id;
- }
- }
- $school_data = BusinessSchool::model()->find('school_id = :school_id',array(':school_id'=> $this->schoolId));
- if($school_data)
- {
- $class_data = ClassModel::model()->find('class_id=:class_id',array(':class_id'=>$class_id));
- if($class_data)
- {
- $criteria = new CDbCriteria();
- $criteria->addInCondition('student_id',$student_ids);
- $students = SStudentInfo::model()->findAll($criteria);
- if($students)
- {
- foreach($students as $k=>$v)
- {
- $data['Students'][$k]['StudentNo'] = $v->student_id;
- $data['Students'][$k]['StudentName'] = $v->realname;
- $data['Students'][$k]['SchoolName'] = $school_data->school_name;
- $data['Students'][$k]['GradeName'] = "";
- $data['Students'][$k]['ClassName'] = $class_data->class_name;
- if($class_data->grade==1)
- {
- $data['Students'][$k]['GradeName'] = "高一";
- }
- if($class_data->grade==2)
- {
- $data['Students'][$k]['GradeName'] = "高二";
- }
- if($class_data->grade==3)
- {
- $data['Students'][$k]['GradeName'] = "高三";
- }
- $data['Students'][$k]['ExternalInfo'] = json_encode(array('exam_id'=>$exam_id,'school_id'=>$this->schoolId));
- }
- }
- }
- }
- $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id));
- if($exam_data)
- {
- $data['StudentExam']['ExamName'] = $exam_data->name;
- $data['StudentExam']['ExamTypeId'] = 4;
- $data['StudentExam']['CourseId'] = $exam_data->subject_id;
- $data['StudentExam']['RegionId'] = 0;
- }
- $paper_topic_relation = SPaperTopicRelation::model()->findAll('paper_id=:paper_id',array(':paper_id'=>$paper_id));
- if($paper_topic_relation)
- {
- foreach($paper_topic_relation as $v)
- {
- $topic_ids[$v->topic_id] = $v->topic_id;
- $topic_score[$v->topic_id] = $v->score;
- }
- unset($criteria);
- $criteria = new CDbCriteria();
- $criteria->addInCondition('topic_id',$topic_ids);
- $question_ids = SRuanyunTopicRelation::model()->findAll($criteria);
- if($question_ids)
- {
- foreach($question_ids as $k=>$v)
- {
- $topic_QuestionId[$v->topic_id] = $v->question_id;
- $data['ExamQuestions'][$k]['QuestionId'] = $v->question_id;
- $data['ExamQuestions'][$k]['FullScore'] = (double)0;
- if(isset($topic_score[$v->topic_id]))
- {
- $data['ExamQuestions'][$k]['FullScore'] = (double)$topic_score[$v->topic_id];
- }
- }
- }
- unset($criteria);
- $criteria = new CDbCriteria();
- $criteria->addCondition('paper_id=:paper_id');
- $criteria->addInCondition('student_id',$student_ids);
- $criteria->params[':paper_id'] = $paper_id;
- $student_paper_rs = SStudentPaperTopicRs::model()->findAll($criteria);
- if($student_paper_rs)
- {
- foreach($student_paper_rs as $k=>$v)
- {
- $data['ExamResults'][$k]['StudentNo'] = $v->student_id;
- $data['ExamResults'][$k]['QuestionId'] = 0;
- if(isset($topic_QuestionId[$v->topic_id]))
- {
- $data['ExamResults'][$k]['QuestionId'] = $topic_QuestionId[$v->topic_id];
- }
- $data['ExamResults'][$k]['Score'] = (double)$v->scoring;
- }
- //调接口
- $upload_log = new BusinessUploadLog();
- $upload_log->school_id = $this->schoolId;
- $upload_log->file_zip_path = Yii::app()->params['ruanyun_exam_interface'];
- $upload_log->message = json_encode($data);
- $upload_log->create_time = time();
- $upload_log->save();
- $RequestResult = Curl::http_post_gzip_json(Yii::app()->params['ruanyun_exam_interface'],json_encode($data));
- $upload_log = new BusinessUploadLog();
- $upload_log->school_id = $this->schoolId;
- $upload_log->file_zip_path ='result';
- $upload_log->message = $RequestResult;
- $upload_log->create_time = time();
- $upload_log->save();
- if($RequestResult)
- {
- $RequestResult_data = json_decode($RequestResult,1);
- if(isset($RequestResult_data['ResultTypeId']) && $RequestResult_data['ResultTypeId']==1)
- {
- echo json_encode(array('status'=>1));exit;
- }else
- {
- echo json_encode(array('status'=>0));exit;
- }
- }else
- {
- echo json_encode(array('status'=>0));exit;
- }
- }else
- {
- echo json_encode(array('status'=>2));exit;
- }
- }
- }
- echo json_encode(array('status'=>0));exit;
- }
- public function actionDo_ruanyun_pdf()
- {
- $condition = array();
- $printList = array();
- $condition[] = "cep.type = 0";
- $condition[] = "e.is_display = '0'";
- $condition[] = "eg.is_third = '0'";
- $condition[] = "e.subject_id = '{$this->subjectId}'";
- $resultList = $this->schoolManager->getPrintList($condition,array('e.create_time desc','e.exam_id desc'));
- if($resultList["rs"]){
- foreach ($resultList['rs'] as $k=>$v) {
- $printList[$k] = $v;
- if ($v["type"] == 1) {
- $printList[$k]['print_name']= $v["exam_name"].'"错题本"';
- }
- elseif ($v["type"] == 2) {
- $printList[$k]['print_name']= $v["exam_name"].'"个性化学习方案"';
- }
- elseif ($v["type"] == 3) {
- $printList[$k]['print_name']= $v["exam_name"].'"个性化学习宝"';
- }
- else {
- $printList[$k]['print_name']= $v["exam_name"];
- }
- $printList[$k]['is_tpl'] = 0; // 需要上传模板
- $printList[$k]['answer_card_uploaded'] = false;
- if(in_array($v['tpl_index'], Yii::app()->params['custom_tpls_ids'])){
- //自定义模板
- $printList[$k]['is_custom_tpl'] = true;
- $v['is_custom_tpl'] = true;
- }else{
- //非自定义模板
- $printList[$k]['is_custom_tpl'] = false;
- $v['is_custom_tpl'] = false;
- }
- if (in_array($v['tpl_index'], Yii::app()->params['no_template_id']) || $v['is_custom_tpl']) {
- $printList[$k]['is_tpl'] = 1;
- if(trim($printList[$k]['answer_card_src'])){
- $printList[$k]['answer_card_uploaded'] = true;
- }
- //题卡分离
- $printList[$k]['paper_tpl_type'] = 2;
- }else{
- $printList[$k]['paper_tpl_type'] = 1;
- }
- if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl']))
- {
- $printList[$k]['paper_tpl_type'] = 3;
- if($v['tpl_index'] == 9 )
- {
- $printList[$k]['paper_tpl_type'] = 4;
- }
- }
- if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl_all']))
- {
- $printList[$k]['paper_tpl_type'] = 3;
- if($v['tpl_index'] == 9 )
- {
- $printList[$k]['paper_tpl_type'] = 4;
- }
- }
- //题卡合一
- }
- }
- $subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId);
- $data = array();
- $data['printList'] = $printList;
- $data['pages'] = $resultList['pager'];
- $data['page_total'] = $resultList['pager']->rowsCount;
- $data["subject"] = $subject_exam_data;
- unset($resultList);
- $this->render('do_ruanyun_pdf',$data);
- }
- public function actionRuanyun_change()
- {
- $sname = Req::get("sname");
- $cid = Req::get("cid");
- $eid = Req::get("eid");
- $studentNames = array();
- $classInfo = ClassModel::model()->findByPk($cid);
- if (empty($classInfo)) {
- Yii::app()->jump->error('未找到班级!');
- }
- $examInfo = Exam::model()->findByPk($eid);
- if (empty($examInfo)) {
- Yii::app()->jump->error('未找到周周练!');
- }
- $getResult = ClassExamPrinter::model()->find('class_id=:cid and exam_id=:eid',array(':cid'=>$cid,':eid'=>$eid));
- if (empty($getResult)) {
- Yii::app()->jump->error('未找到班级与试卷对应关系!');
- }
- $paperInfo = SPaper::model()->find('exam_id=:eid',array(':eid'=>$eid));
- if (empty($paperInfo)) {
- Yii::app()->jump->error('未找到试卷信息!');
- }
- //$relateStudent = SStudentPaperRelation::model()->findAll('paper_id=:paid and class_id=:caid and is_wrongbook_pdf=1',array(':paid'=>$paperInfo->paper_id,':caid'=>$cid));
- $relateStudent = SStudentPaperRelation::model()->findAll('paper_id=:paid and class_id=:caid',array(':paid'=>$paperInfo->paper_id,':caid'=>$cid));
- if (empty($relateStudent))
- {
- Yii::app()->jump->error('未找到考试学生信息!');
- } else {
- $studentIdArray = array();
- $wrongStatus = array();
- $studentArrayTwo = array();
- $studentScoring = array();
- $_wrongStudentIds = array();
- $student_name = array();
- // 获取当前考试所有学生ID
- foreach ($relateStudent as $key=>$val) {
- $studentIdArray[] = $val->student_id;
- $wrongStatus[$val->student_id] = $val->is_wbisp_pdf;
- $wrongStudentIds[$val->student_id] = $val->student_id;
- $_wrongStudentIds[$val->student_id] = $val->student_id;
- $studentScoring[$val->student_id] = $val->scoring;
- }
- $wrongStudents = $wrongTopicIds = $wrongAnswers =array();
- // 获取学生的错题
- }
- $result = array();
- if (!empty($wrongStudentIds)) {
- // 获取有错题的学生姓名
- $studentNames = SStudentInfo::model()->getStudentNames($wrongStudentIds);
- }
- $data = array();
- $data['exam_id'] = $eid;
- $data['examName'] = $examInfo["name"];
- $data['class_id'] = $cid;
- $data['sname'] = $sname;
- $data['examInfo'] = $examInfo;
- $data['student_names'] = $studentNames;
- $data['result'] = $relateStudent;
- $this->render('ruanyun_change',$data);
- }
- public function actionUpdatepaperdowntime()
- {
- $student_id = Req::post('student_id');
- $exam_id = Req::post('exam_id');
- if($student_id && $exam_id)
- {
- $student_paper_relation = SStudentPaperRelation::model()->find('student_id = :student_id and exam_id=:exam_id and is_isp_pdf=:is_isp_pdf',array(':student_id'=>$student_id,':exam_id'=>$exam_id,':is_isp_pdf'=>1));
- if($student_paper_relation)
- {
- SStudentPaperRelation::model()->updateAll(array('is_two_isp_download'=>1,'download_two_isp_time'=>time()),'student_id= :student_id and exam_id=:exam_id',array(':student_id'=>$student_id,':exam_id'=>$exam_id));
- }
- }
- }
- public function actionStudent_product()
- {
- //当前学期所有班级
- $grade = Req::get('grade');
- $class_id = Req::get('class_id');
- $ptype = Req::get('ptype'); //类型,期中,期末,总复习
- $season = Req::get('season'); //季节
- $class_name = '';
- $pageLimit=4;
- if($season){
- $pageLimit=$pageLimit*2;
- }
- if($ptype){
- $pageLimit=$pageLimit*3;
- }
- $criteria = new CDbCriteria();
- if($class_id)
- {
- $criteria->addCondition('class_id=:class_id');
- $criteria->params[':class_id'] = $class_id;
- }
- $criteria->addCondition('semester_id=:semester_id');
- $criteria->params[':semester_id'] = $this->semesterId;
- if($grade)
- {
- $criteria->addCondition('grade=:grade');
- $criteria->params[':grade'] = $grade;
- }
- $criteria->order = 'grade asc,class_id asc';
- $count = ClassModel::model()->count($criteria);
- $pager = new CPagination($count,$pageLimit);
- $criteria->limit=$pager->getLimit();
- $criteria->offset=$pager->getOffset();
- $class_data = ClassModel::model()->findAll($criteria);
- if(!$class_data)
- {
- Yii::app()->jump->error('未找到班级!');
- }
- $data = array();
- $class_names = array();
- $class_ids = array();
- $class_student_ids = array();
- $class_down = array();
- $class_create = array();
- foreach($class_data as $v)
- {
- if($v->class_id == $class_id)
- {
- $class_name = $v->class_name;
- }
- $class_names[$v->class_id] = $v->class_name;
- $class_ids[$v->class_id] = $v->class_id;
- }
- unset($criteria);
- $criteria = new CDbCriteria();
- $criteria->addInCondition('class_id',$class_ids);
- $criteria->addCondition('status=:status');
- $criteria->params[':status'] = 0;
- $student_data = SStudentClassRelation::model()->findAll($criteria);
- if($student_data)
- {
- foreach($student_data as $v)
- {
- $class_student_ids[$v->class_id][$v->student_id] = $v->student_id;
- }
- }
- //debug($class_data);
- /*** 优化后 *****/
- $_class_ids = array();
- if($class_student_ids){
- $_class_ids = array_keys($class_student_ids);
- }
- // 多学科切换条件
- if(in_array($this->subjectId,$this->mathSubjectId)){
- $subjectId=3;
- }else{
- $subjectId=$this->subjectId;
- }
- list($student_product_data,$student_down_product_data,$class_bt) = $this->schoolManager->getStudentProduct($_class_ids,$subjectId);
- /*** 优化后 *****/
- /*** 优化前 *****/
- // $student_product_data = $this->schoolManager->getStudentProduct(array('p.semester_id='.$this->semesterId,'p.is_pdf_created = 1'));
- // $student_down_product_data = $this->schoolManager->getStudentProduct(array('p.semester_id='.$this->semesterId,'p.is_download = 1'));
- /*** 优化前 *****/
- if($student_down_product_data)
- {
- foreach($student_down_product_data as $v)
- {
- $class_down[$v['class_id']][$v['product_type']] = $v;
- }
- }
- if($student_product_data)
- {
- foreach($student_product_data as $v)
- {
- $class_create[$v['class_id']][$v['product_type']] = $v;
- }
- }
- unset($criteria);
- $criteria = new CDbCriteria();
- if($grade)
- {
- $criteria->addCondition('grade=:grade');
- $criteria->params[':grade'] = $grade;
- }
- $criteria->addCondition('semester_id=:semester_id');
- $criteria->params[':semester_id'] = $this->semesterId;
- $class_all = ClassModel::model()->findAll($criteria);
- //阶段个性化学习宝生成状态
- //category 1--春季期中个性化学习宝(2.1~4.30) 2--春季期末个性化学习宝(5.1~7.31) 3--春季总复习个性化学习宝(2.1~7.31) 4--秋季期中个性化学习宝(9.1~11.30) 5--秋季期末个性化学习宝(12.1~1.31) 6--秋季总复习个性化学习宝(9.1~1.31)
- $review_isp = array(
- array(
- 'product_name' => '期中复习学习宝',
- 'season_arr'=>array(
- array(
- 'category_id' => 1,
- 'is_send' => 0,
- 'status' => 0,
- 'category_name' => '春季(根据2-4月的考试数据生成)',
- ),
- array(
- 'category_id' => 4,
- 'is_send' => 0,
- 'status' => 0,
- 'category_name' => '秋季(根据9-11月的考试数据生成)',
- ),
- ),
- ),
- array(
- 'product_name' => '期末复习学习宝',
- 'season_arr'=>array(
- array(
- 'category_id' => 2,
- 'is_send' => 0,
- 'status' => 0,
- 'category_name' => '春季(根据5-7月的考试数据生成)',
- ),
- array(
- 'category_id' => 5,
- 'is_send' => 0,
- 'status' => 0,
- 'category_name' => '秋季(根据12-1月的考试数据生成)',
- ),
- ),
- ),
- array(
- 'product_name' => '总复习学习宝',
- 'season_arr'=>array(
- array(
- 'category_id' => 3,
- 'is_send' => 0,
- 'status' => 0,
- 'category_name' => '春季(根据2-7月的考试数据生成)',
- ),
- array(
- 'category_id' => 6,
- 'is_send' => 0,
- 'status' => 0,
- 'category_name' => '秋季(根据9-1月的考试数据生成)',
- ),
- ),
- ),
- );
- $review_info = SReviewPaperProductSet::model()->findAll(
- array(
- 'select'=>'category,status,reset_time',
- 'condition'=>'semester_id = :semester_id and subject_id=:subject',
- 'params'=>array(':semester_id'=>$this->semesterId,':subject'=>$subjectId),
- )
- );
- $review_status = array();
- $reset_time = array();
- $cate3_rel_cate6 = array();
- foreach ($review_info as $info) {
- $review_status[$info->category] = $info->status;
- $reset_time[$info->category] = $info->reset_time;
-
- $cate3_rel_cate6[$info->category] = $info->category;
- }
- unset($review_info);
- foreach ($review_isp as $key => $review){
- foreach ($review['season_arr'] as $k => $cate){
- if(isset($review_status[$cate['category_id']])){
- $review_isp[$key]['season_arr'][$k]['status'] = (int)$review_status[$cate['category_id']];
- $review_isp[$key]['season_arr'][$k]['reset_time'] = $reset_time[$cate['category_id']]; //重置时间
- }
- }
- }
- $data['pages'] = $pager;
- $data['pape_count'] = $count;
- $data['class_data'] = $class_data;
- $data['semester_name'] = $this->semesterDetail['semester_name'];
- $data['class_student'] = $class_student_ids;
- $data['class_down'] = $class_down;
- $data['class_create'] = $class_create;
- $data['grade'] = $grade;
- $data['class_name'] = $class_name;
- $data['class_id'] = $class_id;
- $data['class_all'] = $class_all;
- $data['review_isp'] = $review_isp;
- $data['semester_id'] = $this->semesterId;
- $data['subjectId'] = $this->subjectId;
- $data['cate3_rel_cate6'] = $cate3_rel_cate6;
- $data['ptype'] = $ptype;
- $data['season'] = $season;
- $data['class_bt'] = $class_bt;
- 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('sheet',$data);
- }
- public function actionClass_student_product()
- {
- Url::clean();
- $cid = Req::get("cid");
- $type = Req::get("type");
- $student_name = Req::get("student_name");
- $data = array();
- $student_ids = array();
- $student_products = array();
- if(!$cid)
- {
- Yii::app()->jump->error('未找到班级!');
- }
- $classInfo = ClassModel::model()->findByPk($cid);
- if (empty($classInfo)) {
- Yii::app()->jump->error('未找到班级!');
- }
- $class_student_data = SStudentClassRelation::model()->findAll('class_id=:class_id and status=:status',array(':class_id'=>$cid,':status'=>0));
- if($class_student_data)
- {
- foreach($class_student_data as $v)
- {
- $student_ids[$v->student_id] = $v->student_id;
- }
- }
- $criteria = new CDbCriteria();
- $criteria->addInCondition('student_id',$student_ids);
- if($student_name)
- {
- $criteria->addSearchCondition('realname',$student_name);
- }
- $count = SStudentInfo::model()->count($criteria);
- $pager = new CPagination($count,10);
- $criteria->limit=$pager->getLimit();
- $criteria->offset=$pager->getOffset();
- $student_data = SStudentInfo::model()->findAll($criteria);
- $student_ids1=array();
- foreach($student_data as $v){
- $student_ids1[] = (string)$v->student_id;
- }
- // 多学科切换条件
- if(in_array($this->subjectId,$this->mathSubjectId)){
- $subjectId=3;
- }else{
- $subjectId=$this->subjectId;
- }
- $stuids = array();
- if($student_ids1){
- if (Yii::app()->params["limit_open"]) {
- $semester=new SSemester();
- $nowsem=$semester->getCurrentSemester();
- $classinfo= ClassModel::model()->find("class_id=:id",array(":id"=>$cid));
- $intarr=array(
- "schoolId"=>$this->schoolId,
- "clazzId"=>$cid,
- "semester"=>$nowsem['refer_code'],
- "grade"=>$classinfo['grade'],
- "students"=>array(),
- "examTime"=>time(),
- "classify"=>1,
- "subject"=>$subjectId,
- );
- $stuids=$this->getManyProductOrder($intarr,array(1,2,3),$student_ids1);
-
- }else {
- $stuids = $student_ids1;
- }
- }
- foreach($student_data as $k=>$v){
- if($this->inArray($v->student_id,$stuids)){
- // if(in_array((string)$v->student_id,$stuids)){
- $v->is_outer=1;
- }else{
- $v->is_outer=0;
- }
- $student_data[$k]=$v;
- }
- unset($criteria);
- $student_product_data=SStudentProductModel::model()->getStudentCreate($student_ids,$subjectId,$type,$this->semesterId);
- if($student_product_data)
- {
- foreach($student_product_data as $v)
- {
- $student_products[$v['student_id']] = $v;
- }
- }
- $data['page_count'] = $count;
- $data['class_id'] = $cid;
- $data['class_name'] = $classInfo->class_name;
- $data['pages'] = $pager;
- $data['student'] = $student_data;
- $data['type'] = $type;
- $data['student_products'] = $student_products;
- $data['semester_name'] = $this->semesterDetail['semester_name'];
- $data['student_name'] = $student_name;
- 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('sheet_chang',$data);
- }
- /**
- * in_array() php 5.3 有问题重新写
- * @param type $value
- * @param type $arr
- * @return boolean
- */
- public function inArray($value,$arr){
- if($arr){
- foreach($arr as $v){
- if((string)$value === (string)$v){
- return true;
- }
- }
- }
- return false;
- }
- public function actionDownload_student_product(){
- $classId = Req::get("classId");
- $type = Req::get("type");
- $studentsIds = Req::get("studentsIds");
- if( !$classId || !$type){
- echo json_encode(array("success" => 0, "message" => "缺少参数"));
- exit();
- }
- if(!in_array($type, array(1, 2, 3))){
- echo json_encode(array("success" => 0, "message" => "参数错误[1]"));
- exit();
- }
- $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
- //
- if(!$apiUrl){
- echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
- exit();
- }
- $params = array(
- "schoolId" => $this->schoolId,
- "classId" => $classId,
- "type" => $type,
- );
- $student_class_data = SStudentClassRelation::model()->findAll('class_id=:class_id and status=:status',array(':class_id'=>$classId,':status'=>0));
- if($student_class_data)
- {
- if(!$studentsIds)
- {
- $studentsIds=array();
- foreach($student_class_data as $v)
- {
- // $params['studentIds'][] = $v->student_id;
- $studentsIds[]=$v->student_id;
- }
- }
- }else{
- echo json_encode(array("success" => 0, "message" => "班级暂无学生"));exit;
- }
- if($studentsIds)
- {
- ;
- if(!is_array($studentsIds)){
- $studentsIds=explode(',',$studentsIds);
- }
- // $student_ids1="";
- // foreach($studentsIds as $v){
- // $student_ids1.="'".$v."',";
- // }
- // $student_ids1=substr($student_ids1,0,strlen($student_ids1)-1);
- // $stu_order=array();
- // if($student_ids1){
- // $today=date("Y-m-d H:i:s");
- // $semester=new SSemester();
- // $nowsem=$semester->getCurrentSemester();
- // $sql="SELECT
- // student_id,
- // student_name,
- // group_concat(trial_begin_time) AS trial_begin_time,
- // group_concat(trial_end_time) AS trial_end_time,
- // group_concat(type_id) AS type_id,
- // group_concat(classify) AS classify,
- // group_concat(`code`) AS `code`
- // FROM
- // (
- // SELECT
- // o.id,
- // IFNULL(o.trial_begin_time, '') AS trial_begin_time,
- // IFNULL(o.trial_end_time,'') as trial_end_time,
- // g.type_id,
- // g.classify,
- // IFNULL(gt.`code`,0) as `code`,
- // os.student_name,
- // os.student_id
- // FROM
- // `order` AS o
- // JOIN order_goods AS og ON og.order_id = o.id
- // JOIN goods AS g ON g.id = og.goods_id
- // left JOIN goods_term AS gt ON g.id = gt.goods_id
- // left JOIN order_goods_semester AS ogs ON o.id = ogs.order_id
- // JOIN order_student AS os ON os.order_id = o.id
- // WHERE
- // os.student_id in ($student_ids1)
- // and (o.trial_end_time >= '{$today}' OR ogs.`code` ='{$nowsem['refer_code']}')
- // and o.status=1
- // AND o.school_id ={$this->schoolId}
- // AND os.chargeback = 0
- // and o.id not in (select business_key from zsy_service where status=1)
- // ORDER BY
- // g.type_id
- //
- // ) t
- // GROUP BY
- // student_name ";
- // $stu_order=Yii::app()->db251->createCommand($sql)->queryAll();
- //
- // }
- // $limit=array();
- // if($stu_order){
- //
- // foreach($stu_order as $v){
- // $limit[$v['student_id']]=$v;
- // }
- //
- // }
- // $stuids=$studentsIds;
- // foreach($stuids as $k=>$v){
- // if(!isset($limit[$v])){
- // unset($stuids[$k]);
- // }
- // }
- $stuids = array();
- if (Yii::app()->params["limit_open"]) {
- $semester=new SSemester();
- $nowsem=$semester->getCurrentSemester();
- $classinfo= ClassModel::model()->find("class_id=:id",array(":id"=>$classId));
- $intarr=array(
- "schoolId"=>$this->schoolId,
- "clazzId"=>$classId,
- "semester"=>$nowsem['refer_code'],
- "grade"=>$classinfo['grade'],
- "students"=>array(),
- "examTime"=>time(),
- "classify"=>1,
- "subject"=>3,
- );
- $this->getStuOrder($studentsIds,$intarr,$stuids);
- }else {
- $stuids = $studentsIds;
- }
- if(!$stuids){
- echo json_encode(array("success" => 0, "message" => "所选的学生没有下载权限"));exit;
- }
- $params['studentIds'] = $stuids;
- $criteria = new CDbCriteria();
- $_students = array();
- if($params["studentIds"])
- {
- $_students = $params["studentIds"];
- }
- $criteria->addInCondition('student_id',$_students);
- $criteria->addCondition('type=:type');
- $criteria->params[':type'] = $type;
- $_student_product_data = SStudentProductModel::model()->findAll($criteria);
- if(!$_student_product_data)
- {
- echo json_encode(array("success" => 0, "message" => "所选的学生尚未生成PDF"));exit;
- }
- }
- $rs = Curl::post($apiUrl."/rest/download_sp/index", $params);
- if(!($rs = json_decode($rs))){
- $rs = array(
- "success" => 0,
- "message" => "请求接口失败",
- );
- echo json_encode($rs);exit;
- }
- if($rs->success!=0){
- $rs->success=2;
- $rs->limitinfo='全班允许下载';
- }
- if($params["studentIds"] && ($rs->success==1 || $rs->success==2) )
- {
- $criteria = new CDbCriteria();
- $_students = array();
- if($params["studentIds"])
- {
- $_students = $params["studentIds"];
- }
- $criteria->addInCondition('student_id',$_students);
- $criteria->addCondition('type=:type');
- $criteria->params[':type'] = $type;
- SStudentProductModel::model()->updateAll(array('is_download'=>1,'download_time'=>time()),$criteria);
- }
- echo json_encode($rs);exit;
- }
- /**
- * 获取学生是否有订单
- * @param $studentsIds
- * @param $intarr
- * @param $stuids
- */
- protected function getStuOrder($studentsIds,$intarr,&$stuids){
- foreach(array(1,2,3) as $type){
- $intarr['classify'] = $type;
- $intarr['students'] = array_diff($studentsIds,$stuids);
- if(!$intarr['students']){
- break;
- }else{
- $intarr['students'] = array_values($intarr['students']);
- }
- $basic = imsBasicAuth($this->schoolId . '_' . Yii::app()->session['coachInfo']['coach_name'], Yii::app()->params["zsy_api_key"]);
- $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr), $basic));
- if (!$rs) {
- Yii::app()->jump->error("接口错误");
- }
- if (!empty($rs->data)) {
- $stuids = array_merge($stuids,$rs->data);
- }
- }
- }
- /**
- * 打包下载
- */
- public function actionPrint_pack()
- {
- $exam_id = Req::post("exam_id");
- $student_id = Req::post("student_id");
- if(!$exam_id )
- {
- echo json_encode(array("status"=>0,"result"=>"参数不能为空"));
- }
- $student_ids = array();
- if(!$student_id)
- {
- $student_paper_data = SStudentPaperRelation::model()->findAll("exam_id=:exam_id and is_del=:is_del ",array(":exam_id"=>$exam_id,':is_del'=>0));
- if($student_paper_data)
- {
- foreach ($student_paper_data as $v)
- {
- $student_ids[] = $v->student_id;
- }
- }
- }else
- {
- $studentIds = explode(',',$student_id);
- foreach ($studentIds as $v)
- {
- if($v)
- {
- $student_ids[] = $v;
- }
- }
- }
- $password = md5($this->schoolId.Yii::app()->params['zsy_api_key']);
- $url = Yii::app()->params['zsy_api_url'].'/teacher/paper/download/fixedtemplate/qrinfo/'.$this->schoolId;
- $rs = $this->CrmApiPost($url,array('examId'=>$exam_id,'students'=>$student_ids),$this->schoolId,$password);
- //操作日志
- if(Yii::app()->params['handle_log_on_off'])
- {
- writeFileLog(jsonEncode(array(
- "exam_group_id" => '',
- "operate_project" => 'zsyas2',
- "title" => '打包打印',
- "school_id" => $this->schoolId,
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $url,
- "operate_sql" => '',
- "operate_param" =>json_encode(array('params'=>array('examId'=>$exam_id,'students'=>$student_ids),'rs'=>$rs)),
- "date"=>date('Y-m-d H:i:j')
- )));
- }
- if(isset($rs->errCode) && $rs->errCode =='00')
- {
- ClassExamPrinter::model()->updateAll(array('is_print'=>1),'exam_id=:exam_id',array(':exam_id'=>$exam_id));
- echo json_encode(array('status'=>1,'result'=>$rs->data));exit;
- }
- $errMsg = '下载失败';
- if(isset($rs->errMsg))
- {
- $errMsg = $rs->errMsg;
- }
- echo json_encode(array('status'=>0,'result'=>$errMsg));exit;
- }
- public function CrmApiPost($url, $arr, $username,$password,$type='POST',$header=array())
- {
- $ch = @curl_init();
- $result = FALSE;
- if ($ch)
- {
- $data = json_encode($arr);
- $headerArr=array(
- 'Content-Type: application/json',
- 'Content-Length: '. strlen($data),
- 'Connection: false',
- 'Expect:'
- );
- if($header){
- $headerArr=array_merge($headerArr,$header);
- }
- if($type=='POST'){
- // Digest认证
- curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
- curl_setopt($ch, CURLOPT_USERPWD, $username .':'. $password);
- // 不输出头部
- curl_setopt($ch, CURLOPT_HEADER, 0);
- // curl_exec 获取到的内容不直接输出, 而是返回
- curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
- curl_setopt($ch, CURLOPT_TIMEOUT,120);
- curl_setopt($ch, CURLOPT_NOSIGNAL,1);
- curl_setopt($ch, CURLOPT_TIMEOUT_MS,120000);
- // 请求重启路由器的地址 传参 进行重启
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_USERAGENT, 'Api Client/1.0.0 (chengfei@liancaitech.com)');
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArr);
- if( !curl_errno($ch))
- {
- $result = json_decode(curl_exec($ch));
- }
- // 释放资源
- curl_close($ch);
- }elseif($type=='PUT'){
- $data = json_encode($arr);
- curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
- curl_setopt($ch, CURLOPT_USERPWD, $username .':'. $password);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
- curl_setopt($ch, CURLOPT_TIMEOUT, 10);
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArr);
- $result = json_decode(curl_exec($ch));
- curl_close($ch);
- }
- }
- return $result;
- }
- //获取考试的班级
- public function actionGetExamClass(){
- $examGroupId = Req::get("examGroupId");
- $printType = (string)Req::get("printType");
- $productType = (string)Req::get("productType");
- $subjectId = (int)Req::get("subjectId");
- $resultList =$resetLogs= array();
- $resetTotal=3;//学管重置总次数
- if(is_numeric($examGroupId) && $examGroupId > 0){
- $condition[] = " e.exam_group_id = ".$examGroupId;
- if ($printType == 'third_isp' || $subjectId == 8) {
- $condition[] = "e.subject_id = 8";
- }elseif ($printType == 'third_wb') {
- $condition[] = "e.subject_id = '{$subjectId}'";
- }elseif (in_array($this->subjectId,$this->mathSubjectId)) {
- $condition[] = "e.subject_id in (".implode(',',$this->mathSubjectId).")";
- } else {
- $condition[] = "e.subject_id = '{$this->subjectId}'";
- }
- switch ($printType) {
- case "wp":
- $printTypeData = 0;
- break;
- case "wtb":
- $printTypeData = 1;
- break;
- case "isp":
- $printTypeData = 2;
- break;
- case "studytrend":
- $printTypeData = 3;
- break;
- case "section":
- $printTypeData = 4;
- break;
- case "third_wb":
- $printTypeData = 1;
- break;
- case "third_isp":
- $printTypeData = 3;
- break;
- case "exam_product":
- $printTypeData = $productType;
- break;
- default:
- $printTypeData = null;
- break;
- }
- if(!Str::isBlank($printTypeData)){
- $condition[] = "cep.type = '{$printTypeData}'";
- }
- if ($printType == 'wp') {
- $condition[] = "eg.is_third = 0";
- $resultList = $this->schoolManager->getPrintList($condition,array('e.create_time desc'));
- }elseif($printType == 'exam_product'){
- //FIXME 新考试类型产品(如初高中方法宝)
- $examProduct = new SExamProductStatus();
- $rs = $examProduct->getProductList($condition,array('e.create_time desc'), $productType,100);
- $resultList = isset($rs['rs']) ? $rs['rs'] : array();
- }
- else {
- $resultList = $this->schoolManager->getDownloadClassIpf($condition,array('e.complete_time desc'));
- }
- $resetLogs=$this->sConn->createCommand("select exam_group_id,exam_id,class_id,learn_tube_reset_count,learn_tube_reset_time,reset_count from product_reset_log where exam_group_id ='{$examGroupId}' and product_type='".$printTypeData."'")->queryAll();
- foreach($resetLogs as $key=>$resetLogInfo){
- unset($resetLogs[$key]);
- $resetLogs[$resetLogInfo['class_id']]=$resetLogInfo;
- }
- foreach($resultList as &$item){
- $learnTubeResetCount=isset($resetLogs[$item['class_id']]['learn_tube_reset_count'])?$resetLogs[$item['class_id']]['learn_tube_reset_count']:0;
- $learnTubeResetTime=isset($resetLogs[$item['class_id']]['learn_tube_reset_time'])?$resetLogs[$item['class_id']]['learn_tube_reset_time']:0;
- $learnTubeResetResidueCount=$resetTotal>$learnTubeResetCount?$resetTotal-$learnTubeResetCount:0;
- $item['learn_tube_reset_count']=$learnTubeResetCount;
- $item['learn_tube_reset_residue_count']=$learnTubeResetResidueCount;
- //学管30分钟内只能重置一次
- $item['is_cool_down']=time()-$learnTubeResetTime<=1800?0:1;
- //冷却文字提示 30分钟内并且剩余次数大于0
- $item['is_cool_down_prompt']=!$item['is_cool_down'] && $learnTubeResetResidueCount?true:false;
- $item['reset_count']=isset($resetLogs[$item['class_id']]['reset_count'])?$resetLogs[$item['class_id']]['reset_count']:0;
- }
- }
- //是不是技术支持
- $isTechnicalSupport=1;
- if(!isset(Yii::app()->session['testFlag']) || Yii::app()->session['testFlag']!=1 ){
- $isTechnicalSupport=0;
- }
- $data=array(
- "resultList" => $resultList,
- 'printType'=>$printType,
- 'productType'=>$productType,
- 'is_technical_support'=>$isTechnicalSupport,
- );
- $this->render('reset_isp',$data);
- }
- //设置阶段个性化学习宝
- public function actionSetReviewIsp(){
- $res = array();
- $res['status'] = 0;
- $res['msg'] = '';
- $error = array();
- $semester_id = Req::post("semester_id");
- $category = (int)Req::post("category");
- $_class_id = (string)Req::post("class_id");
- $handle_type = (string)Req::post("handle_type");
- if(!($semester_id && is_numeric($semester_id))){
- $error[] = '学期参数不正确';
- }
- if(!in_array($category,array(1,2,3,4,5,6))){
- $error[] = '类型参数不正确';
- }
- if(!$handle_type){
- $error[] = '操作类型参数不正确';
- }
- $status = 0;
- if($handle_type == 'generat'){
- $status = 1;
- }else{
- $status = 90;
- }
- if(in_array($this->subjectId,$this->mathSubjectId)){
- $subjectId=3;
- }else{
- $subjectId=$this->subjectId;
- }
- //验证时间在不在当前学期范围内
- $time = time();
- // if(!$error){
- // $semester = Semester::model()->find(
- // array(
- // 'select'=>'start_time,end_time',
- // 'condition'=>'status = 1',
- // )
- // );
- //
- // if($semester){
- // if (!($time >= $semester->start_time && $time <= $semester->end_time)) {
- // $error[] = '时间不在当前学期范围内';
- // }
- // }else{
- // $error[] = '学期数据不正确';
- // }
- // }
- $gradeArr=array();
- if(!$error){
- $busTran = $this->sConn->beginTransaction();
- try{
- $sql = 'select class_id,grade from `class` where semester_id = '.$semester_id;
- if ($_class_id) {
- $sql .= ' and class_id = ' . $_class_id;
- }
- $class_info = $this->sConn->createCommand($sql)->queryAll();
- if ($class_info) {
- $class_ids = array();
- foreach ($class_info as $info) {
- $class_ids[$info['class_id']] = $info['class_id'];
- $gradeArr[$info['grade']]=$info['grade'];
- }
- }else{
- throw new Exception('本学期没班级');
- }
- $sql = 'select rprs_id from review_paper_product_set where semester_id = '.$semester_id.' and category = '.$category.' and subject_id='.$subjectId;
- $product_set_info = $this->sConn->createCommand($sql)->queryRow();
- if ($product_set_info) {
- $sql = "update review_paper_product_set set `status` = {$status},update_time = {$time},reset_time={$time} where rprs_id = {$product_set_info['rprs_id']}";
- }else{
- $sql = "insert into review_paper_product_set(semester_id,category,status,update_time,create_time,subject_id) value({$semester_id},{$category},{$status},{$time},{$time},{$subjectId})";
- }
- $bool = $this->sConn->createCommand($sql)->execute();
- if ($bool === false) {
- throw new Exception('操作产品设置失败');
- }
- if (isset($product_set_info['rprs_id']) && $product_set_info['rprs_id']) {
- $rprs_id = $product_set_info['rprs_id'];
- }else{
- $rprs_id = $this->sConn->getLastInsertID();
- }
- $sql = 'select rpc_id,class_id,status from `review_product_class` where rprs_id = '.$rprs_id.' and class_id in ('.implode(',',$class_ids).')';
- if ($_class_id) {
- $sql .= ' and class_id = ' . $_class_id;
- }
- $product_class_info = $this->sConn->createCommand($sql)->queryAll();
- $class_rel_rprc = array();
- if ($product_class_info) {
- foreach ($product_class_info as $info) {
- $class_rel_rprc[$info['class_id']] = $info['rpc_id'];
- }
- }
- //创建或更新数据
- $update_class_sql = array();
- $insert_class_sql = array();
- foreach ($class_ids as $class_id) {
- if (isset($class_rel_rprc[$class_id])) {
- $update_class_sql[] = "update review_product_class set `status` = {$status},update_time = {$time} where rpc_id = {$class_rel_rprc[$class_id]}";
- }else{
- $insert_class_sql[] = "({$rprs_id},{$class_id},{$status},{$time},{$time})";
- }
- }
- if ($update_class_sql) {
- foreach ($update_class_sql as $_sql) {
- $bool = $this->sConn->createCommand($_sql)->execute();
- if ($bool === false) {
- throw new Exception('操作产品班级失败');
- }
- }
- }
- if ($insert_class_sql) {
- $_sql = "insert into review_product_class(rprs_id,class_id,status,update_time,create_time) values ".implode(',',$insert_class_sql);
- $_sql = rtrim($_sql, ',');
- $bool = $this->sConn->createCommand($_sql)->execute();
- if ($bool === false) {
- throw new Exception('操作产品班级失败');
- }
- }
- //更新学生生成状态
- if ($status == 90) {
- if ($category > 3) {
- $_category = $category - 3;
- }else{
- $_category = $category;
- }
- //重置后清除已存在的下载任务
- $unique_key = $semester_id . '_' . $_category;
- $this->conn->createCommand("delete from pack_product_task where school_id ={$this->schoolId} and unique_key= '{$unique_key}' and product_type=4 and subject_id='{$subjectId}'")->execute();
- $rpcIds=array_values($class_rel_rprc);
- $sql = "update student_product set `is_html_created` = 0,is_pdf_created = 0 where semester_id = {$semester_id} and product_type = {$category} and plan_id in(".implode(',',$rpcIds).") ";
- if ($_class_id) {
- $_sql = 'select student_id from student_class_relation where class_id = '.$_class_id.' and status = 0';
- $class_student = $this->sConn->createCommand($_sql)->queryAll();
- $class_stu_ids = array();
- if ($class_student) {
- foreach ($class_student as $value) {
- $class_stu_ids[] = $value['student_id'];
- }
- }else{
- throw new Exception('班级没有对应的学生');
- }
- $sql .= ' and student_id in ('.implode(',',$class_stu_ids).')';
- }
- $this->sConn->createCommand($sql)->execute();
- }
- $busTran->commit();
- //发送消息{"school_id":"3955","subject_id":"3","send_type":"stage_review","msg_type":1,"grade_ids":[1],"year":2021,
- //"product_type":"1","class_ids":["683589263477706752"],"student_ids":[]}
- if($handle_type=='reset'){
- $msgType=90;
- }else{
- $msgType=1;
- }
- if ($_class_id) {
- $sendMsg=array(
- 'school_id'=>$this->schoolId,
- 'msg_type'=>$msgType,
- 'subject_id'=>$subjectId,
- 'send_type'=>'many_stage_review',
- 'grade_ids'=>array_values($gradeArr),
- 'year'=>isset(Yii::app()->params['season_product_year'])?Yii::app()->params['season_product_year']:date('Y'),
- 'product_type'=>$category,
- 'class_ids'=>array($_class_id)
- );
- sendDataToKafka('php-product-many-stage-html',$sendMsg);
- }else{
- foreach ($gradeArr as $value){
- $sendMsg=array(
- 'school_id'=>$this->schoolId,
- 'msg_type'=>$msgType,
- 'subject_id'=>$subjectId,
- 'send_type'=>'many_stage_review',
- 'grade_ids'=>array($value),
- 'year'=>isset(Yii::app()->params['season_product_year'])?Yii::app()->params['season_product_year']:date('Y'),
- 'product_type'=>$category,
- );
- sendDataToKafka('php-product-many-stage-html',$sendMsg);
- }
- }
- }catch(Exception $e){
- $error[] = $e->getMessage();
- $busTran->rollBack();
- }
- }
- if($error){
- $res['msg'] = implode(PHP_EOL,$error);
- echo json_encode($res);
- }else{
- $res['status'] = 1;
- echo json_encode($res);
- }
- exit;
- }
- //读取班级
- public function actionLoadClass(){
- $grade=Req::post('grade');
- $branch=Req::post('branch');
- $exam_group_ids=Req::post('eid');
- $result['status']=0;
- $examClass=array();
- //获取考试ID
- $criteria = new CDbCriteria();
- $criteria->select = 'exam_id,exam_group_id';
- $criteria->addCondition("exam_group_id='".$exam_group_ids."'");
- $exam_data = Exam::model()->findAll($criteria);
- unset($criteria);
- unset($exam_group_ids);
- if($exam_data)
- {
- foreach($exam_data as $v)
- {
- $exam_ids[] = $v->exam_id;
- }
- unset($exam_data);
- //通过考试ID,获取打印班级
- $criteria = new CDbCriteria();
- $criteria->select = 'exam_id,class_id';
- $criteria->addInCondition('exam_id',$exam_ids);
- $class_print_data = ClassExamPrinter::model()->findAll($criteria);
- if($class_print_data)
- {
- foreach($class_print_data as $v)
- {
- $examClass[]=(string)$v->class_id;
- }
- }
- unset($criteria);
- unset($class_print_data);
- }
- //判断考试是否走班考试
- $class_type=1;
- if($examClass){
- $checkClassData=ClassModel::model()->find('class_id=:classid',array(':classid'=>$examClass[0]));
- if($checkClassData && $checkClassData->class_type==2){
- $class_type=2;
- }
- }
- if($branch){
- $class_data = ClassModel::model()->findAll('semester_id=:semester_id and grade=:grade and arts_science=:arts_science and class_type=:class_type and is_hide=0',array(':semester_id'=>$this->semesterId,":grade"=>$grade,':arts_science'=>$branch,":class_type"=>$class_type));
- }else{
- $class_data = ClassModel::model()->findAll('semester_id=:semester_id and grade=:grade and class_type=:class_type and is_hide=0 ',array(':semester_id'=>$this->semesterId,":grade"=>$grade,":class_type"=>$class_type));
- }
- $groupClassData=array();
- foreach ($class_data as $val){
- $temp=array(
- 'class_id'=>$val->class_id,
- 'class_name'=>$val->class_name,
- 'grade' =>$val->grade,
- 'arts_science'=>$val->arts_science
- );
- if(in_array((string)$val->class_id,$examClass,true)){
- $temp['is_used']=1;
- }else{
- $temp['is_used']=0;
- }
- $groupClassData[$val->level][]=$temp;
- }
- $result['status']=1;
- $result['classData']=$groupClassData;
- exit(json_encode($result));
- }
- //提交选择班级结果
- public function actionSaveExamClass(){
- $classId=Req::post('classId');
- $exam_group_id=Req::post('eid');
- $result['status']=0;
- if(!$exam_group_id || !$classId || !is_array($classId)){
- $result['msg']='数据异常';
- exit(json_encode($result));
- }
- $examName='';
- $examClass=array(); //原考试班级
- $needDelClass=array(); //需要删除的班级
- $neeAddClass=array(); //需要增加的班级
- $time=time();
- //获取考试ID
- $criteria = new CDbCriteria();
- $criteria->select = 'exam_id,exam_group_id,class_id';
- $criteria->addCondition("exam_group_id='".$exam_group_id."'");
- $exam_data = Exam::model()->findAll($criteria);
- unset($criteria);
- if($exam_data)
- {
- foreach($exam_data as $v)
- {
- $exam_ids[] = $v->exam_id;
- $examClass[] = (string)$v->class_id;
- }
- foreach ($examClass as $key => $val){
- if(in_array((string)$val,$classId,true)){
- unset($classId[array_search((string)$val,$classId,true)]);
- }else{
- $needDelClass[]=$val; //需要删除
- }
- }
- if($classId){
- $neeAddClass= $classId;
- }
- $examDetail=$this->sConn->createCommand("select `name`,semester_id,subject_id,teacher_id,module_id,`type`,week_num,create_type,create_time,update_time,tpl_index,tpl_data,method_ids,from_exam_id,school_card_status,school_card_length from exam where exam_id='".$exam_ids[0]."' ")->queryRow();
- $papers = $this->sConn->createCommand("select paper_id from paper where exam_id IN (".implode(',',$exam_ids).")")->queryAll();
- $paperDetail=$this->sConn->createCommand("select paper_type,paper_layer,difficulty,topics_count,score,add_time,update_time,method_ids,is_labelled,status from paper where paper_id = '".$papers[0]['paper_id']."'")->queryRow();
- $paperTopics=$this->schoolManager->getPaperTopicsRecords($papers[0]['paper_id']);
- //增加班级
- if($neeAddClass){
- $transaction = $this->sConn->beginTransaction();
- try {
- foreach ($neeAddClass as $classId) {
- $newExamId=getUniqueId($this->schoolId);
- $studentIdData = $this->sConn->createCommand("select student_id from student_class_relation where class_id='" . $classId . "' and status=0 ")->queryAll();
- $studentIds=array();
- if($studentIdData){
- foreach ($studentIdData as $datum){
- $studentIds[]=$datum['student_id'];
- }
- }
- if(!$studentIds) continue;
- $studentIds_0 = BusinessStudent::model()->keepStudentsStatus_0($studentIds);
- $BStudentCards = BusinessStudent::model()->getCardsByStudentIds($studentIds_0);
- //添加考试
- $this->sConn->createCommand()->insert('exam', array(
- 'exam_id' => $newExamId,
- 'exam_group_id' => $exam_group_id,
- 'name' => $examDetail['name'],
- 'subject_id' => $examDetail['subject_id'],
- 'semester_id' => $examDetail['semester_id'],
- 'teacher_id' => $examDetail['teacher_id'],
- 'module_id' => $examDetail['module_id'],
- //'type' => $examDetail['type'],
- 'type' => $examDetail['type'],
- 'status' => 3,
- 'week_num' => $examDetail['week_num'],
- 'create_type' => $examDetail['create_type'],
- 'create_time' => $examDetail['create_time'],
- 'update_time' => $examDetail['update_time'],
- 'tpl_index' => $examDetail['tpl_index'],
- 'tpl_data' => $examDetail['tpl_data'],
- 'class_id' => $classId,
- 'method_ids' => $examDetail['method_ids'],
- 'from_exam_id' => $examDetail['from_exam_id'],
- 'school_card_status' => isset($examDetail['school_card_status']) ? $examDetail['school_card_status'] : 0,
- 'school_card_length' => isset($examDetail['school_card_length']) ? $examDetail['school_card_length'] : 0,
- // 'is_third' =>$examDetail['is_third']
- ));
- //添加试卷
- $newPaperId=getUniqueId($this->schoolId);
- $this->sConn->createCommand()->insert('paper', array(
- 'paper_id' => $newPaperId,
- 'paper_type' => $paperDetail['paper_type'],
- 'exam_id' => $newExamId,
- 'paper_name' => "",
- 'paper_layer' => $paperDetail['paper_layer'],
- 'difficulty' => $paperDetail['difficulty'],
- 'topics_count' => $paperDetail['topics_count'],
- 'score' => $paperDetail['score'],
- 'add_time' => $paperDetail['add_time'],
- 'update_time' => $paperDetail['update_time'],
- 'method_ids' => $paperDetail['method_ids'],
- 'is_labelled' => $paperDetail['is_labelled'],
- 'status' => $paperDetail['status']
- ));
- if ($studentIds_0) {
- foreach ($studentIds_0 as $studentId) {
- // $BStudentCards = BusinessStudent::model()->getCardsByStudentIds($studentIds);
- // if($studentIds){
- // foreach ($studentIds as $studentId) {
- $this->sConn->createCommand()->insert('student_paper_relation', array(
- 'student_id' => $studentId,
- 'paper_id' => $newPaperId,
- 'exam_id' => $newExamId,
- 'semester_id' => $this->semesterId,
- 'class_id' => $classId,
- 'student_card' => (isset($BStudentCards[0]) && isset($BStudentCards[0][$studentId]) ? $BStudentCards[0][$studentId] : 0),
- 'school_student_card' => (isset($BStudentCards[1]) && isset($BStudentCards[1][$studentId]) ? $BStudentCards[1][$studentId] : ''),
- ));
- }
- }
- foreach ($paperTopics as $paperTopic) {
- $this->sConn->createCommand()->insert('paper_topic_relation', array(
- 'paper_id' => $newPaperId,
- 'topic_id' => $paperTopic['topic_id'],
- 'order' => $paperTopic['order'],
- 'mode' => (int)$paperTopic['mode'],
- 'type' => $paperTopic['type'],
- 'score' => $paperTopic['score'],
- 'method_ids' => $paperTopic['method_ids'],
- 'method_difficulty' => $paperTopic['method_difficulty'] ? $paperTopic['method_difficulty'] : 2,
- ));
- $this->sConn->createCommand()->insert('topic_use', array(
- 'topic_id' => $paperTopic['topic_id'],
- 'mode' => $paperTopic['mode'],
- 'teacher_id' => $examDetail['teacher_id'],
- ));
- }
- $this->sConn->createCommand()->insert('class_exam_printer', array(
- 'class_id' => $classId,
- 'exam_id' => $newExamId,
- 'type' => 0,
- 'is_print' => 0,
- 'print_time' => 0,
- 'add_time' => $time,
- ));
- }
- $transaction->commit();
- }catch (Exception $e){
- $transaction->rollBack();
- exit(json_encode(array('status'=>0,'msg'=>'保存失败')));
- }
- }
- if($needDelClass){
- $transaction = $this->sConn->beginTransaction();
- try {
- foreach ($needDelClass as $classId){
- $exam=$this->sConn->createCommand("select exam_id from exam where exam_id IN (".implode(',',$exam_ids).") and class_id='".$classId."'")->queryRow();
- $paper = $this->sConn->createCommand("select paper_id from paper where exam_id ='".$exam['exam_id']."'")->queryRow();
- $this->sConn->createCommand("delete from `exam` where exam_id = '{$exam['exam_id']}'")->execute();
- $this->sConn->createCommand("delete from `paper` where paper_id = '{$paper['paper_id']}'")->execute();
- //student_paper_relation,paper_topic_relation,class_exam_printer
- $this->sConn->createCommand("delete from `student_paper_relation` where paper_id = '{$paper['paper_id']}'")->execute();
- $this->sConn->createCommand("delete from `paper_topic_relation` where paper_id = '{$paper['paper_id']}'")->execute();
- $this->sConn->createCommand("delete from `class_exam_printer` where exam_id = '{$exam['exam_id']}'")->execute();
- }
- $transaction->commit();
- }catch (Exception $e){
- $transaction->rollBack();
- exit(json_encode(array('status'=>0,'msg'=>'保存失败')));
- }
- }
- if(Yii::app()->params['handle_log_on_off'])
- {
- writeFileLog(jsonEncode(array(
- "exam_group_id" => $exam_group_id,
- "operate_project" => 'zsyas2',
- "school_id" => $this->schoolId,
- "title" => '添加考试班级',
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $this->getRoute(),
- "operate_sql" =>'',
- "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
- "date"=>date('Y-m-d H:i:j')
- )));
- }
- exit(json_encode(array('status'=>1,'msg'=>'设置成功')));
- }else{
- $result['msg']='考试数据异常';
- exit(json_encode($result));
- }
- }
- public function UUID_SHORT($length = 20)
- {
- $query = $this->sConn->createCommand("SELECT UUID_SHORT() AS UUID_SHORT")->query()->read();
- $result = $query['UUID_SHORT'];
- if ($length AND is_int($length))
- {
- $result = substr($result, ($length * -1));
- }
- return $result;
- }
- //删除全部未考试学生
- public function actionDelExamStudentAll()
- {
- $exam_group_id = Req::post('exam_group_id');
- $studentsIds = array();
- if(!$exam_group_id)
- {
- echo json_encode(array('status'=>0));exit;
- }
- //获取考试ID
- $criteria = new CDbCriteria();
- $criteria->select = 'exam_id,exam_group_id,class_id';
- $criteria->addCondition("exam_group_id='".$exam_group_id."'");
- $exam_data = Exam::model()->findAll($criteria);
- unset($criteria);
- if($exam_data) {
- foreach ($exam_data as $v) {
- $exam_ids[] = $v->exam_id;
- }
- }
- foreach ($exam_ids as $exam_id){
- $examStudentsIds=array();
- $student_data =$this->schoolManager->getStudentPaperByExamIds($exam_ids);
- if($student_data)
- {
- foreach($student_data as $v)
- {
- $examStudentsIds[$v['student_id']] = $v['student_id'];
- }
- $sendJsonArr[]=array(
- 'school_id'=>$this->schoolId,
- 'send_type'=>'zsyas',
- 'update_type'=>2,
- 'exam_group_id'=>$exam_group_id,
- 'exam_id_arr'=>array($exam_id),
- 'student_id_arr'=>$examStudentsIds
- );
- $studentsIds=array_merge($studentsIds,$examStudentsIds);
- }
- }
- if(!$studentsIds){
- echo json_encode(array('status'=>2));exit;
- }
- if($this->schoolManager->delStudentPaperPropertyByExamIds($exam_ids,$studentsIds))
- {
- //操作日志
- if(Yii::app()->params['handle_log_on_off'])
- {
- writeFileLog(jsonEncode(array(
- "exam_group_id" =>$exam_group_id,
- "operate_project" => 'zsyas2',
- "school_id" => $this->schoolId,
- "title" => '清空本次考试的学生',
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $this->getRoute(),
- "operate_sql" => json_encode(array('delete'=>array(
- 'student_paper_relation'=>array('exam_group_id'=>$exam_group_id)))),
- "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
- "date"=>date('Y-m-d H:i:j')
- )));
- }
- //发送学生端消息
- foreach ($sendJsonArr as $arr){
- sendStudentCacheQueue($arr);
- }
- echo json_encode(array('status'=>1));exit;
- }
- echo json_encode(array('status'=>0));exit;
- }
- //切换扫描方式
- public function actionChangeScan(){
- $data=array();
- $data['version_number'] =$this->version_number;
- $this->render('change_scan',$data);
- }
- //加载考试信息
- public function actionLoadExamInfo(){
- $exam_group_id=Req::post('exam_group_id');
- $result['status']=0;
- if(!$exam_group_id){
- exit(json_encode($result));
- }
- $examGroup=$this->sConn->createCommand("select teacher_id,mark_type,qxk_paper_id from exam_group where exam_group_id='".$exam_group_id."'")->queryRow();
- if(!$examGroup){
- $result['msg']='考试信息不正确';
- exit(json_encode($result));
- }
- $sql="SELECT e.exam_id,e.name,e.tpl_data,c.class_name,e.type FROM `exam` e
- join class c on e.class_id= c.class_id
- where e.exam_group_id='".$exam_group_id."'";
- $examClass=$this->sConn->createCommand($sql)->queryAll();
- $data=array();
- $data['class']='';
- $tplData=array();
- $subject=array(
- 3=>'高考数学',
- 6=>'高三专用',
- 51=>'新高一高二',
- 12=>'物理'
- );
- $topicTypeClass=array(
- 'jie'=>array(8,9,10,11),
- 'tian'=>array(5,6,7),
- 'single'=>array(1,2,12),
- 'multiple'=>array(3,4)
- );
- // '0:线下阅卷、1:按题阅卷、2:按人阅卷、3:班级混合阅卷、4:班级单独阅卷',
- $markType=array(
- 0=>'线下阅卷',1=>'按题阅卷',2=>'按人阅卷',3=>'班级混合阅卷',4=>'班级单独阅卷'
- );
- $typeArr=array(
- 1=>'周考',2=>'单元考',3=>'月考',4=>'联考',5=>'期中',6=>'期末',7=>'高考模拟',8=>'冲刺',
- );
- $data['mark_type']=$markType[$examGroup['mark_type']];
- $subjectId=$this->subjectId;
- if($examClass){
- foreach ($examClass as $val){
- if(!$tplData){
- $json=json_decode($val['tpl_data'],true);
- $tplData['examDate']=$json['examDate'];
- $tplData['subjectId']=$subject[$json['subjectId']];
- $subjectId=$json['subjectId'];
- if(isset($json['textbookId'])){
- $tplData['textbookId']=$json['textbookId'];
- }
- $tplData['qxk']=0;
- $tplData['type']=$typeArr[$val['type']];
- $tplData['author']=$json['author'];
- if($examGroup['qxk_paper_id']>0 && isset($json['new_items'])){
- $tplData['qxk']=1;
- foreach ($json['new_items'] as $item){
- if(in_array($item['basicTopicType'],$topicTypeClass['single'])){
- if(!isset($tplData['select_num'])){
- $tplData['select_num']=1;
- }else{
- $tplData['select_num']++;
- }
- }elseif(in_array($item['basicTopicType'],$topicTypeClass['multiple'])){
- if(!isset($tplData['mult_select_num'])){
- $tplData['mult_select_num']=1;
- }else{
- $tplData['mult_select_num']++;
- }
- }elseif(in_array($item['basicTopicType'],$topicTypeClass['tian'])){
- if(!isset($tplData['tiankong_num'])){
- $tplData['tiankong_num']=1;
- }else{
- $tplData['tiankong_num']++;
- }
- }elseif(in_array($item['basicTopicType'],$topicTypeClass['jie'])){
- if(isset($item['sameAliasNo']) && $item['sameAliasNo']){
- if(!isset($tplData['xuanzuo_num'])){
- $tplData['xuanzuo_num']=1;
- }else{
- $tplData['xuanzuo_num']++;
- }
- }else{
- if(!isset($tplData['jieda_num'])){
- $tplData['jieda_num']=1;
- }else{
- $tplData['jieda_num']++;
- }
- }
- }
- }
- }else{
- if(isset($json['items'][1])){
- $tplData['select_num']=$json['items'][1]['total'];
- }
- if(isset($json['items'][2])){
- $tplData['mult_select_num']=$json['items'][2]['total'];
- }
- if(isset($json['items'][5])){
- $tplData['tiankong_num']=$json['items'][5]['total'];
- }
- if(isset($json['items'][7])){
- $tplData['jieda_num']=$json['items'][7]['total'];
- }
- if(isset($json['items'][17])){
- $tplData['xuanzuo_num']=$json['items'][17]['total'];
- }
- }
- }
- $data['class'].='<span>'.$val['class_name'].'</span>';
- }
- }
- //读取教材
- if(isset($tplData['textbookId']) && $tplData['textbookId']){
- $textBook = $this->apiBrainPost('/textbook/tree', array('subjectId' => $subjectId ));
- if($textBook){
- foreach ($textBook as $value){
- if($tplData['textbookId']==$value->textbook_id){
- $tplData['textBook']=$value->textbook_name;
- }
- }
- }
- }
- $result['status']=1;
- $result['data']=array_merge($data,$tplData);
- exit(json_encode($result));
- }
- //切换扫描方式
- public function actionChangeExamScan(){
- $exam_group_id=Req::post('exam_group_id');
- $result['status']=0;
- if(!$exam_group_id){
- exit(json_encode($result));
- }
- $examGroup=$this->sConn->createCommand("select teacher_id,mark_type from exam_group where exam_group_id='".$exam_group_id."'")->queryRow();
- if(!$examGroup){
- $result['msg']='考试信息不正确';
- exit(json_encode($result));
- }
- $exam=$this->sConn->createCommand("select tpl_data from exam where exam_group_id='".$exam_group_id."'")->queryRow();
- $tpl_data=json_decode($exam['tpl_data'],true);
- if(isset($tpl_data['required']) && $tpl_data['required']>1){
- $result['msg']='选做题只支持多选一设置';
- exit(json_encode($result));
- }
- if(isset($tpl_data['items'][17]['required']) && $tpl_data['items'][17]['required']>1){
- $result['msg']='选做题只支持多选一设置';
- exit(json_encode($result));
- }
- $updateSql="update exam_group set is_scan_changed=1 where exam_group_id='".$exam_group_id."'";
- if($this->sConn->createCommand($updateSql)->execute()){
- $thirdAnswerSheet=$this->sConn->createCommand("select sheet_id from third_answer_sheet where exam_group_id='".$exam_group_id."'")->queryRow();
- if($thirdAnswerSheet){
- $this->sConn->createCommand("delete from third_answer_sheet where exam_group_id='".$exam_group_id."' ")->execute();
- }
- $this->schoolManager->saveExamProcess($exam_group_id,11,time());
- $result['status']=1;
- }
- exit(json_encode($result));
- }
- //加载考试
- public function actionAjaxSearchExam(){
- $grade=Req::post('grade');
- $class=Req::post('class');
- $condition=array();
- $subject=$this->subjectId;
- $condition[]='eg.is_third=0';
- $condition[]='eg.is_scan_changed=0';
- $condition[]='e.status<>1';
- $condition[]='eg.mark_type<>0';
- // $condition[] = "eg.create_type <>6 ";
- if($subject==3){
- $condition[] = "e.subject_id in (".implode(',',$this->mathSubjectId).")";
- }else{
- $condition[]="e.subject_id ='".$subject."'";
- }
- if($grade){
- $condition[]="c.grade='".$grade."'";
- }
- if($class){
- $condition[]="c.class_id='".$class."'";
- }
- $sql="SELECT eg.exam_group_id,e.exam_id,e.name,c.grade,e.tpl_data,eg.is_third,e.`status`,c.class_id,e.subject_id,p.paper_id,eg.import_score_type,e.is_backlog,e.tpl_index,tas.online_card,tas.is_qrcode_online FROM `exam` e ";
- $sql.="join exam_group eg on eg.exam_group_id=e.exam_group_id ";
- $sql.="join class c on c.class_id=e.class_id ";
- $sql.="join paper p on p.exam_id=e.exam_id ";
- $sql.="left join third_answer_sheet tas on tas.exam_group_id=eg.exam_group_id ";
- if($condition){
- $sql.=" where ".implode(' and ',$condition);
- }
- $Exam = $this->sConn->createCommand($sql)->queryAll();
- $list=array();
- if($Exam){
- $paperIds=array();
- $examGroupIds=array();
- foreach($Exam as $key=>$val){
- if( $val['online_card'] && $val['is_qrcode_online']){
- continue;
- }
- $is_custom_tpl=false;
- $paper_tpl_type=0;
- if(in_array($val['tpl_index'], Yii::app()->params['custom_tpls_ids'])){
- //自定义模板
- $is_custom_tpl = true;
- }else{
- //非自定义模板
- $is_custom_tpl = false;
- }
- if (in_array($val['tpl_index'], Yii::app()->params['no_template_id']) || $is_custom_tpl) {
- //题卡分离
- $paper_tpl_type = 2;
- }else{
- $paper_tpl_type = 1;
- }
- if(in_array($val['tpl_index'],Yii::app()->params['merge_topic_tpl']))
- {
- $paper_tpl_type = 3;
- if($val['tpl_index'] == 9 )
- {
- $paper_tpl_type = 4;
- }
- }
- if(in_array($val['tpl_index'],Yii::app()->params['merge_topic_tpl_all']))
- {
- $paper_tpl_type = 3;
- if($val['tpl_index'] == 9 )
- {
- $paper_tpl_type = 4;
- }
- }
- if (!$is_custom_tpl && $paper_tpl_type != 3){
- continue;
- }
- $tpl_data=json_decode($val['tpl_data'],true);
- if(isset($tpl_data['items'][17])){
- // continue; //选做题过滤
- }
- if($val['is_backlog']==0){
- $examGroupIds[]=$val['exam_group_id'];
- }
- }
- if($class && $examGroupIds){
- $sqlClassCount="SELECT eg.exam_group_id,e.exam_id,e.name,e.tpl_data,eg.is_third,e.`status`,e.subject_id,eg.import_score_type FROM `exam_group` eg ";
- $sqlClassCount.="join exam e on eg.exam_group_id=e.exam_group_id ";
- $sqlClassCount.=" where e.exam_group_id in(".implode(',',$examGroupIds).") order by e.update_time desc";
- $ExamCount = $this->sConn->createCommand($sqlClassCount)->queryAll();
- foreach ($ExamCount as $val){
- $list[$val['exam_group_id']]=$val;
- }
- }
- }
- $result['status']=1;
- $result['list']=$list;
- exit(json_encode($result));
- }
- //联评卷列表
- public function actionUnited()
- {
- //初始化
- $exam_group_ids = array();
- $exam_ids = array();
- $_exam_ids = array();
- $_exam_group_ids = array();
- $exam_printer_num = array();
- $exam_use_wp = array();
- $data = array();
- $condition = array();
- $paper_exam = array();
- $class_exam = array();
- $class_ids = array();
- $class_grade_arr = array();
- $paper_arr = array();
- //筛选条件
- $printName = Req::get("name");
- $grade = Req::get("grade");
- $labelled = Req::get("labelled");
- $display = Req::get("display");
- $type = Req::get("type");
- // 发送标注条件
- if($labelled>-1)
- {
- $paper_exam = $this->schoolManager->getPaerLabelledByExam($labelled);
- if($paper_exam)
- {
- foreach($paper_exam as $v)
- {
- $s_exam_ids[$v['exam_id']] = $v['exam_id'];
- }
- }
- unset($paper_exam);
- }
- // 年级条件
- if($grade>0)
- {
- $class_data = $this->schoolManager->getSchoolByGrade($grade,$this->semesterId);
- if($class_data)
- {
- foreach($class_data as $v)
- {
- $class_ids[$v['class_id']] = $v['class_id'];
- }
- $exam_class_data = $this->schoolManager->getClassIdByExam($class_ids);
- if($exam_class_data)
- {
- foreach($exam_class_data as $v)
- {
- if(isset($s_exam_ids[$v['exam_id']]))
- {
- $l_b_exam_ids[$v['exam_id']] = $v['exam_id'];
- }else
- {
- $s_exam_ids[$v['exam_id']] = $v['exam_id'];
- }
- }
- }
- unset($exam_class_data);
- }
- unset($class_data);
- }
- if(isset($l_b_exam_ids))
- {
- if($l_b_exam_ids)
- {
- $condition[] = "e.exam_id in (".implode(',',$l_b_exam_ids).")";
- }else
- {
- $condition[] = "e.exam_id in (0)";
- }
- }else
- {
- if($labelled<0||$grade<1)
- {
- if(isset($s_exam_ids))
- {
- if($s_exam_ids)
- {
- $condition[] = "e.exam_id in (".implode(',',$s_exam_ids).")";
- }else
- {
- $condition[] = "e.exam_id in (0)";
- }
- }
- }else
- {
- $condition[] = "e.exam_id in (0)";
- }
- }
- // 多学科切换条件
- if(in_array($this->subjectId,$this->mathSubjectId)){
- $condition[] = "e.subject_id in (".implode(',',$this->mathSubjectId).")";
- }else{
- $condition[] = "e.subject_id = '{$this->subjectId}'";
- }
- if ( $display == 1) {
- $condition[] = "e.is_display = 1";
- }else
- {
- $condition[] = "e.is_display = 0";
- }
- // 考试名称条件
- if($printName)
- {
- $condition[] = "e.name like '%{$printName}%'";
- }
- $condition[] = "eg.is_united = 1";
- //获取考试列表
- $exam_list = $this->schoolManager->getPrintGroupList($condition,array('e.create_time desc'),12);
- $branch=array(
- 0=>'不分科',
- 1=>'文科',
- 2=>'理科'
- );
- //获取打印班级
- if($exam_list)
- {
- foreach($exam_list['rs'] as $key=>$v)
- {
- $items = array();
- $tpl_data=array();
- $exam_group_ids[$v['exam_group_id']] = $v['exam_group_id'];
- $exam_list['rs'][$key]['is_tpl'] = 0; // 需要上传模板
- $exam_list['rs'][$key]['is_custom_optional_topic'] = 0;
- $exam_list['rs'][$key]['is_paper_49'] = 0;
- if(isset($v['tpl_data'])){
- $tpl_data = json_decode($v['tpl_data'],1);
- }
- if(isset($tpl_data['branch'])){
- $exam_list['rs'][$key]['branch'] = $tpl_data['branch'];
- }
- if(in_array($v['tpl_index'], Yii::app()->params['custom_tpls_ids'])){
- //自定义模板
- $exam_list['rs'][$key]['is_custom_tpl'] = true;
- if(isset($tpl_data['items']) && isset($tpl_data['items'][17])){
- $exam_list['rs'][$key]['is_custom_optional_topic'] = 1;
- }
- $v['is_custom_tpl'] = true;
- }else{
- //非自定义模板
- $exam_list['rs'][$key]['is_custom_tpl'] = false;
- $v['is_custom_tpl'] = false;
- }
- if (in_array($v['tpl_index'], Yii::app()->params['no_template_id']) || $v['is_custom_tpl']) {
- $exam_list['rs'][$key]['is_tpl'] = 1;
- //题卡分离
- $exam_list['rs'][$key]['paper_tpl_type'] = 2;
- }else{
- $exam_list['rs'][$key]['paper_tpl_type'] = 1;
- }
- if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl']))
- {
- $exam_list['rs'][$key]['paper_tpl_type'] = 3;
- if($v['tpl_index'] == 9 )
- {
- $exam_list['rs'][$key]['paper_tpl_type'] = 4;
- }
- }
- if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl_all']))
- {
- $exam_list['rs'][$key]['paper_tpl_type'] = 3;
- if($v['tpl_index'] == 9 )
- {
- $exam_list['rs'][$key]['paper_tpl_type'] = 4;
- }
- }
- if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl7']))
- {
- $exam_list['rs'][$key]['is_paper_49'] = 1;
- }
- if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl8']))
- {
- $exam_list['rs'][$key]['is_paper_49'] = 1;
- }
- //题卡合一
- //读取联考文理科
- $united=$this->schoolManager->getUnitedByExamGroupId($v['exam_group_id']);
- if($united){
- $exam_list['rs'][$key]['branch_name']=$branch[$united['branch']];
- }else{
- $exam_list['rs'][$key]['branch_name']='';
- }
- }
- //获取考试ID
- $criteria = new CDbCriteria();
- $criteria->select = 'exam_id,exam_group_id';
- $criteria->addInCondition('exam_group_id',$exam_group_ids);
- $exam_data = Exam::model()->findAll($criteria);
- unset($criteria);
- unset($exam_group_ids);
- if($exam_data)
- {
- foreach($exam_data as $v)
- {
- //$exam_use_wp
- $exam_ids[$v->exam_id] = $v->exam_id;
- $_exam_group_ids[$v->exam_group_id][$v->exam_id] = $v->exam_id;
- $_exam_ids[$v->exam_id] = $v->exam_group_id;
- }
- unset($exam_data);
- //通过考试ID,获取打印班级
- $criteria = new CDbCriteria();
- $criteria->select = 'exam_id,class_id';
- $criteria->addInCondition('exam_id',$exam_ids);
- $criteria->addCondition('is_print = 1');
- $class_print_data = ClassExamPrinter::model()->findAll($criteria);
- if($class_print_data)
- {
- foreach($class_print_data as $v)
- {
- if( isset($_exam_ids[$v->exam_id]))
- {
- $exam_printer_num[$_exam_ids[$v->exam_id]][$v->exam_id] = $v->exam_id;
- }
- }
- }
- unset($criteria);
- unset($class_print_data);
- }
- }
- //获取班级年级
- $class_data = ClassModel::model()->findAll('semester_id=:semester_id',array(':semester_id'=>$this->semesterId));
- if($class_data)
- {
- foreach($class_data as $v)
- {
- $class_grade_arr[$v->class_id] = $v->grade;
- }
- }
- unset($class_data);
- //获取试卷标注状态
- $criteria = new CDbCriteria();
- $criteria->select = 'exam_id,is_labelled';
- $criteria->addInCondition('exam_id',$exam_ids);
- $paper_data = SPaper::model()->findAll($criteria);
- unset($criteria);
- if($paper_data)
- {
- foreach($paper_data as $v)
- {
- if( isset($_exam_ids[$v->exam_id]))
- {
- $paper_arr[$_exam_ids[$v->exam_id]] = $v->is_labelled;
- }
- }
- }
- //查询联评卷考试
- $apply_setting_type=1;
- $schoolInfo=$this->schoolManager->getSchoolInfo($this->schoolId);
- if($schoolInfo['client']==2){
- $apply_setting_type=0;
- }
- $TaskExam=$this->schoolManager->getUnitedList($apply_setting_type);
- $findSchool = BusinessSchool::model()->find('school_id=:scid',array(':scid'=>Yii::app()->session['coachInfo']['school_id']));
- $data['pages'] = $exam_list['pager'];
- $data['page_total'] = $exam_list['pager']->rowsCount;
- $data['printList'] = $exam_list['rs'];
- $data['printer'] = $exam_printer_num;
- $data['exam_class'] = $_exam_group_ids;
- $data["exam_use_wp"] = $findSchool->use_wp;
- $data["display"] = $display;
- $data["labelled"] = $labelled;
- $data["grade"] = $grade;
- $data["printName"] = $printName;
- $data["paper"] = $paper_arr;
- $data["class_grade"] = $class_grade_arr;
- $data["printType"] = $type;
- $data['task_exam']=$TaskExam;
- $this->render('group_list_united',$data);
- }
- public function actionClass_exam_united()
- {
- $condition = array();
- $exam_ids = array();
- $exam_id = '';
- $exam_name = '';
- $class_names = array();
- $class_ids = array();
- $class_print = array();
- $data = array();
- $exam_student_up_num = array();
- $exam_student_num = array();
- $class_name = Req::get("class_name");
- $exam_group_id = Req::get("exam_group_id");
- $masttype = (int)Req::get("masttype");
- $is_united = (int)Req::get('is_united');
- if($exam_group_id <= 0)
- {
- Yii::app()->jump->error('未找到考试信息!');
- }
- $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- if(!$exam_group_data)
- {
- Yii::app()->jump->error('未找到考试信息!');
- }
- $condition[] = "exam_group_id = ".$exam_group_id;
- //获取班级信息
- $class_data = $this->schoolManager->getSemesterClasses($this->semesterId);
- if($class_data)
- {
- foreach($class_data as $v)
- {
- if($class_name && $v['class_name'] == $class_name)
- {
- $class_ids[$v['class_id']] = $v['class_id'];
- }
- $class_names[$v['class_id']] = $v['class_name'];
- }
- }
- if($class_ids)
- {
- $condition[] = "class_id in (".implode(',',$class_ids).") ";
- }
- // 多学科切换条件
- if(in_array($this->subjectId,$this->mathSubjectId)){
- $condition[] = "subject_id in (".implode(',',$this->mathSubjectId).")";
- }else{
- $condition[] = "subject_id = '{$this->subjectId}'";
- }
- if($class_ids)
- {
- $condition[] = "class_id in (".implode(',',$class_ids).") ";
- }
- //获取考试列表
- $exam_data = $this->schoolManager->getExamsByExamGroupIdList($condition,array('exam_id desc'),12);
- if($exam_data['rs'])
- {
- foreach($exam_data['rs'] as $k=>$v)
- {
- $exam_ids[$v['exam_id']] = $v['exam_id'];
- $exam_id = $v['exam_id'];
- $exam_name = $v['print_name'];
- }
- }else
- {
- Yii::app()->jump->error('未找到考试信息!');
- }
- //查询联考模板
- $task_exam=$this->schoolManager->getUnitedByExamGroupId($exam_group_id);
- if(!$task_exam){
- Yii::app()->jump->error('联考数据读取失败!');
- }
- //获取班级考试是否打印
- $criteria = new CDbCriteria();
- $criteria->addInCondition('exam_id',$exam_ids);
- $criteria->addCondition('type = 0');
- $class_print_data = ClassExamPrinter::model()->findAll($criteria);
- if($class_print_data)
- {
- foreach($class_print_data as $v)
- {
- $class_print[$v->exam_id] = $v->is_print;
- }
- }
- unset($criteria);
- unset($class_print_data);
- //获取班级考试的上传成绩
- $criteria = new CDbCriteria();
- $criteria->select= 'student_id,is_feedback,exam_id';
- $criteria->addInCondition('exam_id',$exam_ids);
- $criteria->addCondition('is_del = 0');
- $student_paper_data = SStudentPaperRelation::model()->findAll($criteria);
- unset($exam_ids);
- if($student_paper_data)
- {
- foreach($student_paper_data as $v)
- {
- if($v->is_feedback)
- {
- $exam_student_up_num[$v->exam_id][$v->student_id] = $v->student_id;
- }
- $exam_student_num[$v->exam_id][$v->student_id] = $v->student_id;
- }
- }
- unset($criteria);
- unset($student_paper_data);
- //获取paper 表数据
- $paper_data = SPaper::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id));
- if(!$paper_data)
- {
- Yii::app()->jump->error('未找到考试信息!');
- }
- $printList = array();
- if($exam_data["rs"]){
- foreach ($exam_data['rs'] as $k=>$v) {
- $printList['is_tpl'] = 0; // 需要上传模板
- $printList['answer_card_uploaded'] = false;
- if(in_array($v['tpl_index'], Yii::app()->params['custom_tpls_ids'])){
- //自定义模板
- $printList['is_custom_tpl'] = true;
- $v['is_custom_tpl'] = true;
- }else{
- //非自定义模板
- $printList['is_custom_tpl'] = false;
- $v['is_custom_tpl'] = false;
- }
- if (in_array($v['tpl_index'], Yii::app()->params['no_template_id']) || $v['is_custom_tpl']) {
- $printList['is_tpl'] = 1;
- if(trim($paper_data->answer_card_src)){
- $printList['answer_card_uploaded'] = true;
- }
- //题卡分离
- $printList['paper_tpl_type'] = 2;
- }else{
- $printList['paper_tpl_type'] = 1;
- }
- if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl']))
- {
- $printList['paper_tpl_type'] = 3;
- if($v['tpl_index'] == 9 )
- {
- $printList['paper_tpl_type'] = 4;
- }
- }
- if(in_array($v['tpl_index'],Yii::app()->params['merge_topic_tpl_all']))
- {
- $printList['paper_tpl_type'] = 3;
- if($v['tpl_index'] == 9 )
- {
- $printList['paper_tpl_type'] = 4;
- }
- }
- //英语题卡分离一
- if($this->subjectId == 8){
- $printList['paper_tpl_type'] = 5;
- }
- }
- }
- // 获取多学科状态
- $this->setIs_new($exam_group_id);
- $data['printList'] = $exam_data['rs'];
- $data['print'] = $printList;
- $data['pages'] = $exam_data['pager'];
- $data['page_total'] = $exam_data['pager']->rowsCount;
- $data["class_name"] = $class_name;
- $data["class_data"] = $class_names;
- $data["exam_group_data"] = $exam_group_data;
- $data["exam_id"] = $exam_id;
- $data["exam_name"] = $exam_name;
- $data["exam_print"] = $class_print;
- $data["exam_student"] = $exam_student_num;
- $data["exam_up_student"] = $exam_student_up_num;
- $data["exam_group_id"] = $exam_group_id;
- $data['task_exam']=$task_exam;
- $this->render('class_exam_united',$data);
- }
- //报名统考列表
- public function actionUnitedTask(){
- $data=array();
- $apply_setting_type=1;
- $schoolInfo=$this->schoolManager->getSchoolInfo($this->schoolId);
- if($schoolInfo['client']==2){
- $apply_setting_type=0;
- }
- $TaskExam=$this->schoolManager->getAllUnitedList($apply_setting_type);
- $grade=array(
- 0=>'',
- 1=>'高一',
- 2=>'高二',
- 3=>'高三'
- );
- $branch=array(
- 0=>'不分科',
- 1=>'文科',
- 2=>'理科'
- );
- if($TaskExam){
- foreach ($TaskExam as $key=>$val){
- $TaskExam[$key]['sign_up']=0;
- //查询报名
- $singUpData=$this->schoolManager->getSignUpBySchoolIdTaskId($this->schoolId,$val['task_exam_id']);
- if($singUpData){
- $TaskExam[$key]['sign_up']=1;
- $TaskExam[$key]['mobile']=$singUpData['user_name'].'/'.$singUpData['mobile'];
- }
- $TaskExam[$key]['grade_name']=$grade[$val['grade']];
- $TaskExam[$key]['branch_name']=$branch[$val['branch']];
- }
- }
- $data['task_exam']=$TaskExam;
- $this->render('united_task',$data);
- }
- //报名
- public function actionSignUp(){
- $tk_exam_id = Req::post("exam_group_id");
- $contacts = Req::post('contacts');
- $tel = Req::post('tel');
- $school_id = $this->schoolId;
- $coach_id = Yii::app()->session['coachInfo']['coach_id'];
- $result['status']=0;
- $task_exam=$this->schoolManager->getUnitedByTaskExamId($tk_exam_id);
- if(!$task_exam){
- $result['msg']="联考信息有误";
- exit(json_encode($result));
- }
- if($task_exam['apply_deadline']<time()){
- $result['msg']="报名已截止";
- exit(json_encode($result));
- }
- $unitedExam=$this->schoolManager->getExamByTaskId($tk_exam_id);
- if($unitedExam){
- $result['msg']="考试已开始,不接受报名啦";
- exit(json_encode($result));
- }
- $signData=$this->schoolManager->getSignUpBySchoolIdTaskId($school_id,$tk_exam_id);
- if($signData){
- $result['msg']="已报名当次联考,不能重复报名";
- exit(json_encode($result));
- }else{
- //学校信息
- $schoolInfo=$this->schoolManager->getSchoolInfo($school_id);
- $insertData=array(
- 'teacher_id'=>$coach_id,
- 'school_id'=>$school_id,
- 'tk_exam_id'=>$tk_exam_id,
- 'user_name'=>$contacts,
- 'mobile'=>$tel,
- 'create_time'=>date('Y-m-d H:i:s'),
- 'school_name'=>$schoolInfo['school_name'],
- 'province_id'=>$schoolInfo['province_id'],
- 'city_id'=>$schoolInfo['city_id'],
- 'area_id'=>$schoolInfo['area_id'],
- 'address'=>$schoolInfo['address']
- );
- if($this->schoolManager->SignUp($insertData)){
- $result['status']=1;
- }
- }
- exit(json_encode($result));
- }
- //取消报名
- public function actionSignOut(){
- $tk_exam_id = Req::post("exam_group_id");
- $school_id = $this->schoolId;
- $result['status']=0;
- $task_exam=$this->schoolManager->getUnitedByTaskExamId($tk_exam_id);
- if(!$task_exam){
- $result['msg']="联考信息有误";
- exit(json_encode($result));
- }
- if($task_exam['apply_deadline']<time()){
- $result['msg']="报名时间已截止,不能撤消报名";
- exit(json_encode($result));
- }
- $unitedExam=$this->schoolManager->getExamByTaskId($tk_exam_id);
- if($unitedExam){
- $result['msg']="考试已开始,不能撤消报名";
- exit(json_encode($result));
- }
- if($this->schoolManager->SignOutBySchoolIdTaskId($school_id,$tk_exam_id)){
- $result['status']=1;
- }
- exit(json_encode($result));
- }
- // 下载联考答题卡
- public function actionCreate_united_tempelate(){
- $wpcode = Req::post("eid");
- $flag = Req::post("flag");
- $error['success'] = 0;
- if (empty($wpcode)) {
- $error['message'] = '么有周周练id!';
- echo json_encode($error);exit();
- }
- $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$wpcode));
- //获取本次考试的examids
- $exam_ids = array();
- $getRes=array();
- if($exam_data)
- {
- $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id));
- $index_tpl = 0;
- if($exam_group_data)
- {
- foreach($exam_group_data as $v)
- {
- $exam_ids[$v->exam_id] = $v->exam_id;
- $index_tpl = $v->tpl_index;
- }
- }
- $getRes['examGroupId']=$exam_data->exam_group_id;
- //读取联考数据
- $task_exam=$this->schoolManager->getUnitedByExamGroupId($exam_data->exam_group_id);
- if(!$task_exam){
- $error['message'] = '联考信息有误!';
- echo json_encode($error);exit();
- }
- $getRes['path']=$task_exam['answer_template_url'];
- if($exam_data['school_card_status']==1){
- $getRes['school_card_status']=1;
- $getRes['school_card_length']=(int)$exam_data['school_card_length'];
- }else{
- $school_card_length = 8;
- if($this->schoolId>999){
- $school_card_length = 9;
- }
- $getRes['school_card_status']=0;
- $getRes['school_card_length']=(int)$school_card_length;
- }
- if(in_array($index_tpl,Yii::app()->params['print_topic_tpl']))
- {
- $flag = 0;
- }
- if($flag==3 || $flag==4 || $flag == 12)
- {
- $criteria = new CDbCriteria();
- $criteria->addInCondition('exam_id',$exam_ids);
- $criteria->addCondition('type=:type');
- $criteria->params[':type'] = 0;
- $getResult = ClassExamPrinter::model()->findAll($criteria);
- if (!empty($getResult)) {
- ClassExamPrinter::model()->updateAll(array('is_print'=>1,'print_time'=>time()),$criteria);
- }
- }
- }
- $data['success']=1;
- $data['object']=$getRes;
- echo json_encode($data);die;
- }
- //晨读词汇全学科获取教材
- public function getQuanTextbook(){
- $result = array();
- $topicDetails = $this->apiBrainPost('/all_textbook/getTextbookBySubjectId', array('subjectId' => 8,'type'=>1), 25, true);
- if($topicDetails && isset($topicDetails['status']) && $topicDetails['status']){
- if(isset($topicDetails['data']) && $topicDetails['data']){
- $result = $topicDetails['data'];
- }
- }
- return $result;
- }
- //晨读词汇全学科获取知识点(暂时用于晨读词汇专题专项)
- public function getQuanKnowledge(){
- $result = array();
- $i=0;
- $data = $this->apiBrainPost('/all_knowledge/tree', array('subjectId' => 8,'isTree'=>1), 25, true);
- if($data && isset($data['status']) && $data['status']){
- if(isset($data['data']) && $data['data']){
- // $result = $data['data'];
- foreach($data['data'] as $level_1){
- if(isset($level_1['child']) && $level_1['child']){
- foreach($level_1['child'] as $level_2){
- if(isset($level_2['knowledge_name']) && $level_2['knowledge_name']=='语法'){
- if(isset($level_2['child']) && $level_2['child']){
- foreach($level_2['child'] as $level_3){
- if(isset($level_3['knowledge_id']) && $level_3['knowledge_id'] && isset($level_3['knowledge_name']) && $level_3['knowledge_name']){
- $result[$i] = array('special_id'=>$level_3['knowledge_id'],'special_name'=>$level_3['knowledge_name'],'items'=>array());
- if(isset($level_3['child']) && $level_3['child']){
- foreach($level_3['child'] as $level_4){
- if(!$level_4['child'] && isset($level_4['knowledge_id']) && $level_4['knowledge_id'] && isset($level_4['knowledge_name']) && $level_4['knowledge_name']){
- $result[$i]['items'][] = array('item_id'=>$level_4['knowledge_id'],'item_name'=>$level_4['knowledge_name']);
- }
- }
- }else{//二级知识点下无三级知识点时,二级补到三级(若专题下无子集时,子集呈现自身)
- $result[$i]['items'][] = array('item_id' => $level_3['knowledge_id'], 'item_name' => $level_3['knowledge_name']);
- }
- $i++;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- return $result;
- }
-
- //晨读词汇(高三)
- public function actionMrv3(){
- $data = array();
- $time = time();
- $data['year'] = $year = date("Y");
- $data['month'] = $month = (int)date("m");
- $data['week'] = $week = date("W", time()) - date("W", strtotime(date("Y-m-01", time()))) + 1;
- $quanTextbookData = $this->getQuanTextbook();
- if($quanTextbookData){
- foreach($quanTextbookData as $k=>$v){
- if(isset($v['textbook_id']) && isset($v['textbook_name'])){
- $data['textbookNames'][$v['textbook_id']] = $v['textbook_name'];
- if(!isset($textbookId)){
- $textbookId = $v['textbook_id'];
- }
- if($textbookId == $v['textbook_id']){
- if(isset($v['child']) && $v['child']){
- foreach($v['child'] as $kk=>$vv){
- $data['moduleNames'][$vv['textbook_id']] = $vv['textbook_name'];
- if(!isset($moduleId)){
- $moduleId = $vv['textbook_id'];
- }
- if($moduleId == $vv['textbook_id']){
- if(isset($vv['child']) && $vv['child']){
- foreach($vv['child'] as $kkk=>$vvv){
- $data['unitNames'][$vvv['textbook_id']] = $vvv['textbook_name'];
- }
- }
- }
- }
- }
- }
- }
- }
- }
-
- $specialArr = $this->getQuanKnowledge();
- /* 老流程暂时注释
- $textboookTree = new MongodbEnglishTree();
- $criteria = new EMongoCriteria();
- $_textbookData = $textboookTree->find($criteria,array());
- if($_textbookData){
- foreach ($_textbookData as $doc) {
- foreach($doc->attributes as $key => $value){
- if($key !== '_id'){
- if(isset($value['textbook_id']) && isset($value['name'])){
- $data['textbookNames'][$value['textbook_id']] = $value['name'];
- if(!isset($textbookId)){
- $textbookId = $value['textbook_id'];
- }
- if($textbookId == $value['textbook_id']){
- if(isset($value['module']) && $value['module']){
- foreach($value['module'] as $kk=>$vv){
- $data['moduleNames'][$vv['textbook_module_id']] = $vv['name'];
- if(!isset($moduleId)){
- $moduleId = $vv['textbook_module_id'];
- }
- if($moduleId == $vv['textbook_module_id']){
- if(isset($vv['unit']) && $vv['unit']){
- foreach($vv['unit'] as $kkk=>$vvv){
- $data['unitNames'][$vvv['textbook_unit_id']] = $vvv['name'];
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
-
- $textboookTree = new MongodbGrammarSpecial();
- $criteria = new EMongoCriteria();
- $textbookData = $textboookTree->find($criteria,array());
- $specialArr = array();
- if($textbookData){
- foreach ($textbookData as $doc) {
- if ($doc['child']) {
- $item = array();
- foreach ($doc['child'] as $child) {
- $item[] = array(
- 'item_id' => $child['grammar_id'],
- 'item_name' => $child['content'],
- );
- }
- $specialArr[] = array(
- 'special_id' => $doc['_id'],
- 'special_name' => $doc['content'],
- 'items' => $item
- );
- }
- }
- }
- */
- $data['special_arr'] = $specialArr;
- // $data['special_arr'] = array(
- // array(
- // 'special_id' => 1,
- // 'special_name' => '专题1',
- // 'is_selected' => true,
- // 'items' => array(
- // array(
- // 'item_id' => 32,
- // 'item_name' => '专项11',
- // 'is_selected' => true,
- // ),
- // array(
- // 'item_id' => 1232,
- // 'item_name' => '专项10',
- // 'is_selected' => true,
- // ),
- // )
- // ),
- // array(
- // 'special_id' => 2,
- // 'special_name' => '专题2',
- // 'is_selected' => true,
- // 'items' => array(
- // array(
- // 'item_id' => 324,
- // 'item_name' => '专项12',
- // 'is_selected' => true,
- // ),
- // array(
- // 'item_id' => 387,
- // 'item_name' => '专项13',
- // 'is_selected' => true,
- // ),
- // )
- // ),
- // );
- $data['printType'] = 'mrv3';
- $this->render('mrv_3',$data);
- }
- //晨读词汇(高一高二)
- public function actionMrvSetting(){
- $data = array();
- $time = time();
- $data['year'] = $year = date("Y");
- $data['month'] = $month = (int)date("m");
- $data['week'] = $week = date("W", time()) - date("W", strtotime(date("Y-m-01", time()))) + 1;
- $quanTextbookData = $this->getQuanTextbook();
- if($quanTextbookData){
- foreach($quanTextbookData as $k=>$v){
- if(isset($v['textbook_id']) && isset($v['textbook_name'])){
- $data['textbookNames'][$v['textbook_id']] = $v['textbook_name'];
- if(!isset($textbookId)){
- $textbookId = $v['textbook_id'];
- }
- if($textbookId == $v['textbook_id']){
- if(isset($v['child']) && $v['child']){
- foreach($v['child'] as $kk=>$vv){
- $data['moduleNames'][$vv['textbook_id']] = $vv['textbook_name'];
- if(!isset($moduleId)){
- $moduleId = $vv['textbook_id'];
- }
- if($moduleId == $vv['textbook_id']){
- if(isset($vv['child']) && $vv['child']){
- foreach($vv['child'] as $kkk=>$vvv){
- $data['unitNames'][$vvv['textbook_id']] = $vvv['textbook_name'];
- }
- }
- }
- }
- }
- }
- }
- }
- }
-
- /*老流程暂时注释
- $textboookTree = new MongodbEnglishTree();
- $criteria = new EMongoCriteria();
- $textbookData = $textboookTree->find($criteria,array());
- if($textbookData){
- foreach ($textbookData as $doc) {
- foreach($doc->attributes as $key => $value){
- if($key !== '_id'){
- if(isset($value['textbook_id']) && isset($value['name'])){
- $data['textbookNames'][$value['textbook_id']] = $value['name'];
- if(!isset($textbookId)){
- $textbookId = $value['textbook_id'];
- }
- if($textbookId == $value['textbook_id']){
- if(isset($value['module']) && $value['module']){
- foreach($value['module'] as $kk=>$vv){
- $data['moduleNames'][$vv['textbook_module_id']] = $vv['name'];
- if(!isset($moduleId)){
- $moduleId = $vv['textbook_module_id'];
- }
- if($moduleId == $vv['textbook_module_id']){
- if(isset($vv['unit']) && $vv['unit']){
- foreach($vv['unit'] as $kkk=>$vvv){
- $data['unitNames'][$vvv['textbook_unit_id']] = $vvv['name'];
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- */
- $data['printType'] = 'mrv_setting';
- $this->render('mrv_setting',$data);
- }
- //动态获取模块和单元(晨读词汇)
- public function actionAjaxWeekGetModuleAndUnit(){
- $result = array();
- $error = array();
- $textbookId=(int)Req::post('textbookId');
- $quanTextbookData = $this->getQuanTextbook();
- if($quanTextbookData){
- foreach($quanTextbookData as $key => $value){
- if(isset($value['textbook_id']) && isset($value['textbook_name'])){
- if($value['textbook_id'] == $textbookId){
- if(isset($value['child']) && $value['child']){
- foreach($value['child'] as $kk=>$vv){
- $result['moduleNames'][$vv['textbook_id']] = $vv['textbook_name'];
- if(!isset($moduleId)){
- $moduleId = $vv['textbook_id'];
- }
- if($moduleId == $vv['textbook_id']){
- if(isset($vv['child']) && $vv['child']){
- foreach($vv['child'] as $kkk=>$vvv){
- $result['unitNames'][$vvv['textbook_id']] = $vvv['textbook_name'];
- }
- }
- }
- }
- }
- }
- }
- }
- }
- echo json_encode($result);exit;
- }
-
- //动态获取模块和单元
- public function actionAjaxGetModuleAndUnit(){
- $result = array();
- $error = array();
- $textbookId=(int)Req::post('textbookId');
-
- $textboookTree = new MongodbEnglishTree();
- $criteria = new EMongoCriteria();
- $textbookData = $textboookTree->find($criteria,array());
- if($textbookData && $textbookId){
- foreach ($textbookData as $doc) {
- foreach($doc->attributes as $key => $value){
- if($key !== '_id'){
- if(isset($value['textbook_id']) && isset($value['name'])){
- if($value['textbook_id'] == $textbookId){
- if(isset($value['module']) && $value['module']){
- foreach($value['module'] as $kk=>$vv){
- $result['moduleNames'][$vv['textbook_module_id']] = $vv['name'];
- if(!isset($moduleId)){
- $moduleId = $vv['textbook_module_id'];
- }
- if($moduleId == $vv['textbook_module_id']){
- if(isset($vv['unit']) && $vv['unit']){
- foreach($vv['unit'] as $kkk=>$vvv){
- $result['unitNames'][$vvv['textbook_unit_id']] = $vvv['name'];
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
-
- echo json_encode($result);exit;
- }
-
- //动态获取单元(晨读词汇)
- public function actionAjaxWeekGetUnitByModuleId(){
- $result = array();
- $error = array();
- $textbookId=(int)Req::post('textbookId');
- $moduleId=(int)Req::post('moduleId');
- $quanTextbookData = $this->getQuanTextbook();
- if($quanTextbookData){
- foreach($quanTextbookData as $key => $value){
- if(isset($value['textbook_id']) && isset($value['textbook_name'])){
- if($value['textbook_id'] == $textbookId){
- if(isset($value['child']) && $value['child']){
- foreach($value['child'] as $kk=>$vv){
- if($moduleId == $vv['textbook_id']){
- if(isset($vv['child']) && $vv['child']){
- foreach($vv['child'] as $kkk=>$vvv){
- $result['unitNames'][$vvv['textbook_id']] = $vvv['textbook_name'];
- }
- }
- }
- }
- }
- }
- }
- }
- }
-
- echo json_encode($result);exit;
- }
-
- //动态获取单元
- public function actionAjaxGetUnitByModuleId(){
- $result = array();
- $error = array();
- $textbookId=(int)Req::post('textbookId');
- $moduleId=(int)Req::post('moduleId');
-
- $textboookTree = new MongodbEnglishTree();
- $criteria = new EMongoCriteria();
- $textbookData = $textboookTree->find($criteria,array());
- if($textbookData && $moduleId && $textbookId){
- foreach ($textbookData as $doc) {
- foreach($doc->attributes as $key => $value){
- if($key !== '_id'){
- if(isset($value['textbook_id']) && isset($value['name'])){
- if($value['textbook_id'] == $textbookId){
- if(isset($value['module']) && $value['module']){
- foreach($value['module'] as $kk=>$vv){
- if($moduleId == $vv['textbook_module_id']){
- if(isset($vv['unit']) && $vv['unit']){
- foreach($vv['unit'] as $kkk=>$vvv){
- $result['unitNames'][$vvv['textbook_unit_id']] = $vvv['name'];
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
-
- echo json_encode($result);exit;
- }
- //获取设置英语个性化学习宝的班级
- public function actionAjaxGetClassesBySettingWeek(){
- $result = array();
- $error = array();
- $grade=(int)Req::post('grade');
- $year = date("Y");
- $month = (int)date("m");
- // $week = date("W", time()) - date("W", strtotime(date("Y-m-01", time()))) + 1;
- $week = date("W");
- //获取班级
- $hasSettingClassIds = array();
- $sql = "select class_id,count(*) count from english_week where semester_id = '{$this->semesterId}' and year_num = {$year} and week_num = {$week} group by class_id";
- $data = $this->sConn->createCommand($sql)->queryAll();
- if($data){
- foreach($data as $k=>$v){
- if($v['count'] > 2){
- $hasSettingClassIds[] = (string)$v['class_id'];
- }
- }
- }
- if($grade){
- $sql = "select class_id,class_name from class where semester_id = '{$this->semesterId}' and grade = {$grade} and is_hide=0";
- $data = $this->sConn->createCommand($sql)->queryAll();
- if($data){
- $i = 0;
- foreach($data as $k => $v){
- $result[$i]['class_id'] = $v['class_id'];
- $result[$i]['class_name'] = $v['class_name'];
- if(in_array((string)$v['class_id'],$hasSettingClassIds,true)){
- $result[$i]['status'] = 1;
- }else{
- $result[$i]['status'] = 0;
- }
- $i++;
- }
- }
- }
- echo json_encode($result);exit;
- }
- //设置高一高二英语个性化学习宝
- public function actionAjaxSaveEnglishWeek(){
- $result = array();
- $error = array();
- if (! Yii::app()->request->isAjaxRequest OR ! Yii::app()->request->isPostRequest){
- $error[] = '错误的来源!';
- }else{
- $grade=(int)Req::post('grade');
- $unitIds = (array)Req::post('unitIds');
- $unitNames = (array)Req::post('names');
- $classIds = Req::post('selectClassIds');
- $itemIds = (array)Req::post('selectedItemIds');
- $classIds = array_unique($classIds);
- $wordType = Req::post('wordsType');
- $phraseType = Req::post('phraseType');
- $wordCount = Req::post('wordCount');
- $phraseCount = Req::post('phraseCount');
- $isAnswerSeparate = Req::post('isAnswerSeparate');
- $isSameAnswer = Req::post('isSameAnswer');
- $wordRange = Req::post('wordRange');
- $spellCount = Req::post('spellCount');
- $sentenceCount = Req::post('sentenceCount');
- $isWordDerive = Req::post('isWordDerive');
- $blankCount = Req::post('blankCount');
- $translateCount = Req::post('translateCount');
- $grammarSingleCount = Req::post('grammarSingleCount');
- $grammarSheetCount = Req::post('grammarSheetCount');
- $readingCount = Req::post('readingCount');
- $unitNames = (array)Req::post('names');
- $specialNames = (array)Req::post('specialNames');
- if(in_array($grade,array(1,2))){
- if(empty($unitIds)){$error[] = '请选择单元';}
- if(count($unitIds)>1){$error[] = '已选单元超出限制';}
- }
- if($grade == 3){
- if(empty($unitIds)){$error[] = '请选择单元';}
- if(count($unitIds)>3){$error[] = '已选单元超出限制';}
- }
- if(!$grade){
- $error[] = '请选择年级';
- }
- if(!$classIds){
- $error[] = '请选择班级';
- }
- $wordApply = array(
- 'spell_count' => $spellCount?$sentenceCount:0,
- 'sentence_count' => $sentenceCount?$sentenceCount:0,
- 'blank_count' => $blankCount?$blankCount:0,
- 'translate_count' => $translateCount?$translateCount:0
- );
- }
- if(!$error){
- $time = time();
- $weekIds = array();
- $month = (int)date("m");
- // $week = date("W", time()) - date("W", strtotime(date("Y-m-01", time()))) + 1;
- $week = date("W");
- $year = date("Y");
- $strModel = new SStudentClassRelation();
- $transaction = $this->sConn->beginTransaction();
- try{
- if ($grade == 3) {
- $weekName = '高三' . date('Y') . '年第' . date('W') . '周晨读词汇';
- }else{
- $weekName = $unitNames[0] . '晨读词汇';
- }
- $weekGroupId = getUniqueId($this->schoolId);
- foreach($classIds as $k=>$v){
- $weekId = getUniqueId($this->schoolId);
- $weekIds[] = $weekId;
- $this->sConn->createCommand()->insert('english_week_setting',array(
- 'grade' => $grade,
- 'class_id' => $v,
- 'semester_id' => $this->semesterId,
- 'node_ids' => implode(',',$unitIds),
- 'special_ids' => implode(',',$itemIds),
- 'create_time' => $time,
- 'words_type' => $wordType ? $wordType : 1,
- 'phrase_type'=> $phraseType ? $phraseType : 1,
- 'words_count'=> $wordCount ? $wordCount : 0,
- 'phrase_count'=> $phraseCount ? $phraseCount : 0,
- 'is_answer_separate'=>isset($isAnswerSeparate) ? $isAnswerSeparate : 1,
- 'words_range'=>isset($wordRange) ? $wordRange : 1,
- 'is_word_derive'=>isset($isWordDerive) ? $isWordDerive : 1,
- 'words_apply'=>json_encode($wordApply),
- 'is_same_answer' => isset($isSameAnswer)?$isSameAnswer:1,
- 'grammar_single_count' => $grammarSingleCount?$grammarSingleCount:0,
- 'grammar_sheet_count' => $grammarSheetCount?$grammarSheetCount:0,
- 'reading_count' => $readingCount?$readingCount:0,
- 'is_new_version'=>1,
- 'node_names'=>$unitNames ? addslashes(implode(",",$unitNames)) : '',
- 'special_names'=>$specialNames ? implode(",",$specialNames) : ''
- ));
- $set_id = $this->sConn->getLastInsertID();
- $this->sConn->createCommand()->insert('english_week',array(
- 'week_id' => $weekId,
- 'name' => $weekName,
- 'class_id' => $v,
- 'grade' => $grade,
- 'semester_id' => $this->semesterId,
- 'year_num' => $year,
- 'week_num' => $week,
- 'set_id'=>$set_id,
- 'create_time' => $time,
- 'week_group_id' => $weekGroupId,
- 'is_all_html'=>1
- ));
- //获取班级学生
- $stuData = $strModel->getRelationsByClassId_Status_0($v);
- if($stuData){
- foreach($stuData as $kk=>$vv){
- $this->sConn->createCommand()->insert('english_week_student',array(
- 'week_id' => $weekId,
- 'student_id' => $vv['student_id'],
- ));
- }
- $this->sConn->createCommand()->insert('english_week_student',array(
- 'week_id' => $weekId,
- 'student_id' => 0,
- ));
- }
- }
- $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'=>$error));exit;
- }else{
- //发送消息
- $kafkaData = array(
- 'school_id' => $this->schoolId,
- 'msg_type' => 1,//90:重置 1:新设置
- 'grade' => $grade,
- 'subject_id' => 8,
- 'send_type' => 'english_week',
- 'product_type' => 15,
- 'gp_group_id' => $weekGroupId,//reading_id
- 'gp_ids' => $weekIds,//week_id
- );
- sendDataToKafka("php-product-english-week-html", $kafkaData);
- echo json_encode(array('status'=>1));exit;
- }
- }
- /**
- * 重置晨读词汇
- */
- public function actionResetEnglishWeek(){
- $weekGroupId = (string)Req::get("weekGroupId");
- $data = array();
- $resetCount = 0;
- if($weekGroupId){
- $sql = "select ew.week_id,ew.`name`,ew.class_id,ew.is_reset,c.class_name from english_week ew join class c on ew.class_id = c.class_id where ew.week_group_id = '{$weekGroupId}'";
- $msg = $this->sConn->createCommand($sql)->queryAll();
- if($msg){
- $i=0;
- foreach($msg as $k=>$v){
- if($v["is_reset"]){
- $resetCount++;
- }
- $weekId = $v["week_id"];
- $data[$i]['total_count'] = 0;
- $data[$i]['create_count'] = 0;
- $data[$i]['name'] = $v["name"];
- $sql = "select count(*) total_count,count(case when is_week_pdf = 1 then 1 end) create_count from english_week_student where student_id > 0 and week_id = '{$weekId}'";
- $msg_student = $this->sConn->createCommand($sql)->queryRow();
- if($msg_student){
- $data[$i]['total_count'] = $msg_student["total_count"];
- $data[$i]['create_count'] = $msg_student["create_count"];
- }
- $data[$i]['week_id'] = $weekId;
- $data[$i]['class_name'] = $v["class_name"];
- $data[$i]['is_reset'] = $v["is_reset"];
- $i++;
- }
- }
- }
- if(!isset(Yii::app()->session['testFlag']) || Yii::app()->session['testFlag']==1 ){
- $resetCount = 0;
- }
- // debug($data);
- $this->render('english_week_reset',array("data"=>$data,"resetCount"=>$resetCount,"weekGroupId"=>$weekGroupId));
- }
-
- /**
- * 重置外刊美文功能
- */
- public function actionAjaxResetEnglishWeek(){
- $result = array();
- $error = array();
- if (! Yii::app()->request->isAjaxRequest OR ! Yii::app()->request->isPostRequest){
- $error[] = '错误的来源!';
- }else{
- $classExam=Req::post('classExam');
- if(!$classExam || !is_array($classExam)){
- $error[] = '请选择班级';
- }
- $redingId=Req::post('readingId');
- if(!$redingId){
- $error[] = '请刷新后再尝试';
- }
- }
- if(!$error){
- $time = time();
- $isNewVersion = 0;
- $transaction = $this->sConn->beginTransaction();
- try{
- $sql = "select week_group_id,week_id,grade,set_id from english_week where week_group_id='{$redingId}' and week_id in (".implode(',',$classExam).")";
- $englishReading = $this->sConn->createCommand($sql)->queryAll();
- if(!$englishReading){
- throw new Exception('无重置晨读词汇推送数据');
- }
- $setId = $englishReading[0]['set_id'];
- $sql = "select is_new_version from english_week_setting where id='{$setId}'";
- $englishSetting = $this->sConn->createCommand($sql)->queryRow();
- if($englishSetting){
- $isNewVersion = $englishSetting['is_new_version'];
- }
-
-
- $this->sConn->createCommand("update english_week set is_all_html = 1,is_reset=1,teacher_general_pdf_path='' where week_id in (".implode(',',$classExam).") ")->execute();
- $sql = "update english_week_student set week_download_time = 0,is_week_download=0,is_week_html=0,week_html_path='',is_week_pdf=0,week_pdf_path='' where week_id in (".implode(',',$classExam).") ";
- $this->sConn->createCommand($sql)->execute();
- //重置后清除已存在的下载任务
- $task_sql = "delete from pack_product_task where school_id ={$this->schoolId} and unique_key in (". implode(",", $classExam).") and product_type=9";
- $this->conn->createCommand($task_sql)->execute();
- $weekIds=array();
- $grade=0;
- foreach($englishReading as $item){
- if($isNewVersion){
- $weekIds[]=$item['week_id'];
- $grade=$item['grade'];
- }
- }
- $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'=>$error));exit;
- }else{
- //新设置重置才发消息
- if($weekIds && $grade) {
- $kafkaData = array(
- 'school_id' => $this->schoolId,
- 'msg_type' => 90,//90:重置 1:新设置
- 'grade' => $grade,
- 'subject_id' => 8,
- 'send_type' => 'english_week',
- 'product_type' => 15,
- 'gp_group_id' => $redingId,//reading_id
- 'gp_ids' => $weekIds,//week_id
- );
- sendDataToKafka("php-product-english-week-html", $kafkaData);
- }
- echo json_encode(array('status'=>1));exit;
- }
- }
-
- //晨读词汇列表
- public function actionMrv(){
- Url::clean();
- $data = array();
- $printName = Req::get("name");
- $classId = Req::get("classId");
- $grade = (int)Req::get("grade");
- $newCondition = array();
- if($grade){
- $newCondition[] = 'ew.grade='.$grade;
- }
- if($printName){
- $newCondition[] = 'ew.name like "%'.$printName.'%"';
- }
- if($classId){
- $newCondition[] = 'ew.class_id='.$classId;
- }
- $resultList = $this->schoolManager->getEnglishWeek($newCondition,array('ew.create_time desc','ew.week_id desc'));
- $printList = array();
- if($resultList["rs"]){
- foreach ($resultList['rs'] as $k=>$v) {
- $printList[$k]=$v;
- }
- }
- if (empty($grade)) {
- $grade = 'ALL';
- }
- $classes = $this->schoolManager->getClasses($grade);
- $data['pages'] = $resultList['pager'];
- $data['page_total'] = $resultList['pager']->rowsCount;
- $data['printList'] = $printList;
- $data["printName"] = $printName;
- $data["classes"] = $classes;
- $data["classId"] = $classId;
- $data["grade"] = $grade;
- $data['printType'] = 'mrv';
- // debug($printList);
- $this->render('mrv',$data);
- }
- //设置高三个性化学习宝
- public function actionAjaxSaveEnglishWeekByGrade3(){
- $result = array();
- $error = array();
- if (! Yii::app()->request->isAjaxRequest OR ! Yii::app()->request->isPostRequest){
- $error[] = '错误的来源!';
- }else{
- $week=(int)Req::post('week');
- if(!$week){
- $error[] = "请选择周几";
- }
- }
- if(!$error){
- $time = time();
- $sql = "select id from english_week_setting where grade = 3";
- $data = $this->sConn->createCommand($sql)->queryRow();
- if($data){
- $insertStatus = $this->sConn->createCommand()->update("english_week_setting", array("setting_week_num" => $week,"create_time"=>$time),"grade=3");
- }else{
- $insertStatus = $this->sConn->createCommand()->insert('english_week_setting',array(
- 'grade' => 3,
- // 'semester_id' => $this->semesterId,
- 'setting_week_num' => $week,
- 'create_time' => $time,
- ));
- }
- if(!$insertStatus){
- $error[] = '系统错误';
- }
- }
- if($error){
- echo json_encode(array('status'=>0,'error'=>$error));exit;
- }else{
- echo json_encode(array('status'=>1));exit;
- }
- }
- //晨读词汇选择学生
- public function actionSelectStuByMrv(){
- $data = array();
- $sname = (string)Req::get("sname"); //学生名字
- $weekId = (string)Req::get("weekId");
- if(!$weekId){
- Yii::app()->jump->error('参数错误!');
- }
- //获取班级名称以及周后推送名称
- $sql = "select ew.name,c.class_name,ew.grade,ew.class_id,ew.create_time,ew.semester_id from english_week ew join class c on ew.class_id = c.class_id where ew.week_id = '{$weekId}'";
- $names = $this->sConn->createCommand($sql)->queryRow();
- if(!$names){
- $names = array();
- $names['name'] = '';
- $names['class_name'] = '';
- $names['grade'] = 0;
- }else{
- $data['name'] = isset($names['name'])?$names['name']:'';
- }
- $sql = "select student_id,is_week_pdf from english_week_student where week_id = '{$weekId}'";
- $relateStudent = $this->sConn->createCommand($sql)->queryAll();
- $studentIds = array();
- $stuIsPdf = array();
- if($relateStudent){
- foreach ($relateStudent as $studentInfo) {
- $studentIds[] = (string)$studentInfo['student_id'];
- $stuIsPdf[(string)$studentInfo['student_id']] = $studentInfo['is_week_pdf'];
- }
- }
- if($studentIds){
- $studentNames = SStudentInfo::model()->getStudentNames($studentIds); //求学生名字
- if($studentNames){
- if($sname){
- $i = 1;
- foreach($studentNames as $k=>$v){
- if(strpos($v,$sname) !== false){
- $data['list'][$i]['stu_id'] = (string)$k;
- $data['list'][$i]['stu_name'] = $v;
- $data['list'][$i]['name'] = $names['class_name'].$v.$names['name'];
- $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$k])?$stuIsPdf[(string)$k]:0;
- $i++;
- }
- }
- }else{
- $i = 1;
- foreach($studentNames as $k=>$v){
- $data['list'][$i]['stu_id'] = (string)$k;
- $data['list'][$i]['stu_name'] = $v;
- $data['list'][$i]['name'] = $names['class_name'].$v.$names['name'];
- $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$k])?$stuIsPdf[(string)$k]:0;
- $i++;
- }
- }
- }
- }
- $Sem=new SSemester();
- $code= $Sem->conn->createQuery()
- ->from('semester')
- ->where("semester_id = '".$names['semester_id']."'")
- ->limit(1)
- ->query()
- ->read();
- $intarr=array(
- "schoolId"=>$this->schoolId,
- "clazzId"=>$names['class_id'],
- "semester"=>$code['refer_code'],
- "grade"=>$names['grade'],
- "students"=>$studentIds,
- "examTime"=>$names['create_time'],
- "classify"=>3,
- "subject"=>8
- );
- $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]);
- $order_classify = ProductDownload::$order_classify;
- $classifies = $order_classify[ProductDownload::PRODUCT_TYPE_EN_MRV];
- $canStudentIds = array();
- foreach ($classifies as $classify) {
- $intarr['classify'] = $classify;
- $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr), $basic));
- if (!$rs || $rs->errCode != "00") {
- continue;
- }
- if (!empty($rs->data)) {
- $canStudentIds = array_merge($canStudentIds,$rs->data);
- }
- }
- $canStudentIds = array_unique($canStudentIds);
- $data['limitstu'] = $canStudentIds ? $canStudentIds : array();
- $data['weekId'] = $weekId;
- $data['sname'] = $sname;
- $data['printType'] = 'mrv_stu';
- $this->render('mrv_stu',$data);
- }
- //下载晨读词汇个性化学习宝
- public function actionGetEnglishFile(){
- $weekId = (string)Req::get("weekId");
- $studentsIds = (string)Req::get("studentsIds");
- $params = array();
- if(!$weekId){
- echo json_encode(array("success" => 0, "message" => "缺少参数"));
- exit();
- }
- if(!$studentsIds){
- $studentsIds = array();
- $sql = "select student_id from english_week_student where week_id = '{$weekId}' and is_week_pdf = 1";
- $stuArr = $this->sConn->createCommand($sql)->queryAll();
- if($stuArr){
- foreach($stuArr as $k=>$v){
- $studentsIds[] = $v['student_id'];
- }
- }
- }else{
- $studentsIds = explode(',',$studentsIds);
- }
- if(!$studentsIds || empty($studentsIds)){
- echo json_encode(array("success" => 0, "message" => "无生成的学生"));
- exit();
- }
- $params['weekId'] = $weekId;
- $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
- if(!$apiUrl){
- echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
- exit();
- }
- $sql = "select class_id,grade,create_time,semester_id from english_week where week_id = '{$weekId}'";
- $msg = $this->sConn->createCommand($sql)->queryRow();
- $Sem=new SSemester();
- $code= $Sem->conn->createQuery()
- ->from('semester')
- ->where("semester_id = '".$msg['semester_id']."'")
- ->limit(1)
- ->query()
- ->read();
- $intarr=array(
- "schoolId"=>$this->schoolId,
- "clazzId"=>$msg['class_id'],
- "semester"=>$code['refer_code'],
- "grade"=>$msg['grade'],
- "students"=>$studentsIds,
- "examTime"=>$msg['create_time'],
- "classify"=>3,
- "subject"=>8
- );
- $schoolInfo = BusinessSchool::model()->find('school_id=:school_id', array(':school_id' => $this->schoolId));
- if(isset($schoolInfo['is_allow_download']) && ($schoolInfo['is_allow_download']==1)){
- if($studentsIds){
- $params["studentIds"] = $studentsIds;
- }
- }else{
- if(Yii::app()->params["limit_open"]){
- $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]);
- $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr),$basic));
- if(!$rs){
- Yii::app()->jump->error("接口错误");
- }
- if($rs->errCode!="00"){
- echo json_encode(array("success" => 0, "message" => $rs->errMsg));
- exit();
- }
- if(!empty($rs->data)){
- $params["studentIds"]=$rs->data;
- if(count($rs->data)<count($intarr['students'])){
- $limitinfo="购买过的".count($intarr['students'])-count($rs->data)."位学生可下载";
- }
- } else{
- echo json_encode(array("success" => 0, "message" =>"请先购买商品"));
- exit();
- }
- }else{
- if($studentsIds){
- $params["studentIds"] = $studentsIds;
- }
- }
- }
- $params['schoolId'] = $this->schoolId;
- $params['type'] = 1;
- $rs = Curl::post($apiUrl."/rest/download_week_pdf/index", $params);
- if(!($rs = json_decode($rs))){
- $rs = array(
- "success" => 0,
- "message" => "请求接口失败",
- );
- }else{
- //更新下载时间
- if($rs->success==1 || $rs->success==2){
- $time = time();
- if($studentsIds){
- $sql = "update english_week_student set is_week_download = 1,week_download_time={$time} where week_id = '{$weekId}' and student_id in (".implode(',',$studentsIds).")";
- $this->sConn->createCommand($sql)->execute();
- }
- }
- }
- // if(isset($rs->downloadPath)){
- // if (YII_ENV == 'pro' || YII_ENV == 'production') {
- // $rs->downloadPath = preg_replace('/http\:\/\/zstatic\d{1,2}/','http://zstatic'.$groupId,$rs->downloadPath);
- // }
- // }
- echo json_encode($rs);exit;
- }
- //月阶段复习列表
- public function actionMainly_revision(){
- Url::clean();
- $data = array();
- $printName = Req::get("name");
- $classId = Req::get("classId");
- $grade = (int)Req::get("grade");
- $newCondition = array();
- if($grade){
- $newCondition[] = 'em.grade='.$grade;
- }
- if($printName){
- $newCondition[] = 'em.name like "%'.$printName.'%"';
- }
- if($classId){
- $newCondition[] = 'em.class_id='.$classId;
- }
- $resultList = $this->schoolManager->getEnglishMonth($newCondition,array('em.create_time desc','em.month_id desc'));
- $printList = array();
- if($resultList["rs"]){
- foreach ($resultList['rs'] as $k=>$v) {
- $printList[$k]=$v;
- }
- }
- if (empty($grade)) {
- $grade = 'ALL';
- }
- $classes = $this->schoolManager->getClasses($grade);
- $data['pages'] = $resultList['pager'];
- $data['page_total'] = $resultList['pager']->rowsCount;
- $data['printList'] = $printList;
- $data["printName"] = $printName;
- $data["classes"] = $classes;
- $data["classId"] = $classId;
- $data["grade"] = $grade;
- $data['printType'] = 'mrv';
- // debug($printList);
- $this->render('mainly_revision',$data);
- }
- //月阶段复习设置
- public function actionSetting_mainly(){
- $data = array();
- $sql = "select setting_month_num from english_month_setting where type = 0";
- $result = $this->sConn->createCommand($sql)->queryRow();
- if($result){
- $data['chooseMonth'] = $result['setting_month_num'];
- }else{
- $data['chooseMonth'] = 1;
- }
- $data['printType'] = 'mrv_3';
- $this->render('setting_mainly',$data);
- }
- //月阶段复习设置
- public function actionAjaxSaveEnglishMonthMainly(){
- $result = array();
- $error = array();
- if (! Yii::app()->request->isAjaxRequest OR ! Yii::app()->request->isPostRequest){
- $error[] = '错误的来源!';
- }else{
- $week=(int)Req::post('week');
- if(!$week){
- $error[] = "请选择周几";
- }
- }
- if(!$error){
- $time = time();
- $sql = "select id from english_month_setting where type = 0";
- $data = $this->sConn->createCommand($sql)->queryRow();
- if($data){
- $insertStatus = $this->sConn->createCommand()->update("english_month_setting", array("setting_month_num" => $week,"create_time"=>$time),"type=0");
- }else{
- $insertStatus = $this->sConn->createCommand()->insert('english_month_setting',array(
- 'type' => 0,
- 'setting_month_num' => $week,
- 'create_time' => $time,
- ));
- }
- if(!$insertStatus){
- $error[] = '系统错误';
- }
- }
- if($error){
- echo json_encode(array('status'=>0,'error'=>$error));exit;
- }else{
- echo json_encode(array('status'=>1));exit;
- }
- }
- //下载英语月阶段复习
- public function actionGetEnglishFileMonth(){
- $monthId = (string)Req::get("monthId");
- $studentsIds = (string)Req::get("studentsIds");
- $params = array();
- if(!$monthId){
- echo json_encode(array("success" => 0, "message" => "缺少参数"));
- exit();
- }
- if(!$studentsIds){
- $studentsIds = array();
- $sql = "select student_id from english_month_student where month_id = '{$monthId}' and is_month_pdf = 1";
- $stuArr = $this->sConn->createCommand($sql)->queryAll();
- if($stuArr){
- foreach($stuArr as $k=>$v){
- $studentsIds[] = $v['student_id'];
- }
- }
- }else{
- $studentsIds = explode(',',$studentsIds);
- }
- if(!$studentsIds || empty($studentsIds)){
- echo json_encode(array("success" => 0, "message" => "无生成的学生"));
- exit();
- }
- $params['monthId'] = $monthId;
- $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
- if(!$apiUrl){
- echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
- exit();
- }
- $sql = "select class_id,grade,create_time,semester_id from english_month where month_id = '{$monthId}'";
- $msg = $this->sConn->createCommand($sql)->queryRow();
- $Sem=new SSemester();
- $code= $Sem->conn->createQuery()
- ->from('semester')
- ->where("semester_id = '".$msg['semester_id']."'")
- ->limit(1)
- ->query()
- ->read();
- $intarr=array(
- "schoolId"=>$this->schoolId,
- "clazzId"=>$msg['class_id'],
- "semester"=>$code['refer_code'],
- "grade"=>$msg['grade'],
- "students"=>$studentsIds,
- "examTime"=>$msg['create_time'],
- "classify"=>3,
- "subject"=>8
- );
- $schoolInfo = BusinessSchool::model()->find('school_id=:school_id', array(':school_id' => $this->schoolId));
- if(isset($schoolInfo['is_allow_download']) && ($schoolInfo['is_allow_download']==1)){
- if($studentsIds){
- $params["studentIds"] = $studentsIds;
- }
- }else{
- if(Yii::app()->params["limit_open"]){
- $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]);
- $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr),$basic));
- if(!$rs){
- Yii::app()->jump->error("接口错误");
- }
- if($rs->errCode!="00"){
- echo json_encode(array("success" => 0, "message" => $rs->errMsg));
- exit();
- }
- if(!empty($rs->data)){
- $params["studentIds"]=$rs->data;
- if(count($rs->data)<count($intarr['students'])){
- $limitinfo="购买过的".count($intarr['students'])-count($rs->data)."位学生可下载";
- }
- } else{
- echo json_encode(array("success" => 0, "message" =>"请先购买商品"));
- exit();
- }
- }else{
- if($studentsIds){
- $params["studentIds"] = $studentsIds;
- }
- }
- }
- $params['schoolId'] = $this->schoolId;
- $params['type'] = 2;
- $rs = Curl::post($apiUrl."/rest/download_week_pdf/index", $params);
- if(!($rs = json_decode($rs))){
- $rs = array(
- "success" => 0,
- "message" => "请求接口失败",
- );
- }else{
- //更新下载时间
- if($rs->success==1 || $rs->success==2){
- $time = time();
- if($studentsIds){
- $sql = "update english_month_student set is_download = 1,download_time={$time} where month_id = '{$monthId}' and student_id in (".implode(',',$studentsIds).")";
- $this->sConn->createCommand($sql)->execute();
- }
- }
- }
- // if(isset($rs->downloadPath)){
- // if (YII_ENV == 'pro' || YII_ENV == 'production') {
- // $rs->downloadPath = preg_replace('/http\:\/\/zstatic\d{1,2}/','http://zstatic'.$groupId,$rs->downloadPath);
- // }
- // }
- echo json_encode($rs);exit;
- }
- //月阶段复习选择学生
- public function actionSelectStuByMainly(){
- $data = array();
- $sname = (string)Req::get("sname"); //学生名字
- $monthId = (string)Req::get("monthId");
- if(!$monthId){
- Yii::app()->jump->error('参数错误!');
- }
- //获取班级名称以及周后推送名称
- $sql = "select em.name,c.class_name,em.grade,em.class_id,em.create_time,em.semester_id from english_month em join class c on em.class_id = c.class_id where em.month_id = '{$monthId}'";
- $names = $this->sConn->createCommand($sql)->queryRow();
- if(!$names){
- $names = array();
- $names['name'] = '';
- $names['class_name'] = '';
- $names['grade'] = 0;
- }else{
- $data['name'] = isset($names['name'])?$names['name']:'';
- }
- $sql = "select student_id,is_month_pdf from english_month_student where month_id = '{$monthId}'";
- $relateStudent = $this->sConn->createCommand($sql)->queryAll();
- $studentIds = array();
- $stuIsPdf = array();
- if($relateStudent){
- foreach ($relateStudent as $studentInfo) {
- $studentIds[] = (string)$studentInfo['student_id'];
- $stuIsPdf[(string)$studentInfo['student_id']] = $studentInfo['is_month_pdf'];
- }
- }
- if($studentIds){
- $studentNames = SStudentInfo::model()->getStudentNames($studentIds); //求学生名字
- if($studentNames){
- if($sname){
- $i = 1;
- foreach($studentNames as $k=>$v){
- if(strpos($v,$sname) !== false){
- $data['list'][$i]['stu_id'] = (string)$k;
- $data['list'][$i]['stu_name'] = $v;
- $data['list'][$i]['name'] = $names['class_name'].$v.$names['name'];
- $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$k])?$stuIsPdf[(string)$k]:0;
- $i++;
- }
- }
- }else{
- $i = 1;
- foreach($studentNames as $k=>$v){
- $data['list'][$i]['stu_id'] = (string)$k;
- $data['list'][$i]['stu_name'] = $v;
- $data['list'][$i]['name'] = $names['class_name'].$v.$names['name'];
- $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$k])?$stuIsPdf[(string)$k]:0;
- $i++;
- }
- }
- }
- }
- $Sem=new SSemester();
- $code= $Sem->conn->createQuery()
- ->from('semester')
- ->where("semester_id = '".$names['semester_id']."'")
- ->limit(1)
- ->query()
- ->read();
- $intarr=array(
- "schoolId"=>$this->schoolId,
- "clazzId"=>$names['class_id'],
- "semester"=>$code['refer_code'],
- "grade"=>$names['grade'],
- "students"=>$studentIds,
- "examTime"=>$names['create_time'],
- "classify"=>3,
- "subject"=>8
- );
- $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]);
- $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr),$basic));
- if(!$rs){
- Yii::app()->jump->error("接口错误");
- }
- if($rs->errCode!="00"){
- Yii::app()->jump->error($rs->errMsg);
- }
- if(!empty($rs->data)){
- $data['limitstu']=$rs->data;
- }
- $data['monthId'] = $monthId;
- $data['sname'] = $sname;
- $data['printType'] = 'mrv_stu';
- $this->render('mainly_stu',$data);
- }
- //生成模板
- public function actionAjaxCreateTemplate(){
- $eId = Req::post('exam_id');
- if(!$eId){
- exit(json_encode(array("status"=>0,"result"=>"考试ID不能为空")));
- }
- //调用java生成模板接口
- $password = md5($this->schoolId.Yii::app()->params['zsy_api_key']);
- $url = Yii::app()->params['zsy_api_url'].'/teacher/paper/math/generate-fixed-template/'.$eId;
- $rs = $this->CrmApiPost($url,array(),$this->schoolId,$password);
- //操作日志
- if(Yii::app()->params['handle_log_on_off'])
- {
- writeFileLog(jsonEncode(array(
- "exam_group_id" => '',
- "operate_project" => 'zsyas2',
- "title" => '一键生成',
- "school_id" => $this->schoolId,
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $url,
- "operate_sql" => '',
- "operate_param" =>json_encode(array('params'=>array('examId'=>$eId),'rs'=>$rs)),
- "date"=>date('Y-m-d H:i:j')
- )));
- }
- if(isset($rs->errCode) && $rs->errCode =='00')
- {
- echo json_encode(array('status'=>1,'result'=>$rs->errMsg));exit;
- }
- $errMsg = '生成失败';
- if(isset($rs->errMsg))
- {
- $errMsg = $rs->errMsg;
- }
- echo json_encode(array('status'=>0,'result'=>$errMsg));exit;
- }
- public function actionAjaxPrintPaper(){
- $exam_id = Req::post("exam_id");
- $student_id = Req::post("student_id");
- if(!$exam_id ) {
- echo json_encode(array("status"=>0,"result"=>"参数不能为空"));
- }
- if(empty($student_id) ) {
- echo json_encode(array("status"=>0,"result"=>"请至少选择一个学生"));
- }
- $studentIds = explode(',',$student_id);
- foreach ($studentIds as $v)
- {
- if($v)
- {
- $student_ids[] = $v;
- }
- }
- $password = md5($this->schoolId.Yii::app()->params['zsy_api_key']);
- $url = Yii::app()->params['zsy_api_url'].'/teacher/paper/math/download-fixed-template';
- $start = time();
- $rs = $this->CrmApiPost($url,array('examId'=>$exam_id,'students'=>$student_ids),$this->schoolId,$password);
- $endTime = time();
- //操作日志
- if(Yii::app()->params['handle_log_on_off'])
- {
- writeFileLog(jsonEncode(array(
- "exam_group_id" => '',
- "operate_project" => 'zsyas2',
- "title" => '批量打印',
- "school_id" => $this->schoolId,
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $url,
- "operate_sql" => '',
- "operate_param" =>json_encode(array('params'=>array('examId'=>$exam_id,'students'=>$student_ids,'time'=>($endTime-$start)),'rs'=>$rs)),
- "date"=>date('Y-m-d H:i:j')
- )));
- }
- if(isset($rs->errCode) && $rs->errCode =='00')
- {
- ClassExamPrinter::model()->updateAll(array('is_print'=>1),'exam_id=:exam_id',array(':exam_id'=>$exam_id));
- echo json_encode(array('status'=>1,'result'=>$rs->data));exit;
- }
- $errMsg = '下载失败';
- if(isset($rs->errMsg))
- {
- $errMsg = $rs->errMsg;
- }
- echo json_encode(array('status'=>0,'result'=>$errMsg));exit;
- }
- //打印试卷和第三方试卷添加班级
- public function actionAddExamClass()
- {
- $classId=Req::post('classId');
- $exam_group_id=Req::post('eid');
- $is_third = Req::post('is_third');
- $result['status']=0;
- if(!$exam_group_id || !$classId || !is_array($classId)){
- $result['msg']='数据异常';
- exit(json_encode($result));
- }
- //防止重复操作
- $redis_add_class_status = Yii::app()->add_exam_class->hmget('temp:exam_class_mark_'.$exam_group_id,array('status'));
- if($redis_add_class_status && $redis_add_class_status[0]){
- echo json_encode(array('status'=>0,'msg'=>'操作频繁,请稍后再试'));
- exit;
- }else{
- Yii::app()->add_exam_class->hmset('temp:exam_class_mark_'.$exam_group_id,array('status'=>1));
- Yii::app()->add_exam_class->expire('temp:exam_class_mark_'.$exam_group_id,30);
- }
- $examClass=array(); //原考试班级
- $neeAddClass=array(); //需要增加的班级
- $time=time();
- $allExamIds=array(); //所有考试id,用于判断考试订单
- //获取考试ID
- $criteria = new CDbCriteria();
- $criteria->select = 'exam_id,exam_group_id,class_id';
- $criteria->addCondition("exam_group_id='".$exam_group_id."'");
- $exam_data = Exam::model()->findAll($criteria);
- unset($criteria);
- if($exam_data)
- {
- foreach($exam_data as $v)
- {
- $exam_ids[] = $v->exam_id;
- $examClass[] = (string)$v->class_id;
- }
- foreach ($examClass as $key => $val){
- if(in_array((string)$val,$classId,true)){
- unset($classId[array_search((string)$val,$classId,true)]);
- }
- }
- if($classId){
- $neeAddClass= $classId;
- }
- $examDetail=$this->sConn->createCommand("select `name`,semester_id,subject_id,teacher_id,module_id,`type`,week_num,create_type,create_time,update_time,tpl_index,tpl_data,method_ids,from_exam_id,school_card_status,school_card_length,is_fine_paper,is_fine_edit from exam where exam_id='".$exam_ids[0]."' ")->queryRow();
- $papers = $this->sConn->createCommand("select paper_id from paper where exam_id IN (".implode(',',$exam_ids).")")->queryAll();
- $paperDetail=$this->sConn->createCommand("select paper_type,paper_layer,difficulty,topics_count,score,add_time,update_time,method_ids,is_labelled,status,labelled_type,send_labelled_time,finish_labelled_time from paper where paper_id = '".$papers[0]['paper_id']."'")->queryRow();
- $paperTopics=$this->schoolManager->getPaperTopicsRecords($papers[0]['paper_id']);
- $paperLargeTopics = $this->schoolManager->getPaperLargeTopicsRecords($papers[0]['paper_id']);
- //增加班级
- $needAddExamId=array();
- if($neeAddClass){
- $transaction = $this->sConn->beginTransaction();
- try {
- //单独阅卷 添加exam_group表数据
- $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- //FIXME 2019-10-23 单独阅卷&旧版阅卷 才添加marking_group记录
- if( $exam_group_data['mark_type'] == 4 && $exam_group_data['is_new_marking']==0) {
- $i = 1;
- foreach ($paperTopics as $paperTopic) {
- if (!in_array($paperTopic['type'], array(1, 2, 11))) {
- $marking_group_id =getUniqueId($this->schoolId);
- foreach ($neeAddClass as $classId) {
- $sql = "select marking_group_id from marking_group where exam_group_id = '{$exam_group_id}' AND class_id = {$classId} AND topic_id = {$paperTopic['topic_id']}";
- $data = $this->sConn->createCommand($sql)->queryRow();
- if (!$data) {
- $this->sConn->createCommand()->insert('marking_group', array(
- 'exam_group_id' => $exam_group_id,
- 'marking_group_id' => $marking_group_id,
- 'class_id' => $classId,
- 'topic_id' => $paperTopic['topic_id'],
- 'topic_type' => $paperTopic['type'],
- 'topic_index' => $i,
- 'topic_score' => $paperTopic['score']
- ));
- }
- }
- }
- $i++;
- }
- }
- $allStudentIds=array();
- $allTeacherIds=array();
- foreach ($neeAddClass as $classId) {
- $newExamId = getUniqueId($this->schoolId);
- $needAddExamId[]=$newExamId;
- $studentIdData = $this->sConn->createCommand("select student_id from student_class_relation where class_id='" . $classId . "' and status=0 ")->queryAll();
- $studentIds=array();
- if($studentIdData){
- foreach ($studentIdData as $datum){
- $studentIds[]=$datum['student_id'];
- }
- }
- //校验是否已存在重复学生
- if($studentIds){
- $checkRepeatStudent=$this->sConn->createCommand("select student_id from student_paper_relation where exam_id in(".implode(',',$exam_ids).") and student_id in(".implode(',',$studentIds).") and is_del=0")->queryRow();
- if($checkRepeatStudent){
- $checkStudentInfo=$this->sConn->createCommand("select realname from student_info where student_id ='{$checkRepeatStudent['student_id']}'")->queryRow();
- echo json_encode(array('status'=>0,'msg'=>$checkStudentInfo['realname'].'('.$checkStudentInfo['realname'].')已参加本场考试,请勿重复添加'));
- exit;
- }
- }
- $allStudentIds=array_merge($allStudentIds,$studentIds);
- //if(!$studentIds) continue;
- $studentIds_0 = BusinessStudent::model()->keepStudentsStatus_0($studentIds);
- $BStudentCards = BusinessStudent::model()->getCardsByStudentIds($studentIds_0);
- //添加考试
- $status=3;
- if($exam_group_data->homework==0 && $is_third==1){
- $status=2;
- }else{
- $status=3;
- }
- $this->sConn->createCommand()->insert('exam', array(
- 'exam_id' => $newExamId,
- 'exam_group_id' => $exam_group_id,
- 'name' => $examDetail['name'],
- 'subject_id' => $examDetail['subject_id'],
- 'semester_id' => $examDetail['semester_id'],
- 'teacher_id' => $examDetail['teacher_id'],
- 'module_id' => $examDetail['module_id'],
- 'type' => $examDetail['type'],
- 'status' => $status,
- 'week_num' => $examDetail['week_num'],
- 'create_type' => $examDetail['create_type'],
- 'create_time' => $examDetail['create_time'],
- 'update_time' => $examDetail['update_time'],
- 'tpl_index' => $examDetail['tpl_index'],
- 'tpl_data' => $examDetail['tpl_data'],
- 'class_id' => $classId,
- 'method_ids' => $examDetail['method_ids'],
- 'from_exam_id' => $examDetail['from_exam_id'],
- 'school_card_status' => isset($examDetail['school_card_status']) ? $examDetail['school_card_status'] : 0,
- 'school_card_length' => isset($examDetail['school_card_length']) ? $examDetail['school_card_length'] : 0,
- 'is_fine_paper' => $examDetail['is_fine_paper'],
- 'is_fine_edit' => $examDetail['is_fine_edit'],
- // 'is_third' =>$examDetail['is_third']
- ));
- //添加试卷
- $newPaperId = getUniqueId($this->schoolId);
- $this->sConn->createCommand()->insert('paper', array(
- 'paper_id' => $newPaperId,
- 'paper_type' => $paperDetail['paper_type'],
- 'exam_id' => $newExamId,
- 'paper_name' => "",
- 'paper_layer' => $paperDetail['paper_layer'],
- 'difficulty' => $paperDetail['difficulty'],
- 'topics_count' => $paperDetail['topics_count'],
- 'score' => $paperDetail['score'],
- 'add_time' => $paperDetail['add_time'],
- 'update_time' => $paperDetail['update_time'],
- 'method_ids' => $paperDetail['method_ids'],
- 'is_labelled' => $paperDetail['is_labelled'],
- 'labelled_type' => $paperDetail['labelled_type'],
- 'send_labelled_time' => $paperDetail['send_labelled_time'],
- 'finish_labelled_time' => $paperDetail['finish_labelled_time'],
- 'status' => $paperDetail['status']
- ));
- if ($studentIds_0) {
- foreach ($studentIds_0 as $studentId) {
- // $BStudentCards = BusinessStudent::model()->getCardsByStudentIds($studentIds);
- // if($studentIds){
- // foreach ($studentIds as $studentId) {
- $this->sConn->createCommand()->insert('student_paper_relation', array(
- 'student_id' => $studentId,
- 'paper_id' => $newPaperId,
- 'exam_id' => $newExamId,
- 'semester_id' => $this->semesterId,
- 'class_id' => $classId,
- 'student_card' => (isset($BStudentCards[0]) && isset($BStudentCards[0][$studentId]) ? $BStudentCards[0][$studentId] : 0),
- 'school_student_card' => (isset($BStudentCards[1]) && isset($BStudentCards[1][$studentId]) ? $BStudentCards[1][$studentId] : ''),
- ));
- $this->sConn->createCommand()->insert('student_paper_relation_property', array(
- 'student_id' => $studentId,
- 'paper_id' => $newPaperId,
- 'exam_id' => $newExamId,
- 'semester_id' => $this->semesterId,
- 'class_id' => $classId,
- 'create_time'=>time(),
- ));
- }
- }
- foreach ($paperTopics as $paperTopic) {
- $this->sConn->createCommand()->insert('paper_topic_relation', array(
- 'paper_id' => $newPaperId,
- 'stem_id' => $paperTopic['stem_id'],
- 'topic_id' => $paperTopic['topic_id'],
- 'no' => $paperTopic['order'],
- 'order' => $paperTopic['order'],
- 'mode' => (int)$paperTopic['mode'],
- 'type' => $paperTopic['type'],
- 'score' => $paperTopic['score'],
- 'question_count' => $paperTopic['question_count'],
- 'question_score_str' => $paperTopic['question_score_str'],
- 'method_ids' => $paperTopic['method_ids'],
- 'method_difficulty' => $paperTopic['method_difficulty'] ? $paperTopic['method_difficulty'] : 2,
- 'template_id' => $paperTopic['template_id'],
- 'is_template' => $paperTopic['is_template'],
- 'is_delete' => $paperTopic['is_delete'],
- 'topic_from' => $paperTopic['topic_from'],
- 'logic_type'=>$paperTopic['logic_type'],
- ));
- $this->sConn->createCommand()->insert('topic_use', array(
- 'topic_id' => $paperTopic['topic_id'],
- 'mode' => $paperTopic['mode'],
- 'teacher_id' => $examDetail['teacher_id'],
- ));
- }
- foreach ($paperLargeTopics as $paperLargeTopic){
- $this->sConn->createCommand()->insert('paper_topic_large', array(
- 'paper_id' => $newPaperId,
- 'large_topic_id' => $paperLargeTopic['large_topic_id'],
- 'topic_no' => $paperLargeTopic['topic_no'],
- 'logic_type' => $paperLargeTopic['logic_type'],
- 'logic_type_second' => $paperLargeTopic['logic_type_second'],
- 'method_ids' => $paperLargeTopic['method_ids'],
- ));
- }
- $this->sConn->createCommand()->insert('class_exam_printer', array(
- 'class_id' => $classId,
- 'exam_id' => $newExamId,
- 'type' => 0,
- 'is_print' => 0,
- 'print_time' => 0,
- 'add_time' => $time,
- ));
- }
- if($exam_group_data['homework']==1){
- $tplData=json_decode($examDetail['tpl_data'],1);
- $teachers=$this->schoolManager->getTeachersByClassesIds($neeAddClass);
- $allStudentIds=array_values($allStudentIds);
- $studentReceiverList=array();
- foreach ($allStudentIds as $val){
- $studentReceiverList[(string)$val]=$val;
- }
- $studentReceiverList=array_values($studentReceiverList);
- $studentNotice[]=array(
- 'app'=>0,
- 'templateId'=>2,
- 'templateParams'=>array($examDetail['name']),
- 'userIds'=>$studentReceiverList
- );
- if(isset($tplData['startline'])){
- $studentNotice['dateTime']=date('Y-m-d H:i:s',strtotime($tplData['startline']));
- }
- foreach ($teachers as $val){
- if(!isset($receiverList[(string)$val['teacher_id']])){
- $receiverList[(string)$val['teacher_id']]=$val['teacher_id'];
- }
- }
- $receiverList=array_values($receiverList);
- $teacherNotice=array(
- 'app'=>1,
- 'templateId'=>1,
- 'templateParams'=>array($examDetail['name']),
- 'userIds'=>$receiverList
- );
- sendDataToKafka('send_message_center',$studentNotice);
- sendDataToKafka('send_message_center',$teacherNotice);
- sendAppNotify($studentNotice);
- sendAppNotify($teacherNotice);
- }
- //数学标注
- $updateLabelledRs='';
- $orderType=array();
- if($exam_group_data['qxk_paper_id']>0 && in_array($examDetail['subject_id'],$this->mathSubjectId) && ($exam_group_data['is_tagging']>0 || $paperDetail['labelled_type']>0)){
- //需要重新查询订单
- $allExamIds=array_merge($exam_ids,$needAddExamId);
- $orderType = $this->checkProductOrderDetail($exam_group_id, $examDetail['subject_id'], array(31, 1, 2, 3,66),$allExamIds);
- if($orderType==-1){
- $error['msg'] = '订单接口异常';
- $error['status']=0;
- echo json_encode($error);exit();
- }elseif($orderType==-2){
- $error['msg'] = '考试参数异常,检查班级中是否添加学生';
- $error['status']=0;
- echo json_encode($error);exit();
- }
- if($orderType){
- $updateLabelledRs = Curl::post(Yii::app()->params['get_api_url'].'/rest/task_exam/update_task_data', array(
- "examGroupId" => (string)$exam_group_id,
- 'productOrderType'=>$orderType
- ));
- $updateLabelledData=json_decode($updateLabelledRs,true);
- if($updateLabelledData['success']==1){
- //判断标注完成状态是否需要更新
- if($exam_group_data['is_tagging']==1 || $paperDetail['is_labelled']==1){
- $needUpdateIsTagging=0;
- $needUpdateLabelled=0;
- foreach ($orderType as $item){
- if($item['goodsTypeId']==31){
- $needUpdateIsTagging=1;
- }
- if(in_array($item['goodsTypeId'],array(1,2,3,66))){
- $needUpdateLabelled=1;
- }
- }
- if($needUpdateIsTagging && $exam_group_data['is_tagging']!=1){
- $this->sConn->createCommand("update exam_group set is_tagging=1 where exam_group_id='{$exam_group_id}'")->execute();
- }
- if($needUpdateLabelled && $paperDetail['is_labelled']!=1){
- $this->sConn->createCommand("update paper set is_labelled=1 where exam_id in(".implode(',',$allExamIds).")")->execute();
- }
- }
- }
- }
- }
- //操作日志
- if(Yii::app()->params['handle_log_on_off'])
- {
- writeFileLog(jsonEncode(array(
- "exam_group_id" => (string)$exam_group_id,
- "operate_project" => 'zsyas2',
- "title" => '添加删除班级',
- "school_id" => $this->schoolId,
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $this->getRoute(),
- "operate_sql" => '',
- "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
- "date"=>date('Y-m-d H:i:s'),
- "update_label_rs"=>$updateLabelledRs,
- 'order_type'=>$orderType
- )));
- }
- $transaction->commit();
- }catch (Exception $e){
- $transaction->rollBack();
- exit(json_encode(array('status'=>0,'msg'=>'保存失败')));
- }
- }
- //发送学生端消息
- if($needAddExamId ){
- $sendJsonArr=array(
- 'school_id'=>$this->schoolId,
- 'send_type'=>'zsyas',
- 'update_type'=>3,
- 'exam_group_id'=>$exam_group_id,
- 'exam_id_arr'=>$needAddExamId
- );
- sendStudentCacheQueue($sendJsonArr);
- }
- exit(json_encode(array('status'=>1,'msg'=>'设置成功')));
- }else{
- $result['msg']='考试数据异常';
- exit(json_encode($result));
- }
- }
- public function actionSendExamStomp(){
- $exam_group_id=Req::post('examGroupId');
- $exam_id=Req::post('examId');
- $result['status']=0;
- if(!$exam_group_id || !$exam_id){
- $result['msg']='考试数据异常';
- exit(json_encode($result));
- }
- $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id));
- if($exam_data['subject_id']==8){
- $stomp_data = array('schoolId'=>$this->schoolId,'examGroupId'=>$exam_group_id,'examIds'=>array($exam_id));
- $rs=$this->sendStomp($stomp_data);
- if($rs){
- $sendMsg=array(
- 'school_id'=>$this->schoolId,
- 'msg_type'=>3,
- 'subject_id'=>$exam_data['subject_id'],
- 'send_type'=>'exam',
- 'exam_group_id'=>$exam_group_id,
- 'exam_ids'=>array($exam_id)
- );
- sendDataToKafka('xbkc-php-product-html',$sendMsg);
- $result['status']=1;
- $result['msg']='发送成功';
- }
- }else{
- $sendMsg=array(
- 'school_id'=>$this->schoolId,
- 'msg_type'=>3,
- 'subject_id'=>$exam_data['subject_id'],
- 'send_type'=>'exam',
- 'exam_group_id'=>$exam_group_id,
- 'exam_ids'=>array($exam_id)
- );
- sendDataToKafka('xbkc-php-product-html',$sendMsg);
- $result['status']=1;
- $result['msg']='发送成功';
- }
- exit(json_encode($result));
- }
- public function actionSendExamStompHomework(){
- $exam_group_id=Req::post('examGroupId');
- $exam_id=Req::post('examId');
- $result['status']=0;
- if(!$exam_group_id || !$exam_id){
- $result['msg']='考试数据异常';
- exit(json_encode($result));
- }
- //发送学生端消息
- $sendJsonArr=array(
- 'school_id'=>$this->schoolId,
- 'send_type'=>'zsyas',
- 'update_type'=>5,
- 'exam_group_id'=>$exam_group_id,
- 'exam_id_arr'=>array($exam_id),
- );
- sendStudentCacheQueue($sendJsonArr);
- $result['status']=1;
- exit(json_encode($result));
- }
- /**
- * 发送消息队列
- * @return mixed
- */
- private function sendStomp($data = array())
- {
- if ($data) {
- $conf = new RdKafka\Conf();
- $conf->set('metadata.broker.list', Yii::app()->params['kafka']);
- $producer = new RdKafka\Producer($conf);
- $topic = $producer->newTopic("zsyte-marking-finished-notify");
- $topic->produce(RD_KAFKA_PARTITION_UA, 0, json_encode($data));
- $producer->poll(0);
- $result = $producer->flush(10000);
- if($result===0){
- return true;
- }
- }
- return true;
- }
- //在线答题卡,试卷结构
- public function actionGetPaperWithTopicsDetails(){
- $examGroupId = Req::post("examGroupId");
- $multiplexId = Req::post("multiplexId");
- if(!$examGroupId){
- exit(json_encode(array('success'=>0,'message'=>'参数错误')));
- }
- $findInfo = SExamGroup::model()->find('exam_group_id=:eg_id',array('eg_id'=>$examGroupId));
- $exam_data = $this->schoolManager->getExamsByExamGroupId($examGroupId);
- $cardStatus=-1;
- $examIds = array();
- $tplIndex=0;
- if($exam_data) {
- foreach ($exam_data as $val) {
- $examIds[] = $val['exam_id'];
- if(!$tplIndex){
- $tplIndex=$val['tpl_index'];
- }
- if($cardStatus==-1){
- $cardStatus=$val['school_card_status'];
- }
- }
- }else{
- exit(json_encode(array('success'=>0,'message'=>'考试读取失败')));
- }
- $paperData = $this->schoolManager->getPaperWithTopicsDetails_v2($examGroupId);
- if(!$paperData){
- exit(json_encode(array('success'=>0,'message'=>'试卷结构读取失败')));
- }
- $paperData=json_decode($paperData,true);
- $paperData['success']=1;
- if(in_array($tplIndex, Yii::app()->params['custom_tpls_ids'])){
- //自定义模板
- $isCustomTpl = true;
- }else{
- //非自定义模板
- $isCustomTpl = false;
- }
- if (in_array($tplIndex, Yii::app()->params['no_template_id']) || $isCustomTpl) {
- //题卡分离
- $paperData['paperTplType'] = 2;
- }else{
- $paperData['paperTplType'] = 1;
- }
- if(in_array($tplIndex,Yii::app()->params['merge_topic_tpl']))
- {
- $paperData['paperTplType']= 1;
- if($tplIndex == 9 )
- {
- $paperData['paperTplType'] = 2;
- }
- }
- if(in_array($tplIndex,Yii::app()->params['merge_topic_tpl_all']))
- {
- $paperData['paperTplType'] = 1;
- if($tplIndex == 9 )
- {
- $paperData['paperTplType'] = 2;
- }
- }
- //英语题卡分离一
- if($this->subjectId == 8){
- $paperData['paperTplType'] = 2;
- }
- //读取打印班级状态
- $countPrint=$this->sConn->createCommand("select count(*) as count from class_exam_printer where is_print_online=1 and exam_id in(".implode(',',$examIds).")")->queryRow();
- if($countPrint && $countPrint['count']>0){
- $paperData['printClassStatus']=1;
- }else{
- $paperData['printClassStatus']=0;
- }
- $thirdAnswerSheet=$this->sConn->createCommand("select `name`,`position`,online_card_pdf,file_path,select_info,multiplex_id,`is_qrcode_online`,`create_time`,`update_time` from third_answer_sheet where exam_group_id='".$examGroupId."'")->queryRow();
- if($thirdAnswerSheet){
- $paperData['position']='';
- //判断是否有复用答题卡记录
- if(!$thirdAnswerSheet['multiplex_id']){
- //旧数据没有复用记录,需要补一条记录
- $onlineCardMultiModel=new SOnlineCardMultiplex();
- $onlineCardMultiModel->exam_group_id=$examGroupId;
- $onlineCardMultiModel->name=$thirdAnswerSheet['name'];
- $onlineCardMultiModel->file_path=$thirdAnswerSheet['file_path'];
- $onlineCardMultiModel->position=$thirdAnswerSheet['position'];
- $onlineCardMultiModel->online_card_pdf=$thirdAnswerSheet['online_card_pdf'];
- $onlineCardMultiModel->is_qrcode_online=$thirdAnswerSheet['is_qrcode_online'];
- $onlineCardMultiModel->is_download=0;
- $onlineCardMultiModel->is_copy=0;
- $onlineCardMultiModel->create_time=$thirdAnswerSheet['create_time'];
- $onlineCardMultiModel->update_time=$thirdAnswerSheet['update_time'];
- if($onlineCardMultiModel->save()){
- $nowMultiplexId=$onlineCardMultiModel->multiplex_id;
- $this->sConn->createCommand("update third_answer_sheet set multiplex_id='{$nowMultiplexId}' where exam_group_id='{$examGroupId}'")->execute();
- }
- }
- if($multiplexId){
- $multi=$this->sConn->createCommand("select multiplex_id,exam_group_id,`name`,file_path,`position`,online_card_pdf,is_qrcode_online,is_download,is_copy,update_time from online_card_multiplex where multiplex_id='{$multiplexId}'")->queryRow();
- if($multi){
- if($multi['position']){
- if(strpos($multi['position'],'http://')!==false || strpos($multi['position'],'https://')!==false){
- $multi['position']=fileGetContents($multi['position']);
- }
- $paperData['position']=$multi['position'];
- }
- }
- }elseif($thirdAnswerSheet['position']){
- if(strpos($thirdAnswerSheet['position'],'http://')!==false || strpos($thirdAnswerSheet['position'],'https://')!==false){
- $paperData['position']=fileGetContents($thirdAnswerSheet['position']);
- }else{
- $paperData['position']=$thirdAnswerSheet['position'];
- }
- }
- $paperData['online_card_pdf']=$thirdAnswerSheet['online_card_pdf'];
- $paperData['file_path']=$thirdAnswerSheet['file_path'];
- $paperData['stem_info']=$thirdAnswerSheet['select_info'];
- }else{
- $paperData['position']='';
- $paperData['online_card_pdf']='';
- $paperData['file_path']='';
- $paperData['stem_info']='';
- }
- $paperData['card_status']=$cardStatus;
- $paperData['examStatus']=$findInfo->status;
- exit(json_encode($paperData));
- }
- //保存在线答题卡
- public function actionSaveCardOnline(){
- $examGroupId = Req::post("examGroupId");
- $multiplexId = isset($_POST['multiplexId'])?$_POST['multiplexId']:''; //复用模板id
- $text = trim(Req::post("timu"));
- $name = Req::post("title");
- $sheet_answer = isset($_POST['sheet_answer'])?$_POST['sheet_answer']:'';
- $sheet_score = isset($_POST['sheet_score'])?$_POST['sheet_score']:'';
- $post = json_decode($text,true);
- $KeGuanTi = isset($post["KeGuanTi"])?$post["KeGuanTi"]:0;
- $TianKongTi = isset($post["TianKongTi"])?$post["TianKongTi"]:0;
- $ZhuGuanTi = isset($post["ZhuGuanTi"])?$post["ZhuGuanTi"]:0;
- $XuanZuoTi = isset($post["XuanZuoTi"])?$post["XuanZuoTi"]:0;
- $pdfUrl =isset($_POST["pdf_url"])?$_POST["pdf_url"]:0;
- $positionJson=isset($_POST['position'])?$_POST['position']:'';
- $useQrCode=isset($_POST['useQrCode'])?$_POST['useQrCode']:0;
- $stemInfo=isset($_POST['stemInfo'])?$_POST['stemInfo']:0;
- $error['success']=0;
- if(!$examGroupId){
- $error['message'] = '考试id不能为空';
- echo json_encode($error);exit();
- }
- if(!$text || !$name || !$sheet_answer || !$sheet_score){
- $error['message'] = '题目参数错误';
- echo json_encode($error);exit();
- }
- if(!$positionJson){
- $error['message'] = '定位信息异常';
- echo json_encode($error);exit();
- }
- $time=time();
- $exam_data = $this->schoolManager->getExamsByExamGroupId($examGroupId);
- if($exam_data){
- // $tpl_data = json_decode($exam_data[0]['tpl_data'],1);
- //验证是否已下载,是否是复用的答题卡
- if($multiplexId){
- $checkMulti=$this->sConn->createCommand("select is_download,is_copy from online_card_multiplex where multiplex_id = '{$multiplexId}' ")->queryRow();
- if($checkMulti['is_download']){
- $error['success']=0;
- $error['message'] = '上传失败,答题卡已经下载!';
- echo json_encode($error);exit();
- }
- if($checkMulti['is_copy']){
- //只保存文件信息
- $this->saveMultiplex();
- }
- }
- $examIds=array();
- foreach ($exam_data as $val){
- $examIds[]=$val['exam_id'];
- }
- $card_file=array();
- $card_pdf='';
- // if (empty($_FILES)) {
- // $error['message'] = '未找到上传文件!';
- // echo json_encode($error);exit();
- // }else{
- // debug($_FILES);
- if($_FILES){
- foreach($_FILES as $k=>$v){
- if(isset($v) && !empty($v)){
- if(!isset($v['size']) || $v['size'] >= 8388608){
- $error['message'] = '文件超过8M!';
- echo json_encode($error);exit();
- }
- $ext=substr($v['name'],strrpos($v['name'],'.')+1);
- if(!isset($v['name']) || !in_array($ext,array('doc','docx','pdf','bmp','jpg','jpeg','png','txt'))){
- $error['message'] = '文件格式不正确!';
- echo json_encode($error);exit();
- }
- if($ext=='pdf'){
- $card_pdf="upload/ThirdSheet/" .$examGroupId.'_'.$time.'.pdf' ;
- if(!move_uploaded_file($v["tmp_name"], $card_pdf)){
- $error['message'] = '保存Pdf文件失败!';
- echo json_encode($error);exit();
- }
- }else{
- $card_file[] = $v;
- }
- }
- }
- }
- $fixName = 'upload/tmpDir/ThirdSheet/'. date('Y') .'/'. date('m') .'/'.date('j').'/';
- $ucloudZipUrl='';
- $ucloudPdfUrl='';
- $ucloudTxtUrl='';
- if (!file_exists($fixName)) {
- mkdir($fixName, 0777, true);
- }
- $zipFileName=$examGroupId.'_'.$time.'.zip';
- $pathName=$fixName.$zipFileName;
- $zip = new ZipArchive;
- $zip->open($pathName, ZipArchive::CREATE);
- foreach($card_file as $k=>$v){
- $zip->addFile($v['tmp_name'], iconv('utf-8', 'gbk//ignore', $v['name']));
- }
- $zip->addFromString('json.txt', $positionJson);
- $zip->close();
- //FIXME 20191204
- $ucloud = new HuaweiCloud();
- //上传压缩包
- $rename = 'zsyas2/cardonline/'.$this->schoolId.'/'. date('Y') . '/' . date('m') . '/' . date('d').'/'. $zipFileName;
- $uploadInfo = $ucloud->putFile($rename, $pathName);
- @unlink($pathName);
- if ($uploadInfo['status'] == 0) {
- $error['success']=0;
- $error['message'] = '答题卡文件上传失败! ';
- echo json_encode($uploadInfo);exit();
- }else{
- $ucloudZipUrl=$uploadInfo['url'];
- }
- //单独上传position.txt
- if($positionJson){
- $positionTxt="upload/ThirdSheet/" .$examGroupId.'_'.$time.'.txt' ;
- file_put_contents($positionTxt, $positionJson);
- $uploadTxtName = 'zsyas2/cardonline/'.$this->schoolId.'/'. date('Y') . '/' . date('m') . '/' . date('d').'/' .$time.'.txt' ;
- $uploadInfo = $ucloud->putFile($uploadTxtName,$positionTxt);
- if ($uploadInfo['status'] == 0) {
- @unlink($positionTxt);
- $error['success']=0;
- $error['message'] = 'Position文件上传失败!';
- echo json_encode($error);exit();
- }else{
- @unlink($positionTxt);
- $uploadInfo['url'] = str_replace("%2F","/",$uploadInfo['url']);
- $ucloudTxtUrl=$uploadInfo['url'];
- }
- }
- //上传Pdf
- if($pdfUrl){
- $ucloudPdfUrl=$pdfUrl;
- // $card_pdf="upload/ThirdSheet/" .$examGroupId.'.pdf' ;
- // $content = file_get_contents($pdfUrl);
- //
- // file_put_contents($card_pdf, $content);
- //
- // $uploadPdfName = 'zsyas2/cardonline/'.$this->schoolId.'/'. date('Y') . '/' . date('m') . '/' . date('d').'/' .time().'.pdf' ;
- // $uploadInfo = $ucloud->putFile($uploadPdfName,$card_pdf);
- //
- // if ($uploadInfo['status'] == 0) {
- // @unlink($card_pdf);
- // $error['success']=0;
- // $error['message'] = '答题卡PDF文件上传失败!';
- // echo json_encode($error);exit();
- // }else{
- // @unlink($card_pdf);
- // $uploadInfo['url'] = str_replace("%2F","/",$uploadInfo['url']);
- // $ucloudPdfUrl=$uploadInfo['url'];
- // }
- }
- if(!$multiplexId){
- //没有复用记录,初始化一条记录
- $insertSql="insert into online_card_multiplex(`exam_group_id`,`name`,`file_path`,`position`,`online_card_pdf`,`create_time`,`update_time`,`is_qrcode_online`) values";
- $insertSql.="('".$examGroupId."','".$name."','".$ucloudZipUrl."','".$ucloudTxtUrl."','".$ucloudPdfUrl."','".time()."','".time()."','".$useQrCode."')";
- $this->sConn->createCommand($insertSql)->execute();
- $last_insert_id = $this->sConn->createCommand("select last_insert_id()")->queryRow();
- $multiplexId=$last_insert_id['last_insert_id()'];
- }else{
- //更新复用记录
- $updateSql="update online_card_multiplex set `file_path`='{$ucloudZipUrl}',`position`='{$ucloudTxtUrl}',`online_card_pdf`='{$ucloudPdfUrl}',update_time='".time()."',is_qrcode_online='".$useQrCode."' where multiplex_id='{$multiplexId}'";
- $this->sConn->createCommand($updateSql)->execute();
- }
- $thirdAnswerSheet=$this->sConn->createCommand("select sheet_id from third_answer_sheet where exam_group_id='".$examGroupId."'")->queryRow();
- if(!$thirdAnswerSheet){
- $ThirdAnswerSheetModel=new SThirdAnswerSheet();
- $ThirdAnswerSheetModel->name=$name;
- $ThirdAnswerSheetModel->exam_group_id=$examGroupId;
- $ThirdAnswerSheetModel->ke_topic_num=$KeGuanTi;
- $ThirdAnswerSheetModel->tian_topic_num=$TianKongTi;
- $ThirdAnswerSheetModel->zu_topic_num=$ZhuGuanTi;
- $ThirdAnswerSheetModel->xuan_topic_num=$XuanZuoTi;
- $ThirdAnswerSheetModel->file_path=$ucloudZipUrl;
- $ThirdAnswerSheetModel->sheet_answer=$sheet_answer;
- $ThirdAnswerSheetModel->sheet_score=$sheet_score;
- $ThirdAnswerSheetModel->create_time=$time;
- $ThirdAnswerSheetModel->update_time=$time;
- $ThirdAnswerSheetModel->position=$ucloudTxtUrl;
- $ThirdAnswerSheetModel->online_card=1;
- $ThirdAnswerSheetModel->online_card_pdf=$ucloudPdfUrl;
- $ThirdAnswerSheetModel->is_qrcode_online=$useQrCode;
- $ThirdAnswerSheetModel->multiplex_id=$multiplexId;
- $rs=$ThirdAnswerSheetModel->save();
- // $insert="insert into third_answer_sheet(`name`,`exam_group_id`,`ke_topic_num`,`tian_topic_num`,`zu_topic_num`,`xuan_topic_num`,`file_path`,`sheet_answer`,`sheet_score`,`create_time`,`update_time`,`position`,`online_card`,`online_card_pdf`,`is_qrcode_online`) ";
- // $insert.=" values('".$name."','".$examGroupId."','".$KeGuanTi."','".$TianKongTi."','".$ZhuGuanTi."','".$XuanZuoTi."','".$ucloudZipUrl."','".$sheet_answer."','".$sheet_score."','".time()."','".time()."','".$positionJson."',1,'".$ucloudPdfUrl."','".$useQrCode."') ";
- // $rs= $this->sConn->createCommand($insert)->execute();
- }else{
- //更新打印状态
- $this->sConn->createCommand("update class_exam_printer set is_print_online=0 where exam_id in(".implode(',',$examIds).")")->execute();
- $updateArr=array(
- 'file_path'=>$ucloudZipUrl,
- 'sheet_answer'=>$sheet_answer,
- 'sheet_score'=>$sheet_score,
- 'ke_topic_num'=>$KeGuanTi,
- 'tian_topic_num'=>$TianKongTi,
- 'zu_topic_num'=>$ZhuGuanTi,
- 'xuan_topic_num'=>$XuanZuoTi,
- 'update_time'=>$time,
- 'position'=>$ucloudTxtUrl,
- 'online_card'=>1,
- 'online_card_pdf'=>$ucloudPdfUrl,
- 'is_qrcode_online'=>$useQrCode,
- 'multiplex_id'=>$multiplexId
- );
- $rs= SThirdAnswerSheet::model()->updateAll($updateArr,"exam_group_id ='{$examGroupId}'");
- // $rs=$this->sConn->createCommand("update third_answer_sheet set `file_path` = '".$ucloudZipUrl."',sheet_answer='".$sheet_answer."',sheet_score='".$sheet_score."',ke_topic_num=".$KeGuanTi.",tian_topic_num=".$TianKongTi.",zu_topic_num=".$ZhuGuanTi.",xuan_topic_num=".$XuanZuoTi.",update_time=".time().",position='".$positionJson."',online_card=1,online_card_pdf='".$ucloudPdfUrl."',is_qrcode_online='".$useQrCode."' where exam_group_id = '{$examGroupId}' ")->execute();
- }
- if($rs){
- $OnlineCardSaveLogModel=new SOnlineCardSaveLog();
- $OnlineCardSaveLogModel->exam_group_id=$examGroupId;
- $OnlineCardSaveLogModel->file_path=$ucloudZipUrl;
- $OnlineCardSaveLogModel->online_card_pdf=$ucloudPdfUrl;
- $OnlineCardSaveLogModel->position=$ucloudTxtUrl;
- $OnlineCardSaveLogModel->create_time=$time;
- $OnlineCardSaveLogModel->save();
- $error['success']=1;
- $error['message'] = '保存成功!';
- $error['data'] = $ucloudPdfUrl;
- $error['multiplex_id']=$multiplexId;
- echo json_encode($error);exit();
- }
- // }
- }else{
- $error['message'] = '考试不存在'.$examGroupId;
- echo json_encode($error);exit();
- }
- echo json_encode($error);exit();
- }
- //判断在线答题卡
- public function actionGetOnlineCard(){
- $exam_group_id = Req::post("exam_group_id");
- if($exam_group_id)
- {
- $third_answer_data = SThirdAnswerSheet::model()->find('exam_group_id=:exam_group_id and online_card=1',array(':exam_group_id'=>$exam_group_id));
- if(!$third_answer_data)
- {
- echo json_encode(array('status'=>-1));exit;
- }
- $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- if($exam_group_data)
- {
- $sheetAnswer=json_decode($third_answer_data['sheet_answer'],true);
- //
- $exam=Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- $tplData=json_decode($exam['tpl_data'],true);
- //update_answer new_rules
- $updateAnswer=array();
- $newRules=array();
- if(isset($tplData['update_answer'])){
- $updateAnswer=$tplData['update_answer'];
- }
- if(isset($tplData['new_rules'])){
- $newRules=$tplData['new_rules'];
- }
- $paper=SPaper::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam['exam_id']));
- $paperTopic=SPaperTopicRelation::model()->findAll('paper_id=:paper_id and type in(1,2,11)',array(':paper_id'=>$paper['paper_id']));
- foreach ($paperTopic as $item){
- if((!isset($sheetAnswer[$item['order']]) || !$sheetAnswer[$item['order']]) && !isset($updateAnswer[$item['order']]) && (!isset($newRules[$item['order']]) || !$newRules[$item['order']]['rule_answer'] )){
- echo json_encode(array('status'=>-2));exit;
- }
- }
- echo json_encode(array('status'=>1,'qxk_paper_id'=>$exam_group_data['qxk_paper_id']));exit;
- }
- }
- echo json_encode(array('status'=>0));exit;
- }
- private function mkdir($path, $chmod = 0755){
- return is_dir($path) || (self::mkdir(dirname($path), $chmod) && mkdir($path, $chmod));
- }
- /**
- * 下载pdf
- */
- public function actionDownOnlinePdf()
- {
- $examGroupId = safe_replace(Yii::app()->request->getQuery('exam_group_id'));
- if (!$examGroupId) {
- Yii::app()->jump->error('请指定考试');
- }
- $third_answer_data = SThirdAnswerSheet::model()->find('exam_group_id=:exam_group_id and online_card=1', array(':exam_group_id' => $examGroupId));
- if (!$third_answer_data) {
- echo json_encode(array('status' => -1));
- exit;
- }
- $exam_data = $this->schoolManager->getExamsByExamGroupId($examGroupId);
- $examIds = array();
- if($exam_data) {
- foreach ($exam_data as $val) {
- $examIds[] = $val['exam_id'];
- }
- }
- if(!$examIds)
- {
- echo json_encode(array('status'=>-1));exit;
- }
- if ($third_answer_data->online_card_pdf) {
- ClassExamPrinter::model()->updateAll(array('is_print_online'=>1),' exam_id in('.implode(',',$examIds).')');
- $url=$third_answer_data->online_card_pdf;
- // 获取远程文件大小
- // 注意filesize()无法获取远程文件大小
- $headers = get_headers($url, 1);
- $fileSize = $headers['Content-Length'];
- //echo $fileSize;exit;
- // 设置header头
- // 因为不知道文件是什么类型的,告诉浏览器输出的是字节流
- header('Content-Type: application/pdf');
- // 告诉浏览器返回的文件大小类型是字节
- header('Accept-Ranges:bytes');
- // 告诉浏览器返回的文件大小
- header('Content-Length: ' . $fileSize);
- // 告诉浏览器文件作为附件处理并且设定最终下载完成的文件名称
- Header("Content-Disposition: attachment; filename=" . $third_answer_data->online_card_pdf); // 输出文件内容
- //针对大文件,规定每次读取文件的字节数为4096字节,直接输出数据
- ob_clean();
- $read_buffer = 1024 * 1024;
- $handle = fopen($url, 'rb');
- //总的缓冲的字节数
- $sum_buffer = 0;
- //只要没到文件尾,就一直读取
- while (!feof($handle)) {
- echo fread($handle, $read_buffer);
- ob_flush();
- }
- fclose($handle);
- } else {
- Yii::app()->jump->error('考试不存在或尚未生成PDF');
- }
- }
- /**
- * html转pdf
- */
- public function actionHtmlToPdf(){
- $examGroupId = Req::post("examGroupId");
- $pdfHtml = htmlspecialchars_decode(Req::post("pdfHtml"));
- // $pageSize = Req::post("pageSize");
- // $orientation = (int)Req::post("orientation");//1-横向 2-纵向;
- $widthm = Req::post("widthm");
- $heightm = Req::post("heightm");
- $error['success']=0;
- if(!$examGroupId){
- $error['message'] = '考试id不能为空';
- echo json_encode($error);exit();
- }
- if(!$pdfHtml){
- $error['message'] = 'html信息错误';
- echo json_encode($error);exit();
- }
- // if(!$pageSize){
- // $error['message'] = '请指定纸张大小';
- // echo json_encode($error);exit();
- // }
- // if(!$orientation){
- // $error['message'] = '请指定纸张方向';
- // echo json_encode($error);exit();
- // }else{
- // if($orientation == 1){
- // $orientation = 'landscape';
- // }else{
- // $orientation = 'portrait';
- // }
- // }
- if(!$widthm){
- $error['message'] = '请设置宽度';
- echo json_encode($error);exit();
- }
- if(!$heightm){
- $error['message'] = '请设置高度';
- echo json_encode($error);exit();
- }
- $htmlpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/online_answer/'; //存放生成的HTML路径
- $pdfpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/online_answer/' . $this->schoolId . "/"; //存放生成的PDF路径
- $pdfurl = '/upload/tmpDir/online_answer/' . $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.=$examGroupId . "-online_answer.html";
- $f = fopen($htmlpath, "w");
- fwrite($f, $pdfHtml);
- fclose($f);
- $htmlurl = '/upload/tmpDir/online_answer/' . $examGroupId . "-online_answer.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."-".$examId.".pdf";
- $pdfpath = $pdfpath . $pdffname;
- $pdfurl = $pdfurl . $pdffname;
- $commond = Yii::app()->params['phantomjs'] . " "
- . Yii::app()->params['html2pdf'] . " "
- . " file://" . $htmlpath
- . " {$pdfpath}"
- . " 176mm*250mm ''";
- } else {
- $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=$examGroupId."-online_answer.pdf";
- $pdfpath = $pdfpath . $pdffname;
- $pdfurl = $pdfurl . $pdffname;
- $commond = Yii::app()->params['phantomjs_server'] . " "
- . Yii::app()->basePath . '/../js/html2pdf_answer.js' . " "
- . " {$htmlurl}"
- . " {$pdfpath}"
- . " {$widthm}*{$heightm} ''";
- }
- exec($commond, $res, $code);
- // debug($res);
- if(isset($res[0])){
- if (strpos($res[0], 'succeed') !== false) {//命令返回成功
- if ($this->file_exists($pdfpath)) {
- $repdf = $examGroupId.".pdf";
- $rename = 'zsyas2/online_answer/'.$this->schoolId.'/'. date('Y') . '/' . date('m') . '/' . date('d').'/'. uniqid() . '.' . $repdf;
- $ucloud = new HuaweiCloud();
- $uploadInfo = $ucloud->putFile($rename, $pdfpath);
- @unlink($pdfpath);
- @unlink($htmlpath);
- if ($uploadInfo['status'] == 0) {
- echo json_encode(array("success" => 0, "message" => "PDF文件上传失败"));exit;
- }else{
- $pdfurl = $uploadInfo['url'];
- }
- $this->sConn->createCommand()->update("exam_group", array("answer_path" => $pdfurl), "exam_group_id = '{$examGroupId}'");
- // echo json_encode(array("success" => 1, "message" => "http://" . $_SERVER['SERVER_NAME'].$pdfurl));exit;
- echo json_encode(array("success" => 1, "message" => "创建成功","url"=>$pdfurl));exit;
- } else {
- @unlink($htmlpath);
- echo json_encode(array("success" => 0, "message" => "PDF文件未找到!"));exit;
- }
- } else {
- @unlink($htmlpath);
- echo json_encode(array("success" => 0, "message" => "PDF创建失败1!"));
- exit;
- }
- }else{
- @unlink($htmlpath);
- echo json_encode(array("success" => 0, "message" => "PDF创建失败2!"));
- exit;
- }
- }
- /**
- * 下载pdf
- */
- public function actionDownPdf(){
- $examGroupId = safe_replace(Yii::app()->request->getQuery('examGroupId'));
- if(!$examGroupId){
- Yii::app()->jump->error('请指定考试');
- }
- $sql = "select eg.answer_path,e.name from exam_group eg join exam e on e.exam_group_id = eg.exam_group_id where eg.exam_group_id = '{$examGroupId}'";
- $exam_info = $this->sConn->createCommand($sql)->queryRow();
- // $pdfpath = str_replace("protected", "", Yii::app()->basePath) . $exam_info['answer_path'];
- // if ($this->check_pdf($pdfpath)) {
- // Header("Content-type:application/pdf");
- // Header("Accept-Ranges: bytes");
- // Header("Accept-Length: " . filesize($pdfpath));
- // Header("Content-Disposition: attachment; filename=" . $this->filter_file_name($exam_info['name']) . ".pdf"); // 输出文件内容
- // flush();// 刷新内容
- // $file=fopen($pdfpath,"r");
- // $download_rate=600;
- // while (!feof($file)){
- // set_time_limit(0);
- // print fread($file,round($download_rate*1024));// 发送当前部分文件给浏览者
- // flush();// flush 内容输出到浏览器端
- // sleep(1);// 终端1秒后继续
- // }
- // } else {
- // Yii::app()->jump->error('考试不存在或尚未生成PDF');
- // }
- if(strpos($exam_info['answer_path'],'http') !== false){
- if(!fileGetContents($exam_info['answer_path'])){
- Yii::app()->jump->error('考试不存在或尚未生成PDF');
- }else{
- $url = $exam_info['answer_path'];
- // 获取远程文件大小
- // 注意filesize()无法获取远程文件大小
- $headers = get_headers($url, 1);
- $fileSize = $headers['Content-Length'];
- //echo $fileSize;exit;
- // 设置header头
- // 因为不知道文件是什么类型的,告诉浏览器输出的是字节流
- header('Content-Type: application/pdf');
- // 告诉浏览器返回的文件大小类型是字节
- header('Accept-Ranges:bytes');
- // 告诉浏览器返回的文件大小
- header('Content-Length: ' . $fileSize);
- // 告诉浏览器文件作为附件处理并且设定最终下载完成的文件名称
- Header("Content-Disposition: attachment; filename=" . $this->filter_file_name($exam_info['name']) . ".pdf"); // 输出文件内容
- //针对大文件,规定每次读取文件的字节数为4096字节,直接输出数据
- ob_clean();
- $read_buffer = 1024*1024;
- $handle = fopen($url, 'rb');
- //总的缓冲的字节数
- $sum_buffer = 0;
- //只要没到文件尾,就一直读取
- while (!feof($handle)) {
- echo fread($handle, $read_buffer);
- ob_flush();
- }
- fclose($handle);
- }
- }else{
- Yii::app()->jump->error('考试不存在或尚未生成PDF');
- }
- }
- private function check_pdf($pdf_path) {
- if (substr($pdf_path, strlen($pdf_path) - 4, 4) == ".pdf") {
- if (file_exists($pdf_path)) {
- return true;
- }
- }
- return false;
- }
- function filter_file_name($filename){
- return str_replace(array(',','.','/','?','!','@','#','$','%','^','&','*','(',')','-','+','{','}','[',']',':',';','"','`','~'),
- array(',','。',' ','?','!',' ',' ',' ',' ','·',' ',' ','(',')','-','+','【','】','【','】',':',';','“',' ',' ')
- , $filename);
- }
- //二轮复习个性化提分手册列表
- public function actionReview(){
- Url::clean();
- $data = array();
- $printName = Req::get("name");
- $classId = Req::get("classId");
- $grade = (int)Req::get("grade");
- $newCondition = array();
- if($grade){
- $newCondition[] = 'mrs.grade='.$grade;
- }
- if($printName){
- $newCondition[] = 'mrs.name like "%'.$printName.'%"';
- }
- if($classId){
- $newCondition[] = 'mrs.class_id='.$classId;
- }
- $resultList = $this->schoolManager->getMathWeek($newCondition,array('mrs.create_time desc','mrs.mr_id desc'));
- $printList = array();
- if($resultList["rs"]){
- foreach ($resultList['rs'] as $k=>$v) {
- $printList[$k]=$v;
- }
- }
- if (empty($grade)) {
- $grade = 'ALL';
- }
- $classes = $this->schoolManager->getClasses($grade);
- $data['pages'] = $resultList['pager'];
- $data['page_total'] = $resultList['pager']->rowsCount;
- $data['printList'] = $printList;
- $data["printName"] = $printName;
- $data["classes"] = $classes;
- $data["classId"] = $classId;
- $data["grade"] = $grade;
- $this->render('review',$data);
- }
- //二轮复习个性化提分手册设置
- public function actionReviewSetting(){
- $data = array();
- $result = $this->apiPost('all_knowledge/point',array());
- $data['special_arr']=$result;
- $this->render('review_setting',$data);
- }
- //保存二轮复习个性化提分手册设置
- public function actionAjaxSaveMathReview(){
- $result = array();
- $error = array();
- if (! Yii::app()->request->isAjaxRequest OR ! Yii::app()->request->isPostRequest){
- $error[] = '错误的来源!';
- }else{
- $grade=(int)Req::post('grade');
- $createType = (int)Req::post('createType');
- $classIds = Req::post('selectClassIds');
- $itemIds = (array)Req::post('selectedItemIds');
- $special = (int)Req::post('special');
- $specialName = Req::post('specialName');
- $isNewVersion = (int)Req::post('isNewVersion');//新版本为1,旧版本默认为0
- if($createType==1){
- //自动,读取专题下所有考点
- $result = $this->apiPost('all_knowledge/point',array('specialIds'=>array($special)));
- $itemIds=array();
- if($result){
- foreach ($result as $item){
- if($item['kps']){
- foreach ($item['kps'] as $kp){
- if($kp['methods']){
- foreach ($kp['methods'] as $method){
- $itemIds[]=$method['method_id'];
- }
- }
- }
- }
- }
- }
- }
- if(!$itemIds){
- $error[] = '请选择专项';
- }
- if(!$grade){
- $error[] = '请选择年级';
- }
- if(!$classIds){
- $error[] = '请选择班级';
- }
- }
- if(!$error){
- $time = time();
- $strModel = new SStudentClassRelation();
- $transaction = $this->sConn->beginTransaction();
- try{
- $mrGroupId = getUniqueId($this->schoolId);
- $mrIds=array();
- foreach($classIds as $k=>$v){
- $mathName = $specialName;
- $mrId=getUniqueId($this->schoolId);
- $mrIds[]=$mrId;
- $this->sConn->createCommand()->insert('math_review_setting',array(
- 'mr_group_id' =>$mrGroupId,
- 'mr_id' => $mrId,
- 'special_id' => $special,
- 'name' => $mathName,
- 'semester_id' => $this->semesterId,
- 'grade' => $grade,
- 'class_id' => $v,
- 'is_all_html' => 0,
- 'method_ids' => implode(',',$itemIds),
- 'create_type' => $createType,
- 'create_time' => $time,
- 'is_new_version' => $isNewVersion,
- ));
- //获取班级学生
- $stuData = $strModel->getRelationsByClassId_Status_0($v);
- if($stuData){
- foreach($stuData as $kk=>$vv){
- $this->sConn->createCommand()->insert('math_review_student',array(
- 'mr_id' => $mrId,
- 'student_id' => $vv['student_id'],
- 'create_time'=>$time
- ));
- }
- }
- }
- $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'=>$error));exit;
- }else{
- //发消息
- if($isNewVersion){
- $kafkaData=array(
- 'school_id'=>$this->schoolId,
- 'msg_type'=>90,//1-完成阅卷,2-发送标注,3-点代办,90-重置 产品生成说写90
- 'grade'=>$grade,
- 'subject_id'=>3,
- 'send_type'=>'math_review',
- 'product_type'=>17,
- 'gp_group_id'=>$mrGroupId,
- 'gp_ids'=>array_unique($mrIds),
- );
- sendDataToKafka("php-product-math-review-html",$kafkaData);
- }
- echo json_encode(array('status'=>1));exit;
- }
- }
- //选择学生二轮复习个性化提分手册
- public function actionSelectStuByMath(){
- $data = array();
- $sname = (string)Req::get("sname"); //学生名字
- $mrId = (string)Req::get("mrId");
- if(!$mrId){
- Yii::app()->jump->error('参数错误!');
- }
- //获取班级名称以及周后推送名称
- $sql = "select ew.name,c.class_name,ew.grade,ew.class_id,ew.create_time,ew.semester_id from math_review_setting ew join class c on ew.class_id = c.class_id where ew.mr_id = '{$mrId}'";
- $names = $this->sConn->createCommand($sql)->queryRow();
- if(!$names){
- $names = array();
- $names['name'] = '';
- $names['class_name'] = '';
- $names['grade'] = 0;
- }else{
- $data['name'] = isset($names['name'])?$names['name']:'';
- }
- $sql = "select student_id,is_review_pdf from math_review_student where mr_id = '{$mrId}'";
- $relateStudent = $this->sConn->createCommand($sql)->queryAll();
- $studentIds = array();
- $stuIsPdf = array();
- if($relateStudent){
- foreach ($relateStudent as $studentInfo) {
- $studentIds[] = (string)$studentInfo['student_id'];
- $stuIsPdf[(string)$studentInfo['student_id']] = $studentInfo['is_review_pdf'];
- }
- }
- if($studentIds){
- $studentNames = SStudentInfo::model()->getStudents($studentIds); //求学生名字
- if($studentNames){
- if($sname){
- $i = 1;
- foreach($studentNames as $k=>$v){
- if(strpos($v['realname'],$sname) !== false){
- $data['list'][$i]['stu_id'] = (string)$v['student_id'];
- $data['list'][$i]['stu_name'] = $v['realname'];
- $data['list'][$i]['name'] = $names['class_name'].$v['realname'].$names['name'];
- $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$v['student_id']])?$stuIsPdf[(string)$v['student_id']]:0;
- switch($v['level']){
- case 1:
- $data['list'][$i]['level'] = '尖子生';
- break;
- case 2:
- $data['list'][$i]['level'] = '尖子生';
- break;
- case 3:
- $data['list'][$i]['level'] = '中等生';
- break;
- case 4:
- $data['list'][$i]['level'] = '学困生';
- break;
- default:
- $data['list'][$i]['level'] = '无';
- }
- $i++;
- }
- }
- }else{
- $i = 1;
- foreach($studentNames as $k=>$v){
- $data['list'][$i]['stu_id'] = (string)$v['student_id'];
- $data['list'][$i]['stu_name'] = $v['realname'];
- $data['list'][$i]['name'] = $names['class_name'].$v['realname'].$names['name'];
- $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$v['student_id']])?$stuIsPdf[(string)$v['student_id']]:0;
- switch($v['level']){
- case 1:
- $data['list'][$i]['level'] = '尖子生';
- break;
- case 2:
- $data['list'][$i]['level'] = '尖子生';
- break;
- case 3:
- $data['list'][$i]['level'] = '中等生';
- break;
- case 4:
- $data['list'][$i]['level'] = '学困生';
- break;
- default:
- $data['list'][$i]['level'] = '无';
- }
- $i++;
- }
- }
- }
- }
- $Sem=new SSemester();
- $code= $Sem->conn->createQuery()
- ->from('semester')
- ->where("semester_id = '".$names['semester_id']."'")
- ->limit(1)
- ->query()
- ->read();
- if($studentIds){
- $intarr=array(
- "schoolId"=>$this->schoolId,
- "clazzId"=>$names['class_id'],
- "semester"=>$code['refer_code'],
- "grade"=>$names['grade'],
- "students"=>$studentIds,
- "examTime"=>$names['create_time'],
- "classify"=>5,
- "subject"=>3
- );
- $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]);
- $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr),$basic));
- if(!$rs){
- Yii::app()->jump->error("接口错误");
- }
- if($rs->errCode!="00"){
- Yii::app()->jump->error($rs->errMsg);
- }
- if(!empty($rs->data)){
- $data['limitstu']=array();
- foreach ($rs->data as $v){
- $data['limitstu'][(string)$v]=$v;
- }
- }
- }
- $data['mrId'] = $mrId;
- $data['sname'] = $sname;
- $data['printType'] = 'mrv_stu';
- $this->render('review_stu',$data);
- }
- //获取设置二轮复习个性化提分手册的班级
- public function actionAjaxGetClassesBySettingMath(){
- $result = array();
- $grade=(int)Req::post('grade');
- $specialId=(int)Req::post('specialId');
- //获取班级
- $hasSettingClassIds = array();
- $sql = "select class_id,count(*) count from math_review_setting where semester_id = '{$this->semesterId}' and special_id='{$specialId}' group by class_id";
- $data = $this->sConn->createCommand($sql)->queryAll();
- if($data){
- foreach($data as $k=>$v){
- if($v['count'] > 2){
- $hasSettingClassIds[] = (string)$v['class_id'];
- }
- }
- }
- if($grade){
- $sql = "select class_id,class_name from class where semester_id = '{$this->semesterId}' and grade = {$grade} and is_hide=0";
- $data = $this->sConn->createCommand($sql)->queryAll();
- if($data){
- $i = 0;
- foreach($data as $k => $v){
- $result[$i]['class_id'] = $v['class_id'];
- $result[$i]['class_name'] = $v['class_name'];
- if(in_array((string)$v['class_id'],$hasSettingClassIds,true)){
- $result[$i]['status'] = 1;
- }else{
- $result[$i]['status'] = 0;
- }
- $i++;
- }
- }
- }
- echo json_encode($result);exit;
- }
- //下载二轮复习个性化提分手册
- public function actionGetMathReviewFile(){
- $mrId = (string)Req::get("mrId");
- $studentsIds = (string)Req::get("studentsIds");
- $params = array();
- if(!$mrId){
- echo json_encode(array("success" => 0, "message" => "缺少参数"));
- exit();
- }
- if(!$studentsIds){
- $studentsIds = array();
- $sql = "select student_id from math_review_student where mr_id = '{$mrId}' and is_review_pdf = 1";
- $stuArr = $this->sConn->createCommand($sql)->queryAll();
- if($stuArr){
- foreach($stuArr as $k=>$v){
- $studentsIds[] = $v['student_id'];
- }
- }
- }else{
- $studentsIds = explode(',',$studentsIds);
- }
- if(!$studentsIds || empty($studentsIds)){
- echo json_encode(array("success" => 0, "message" => "无生成的学生"));
- exit();
- }
- $params['mrId'] = $mrId;
- $sql = "select class_id,grade,create_time,semester_id,school_group_id from math_review_setting where mr_id = '{$mrId}'";
- $msg = $this->sConn->createCommand($sql)->queryRow();
- $Sem=new SSemester();
- $code= $Sem->conn->createQuery()
- ->from('semester')
- ->where("semester_id = '".$msg['semester_id']."'")
- ->limit(1)
- ->query()
- ->read();
- $intarr=array(
- "schoolId"=>$this->schoolId,
- "clazzId"=>$msg['class_id'],
- "semester"=>$code['refer_code'],
- "grade"=>$msg['grade'],
- "students"=>$studentsIds,
- "examTime"=>$msg['create_time'],
- "classify"=>5,
- "subject"=>3
- );
- if(isset($msg['school_group_id']) && $msg['school_group_id']){
- $apiUrl = isset(Yii::app()->params["improve_url"][$msg['school_group_id']]) ? Yii::app()->params["improve_url"][$msg['school_group_id']] : null;
- }else{
- $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
- }
- if(!$apiUrl){
- echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
- exit();
- }
- $schoolInfo = BusinessSchool::model()->find('school_id=:school_id', array(':school_id' => $this->schoolId));
- if(isset($schoolInfo['is_allow_download']) && ($schoolInfo['is_allow_download']==1)){
- if($studentsIds){
- $params["studentIds"] = $studentsIds;
- }
- }else{
- if(Yii::app()->params["limit_open"]){
- $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]);
- $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr),$basic));
- if(!$rs){
- Yii::app()->jump->error("接口错误");
- }
- if($rs->errCode!="00"){
- echo json_encode(array("success" => 0, "message" => $rs->errMsg));
- exit();
- }
- if(!empty($rs->data)){
- $params["studentIds"]=$rs->data;
- if(count($rs->data)<count($intarr['students'])){
- $limitinfo="购买过的".count($intarr['students'])-count($rs->data)."位学生可下载";
- }
- } else{
- echo json_encode(array("success" => 0, "message" =>"请先购买商品"));
- exit();
- }
- }else{
- if($studentsIds){
- $params["studentIds"] = $studentsIds;
- }
- }
- }
- $params['schoolId'] = $this->schoolId;
- $params['type'] = 1;
- $rs = Curl::post($apiUrl."/rest/download_math_pdf/index", $params);
- if(!($rs = json_decode($rs))){
- $rs = array(
- "success" => 0,
- "message" => "请求接口失败",
- );
- }else{
- //更新下载时间
- if($rs->success==1 || $rs->success==2){
- $time = time();
- if($studentsIds){
- $sql = "update math_review_student set is_review_download = 1,review_download_time={$time} where mr_id = '{$mrId}' and student_id in (".implode(',',$studentsIds).")";
- $this->sConn->createCommand($sql)->execute();
- }
- }
- }
- if(isset($msg['school_group_id']) && $msg['school_group_id'] && isset($rs->downloadPath)){
- if (YII_ENV == 'pro' || YII_ENV == 'production') {
- $rs->downloadPath = preg_replace('/http\:\/\/zstatic\d{1,2}/','http://zstatic'.$msg['school_group_id'],$rs->downloadPath);
- }
- }
- echo json_encode($rs);exit;
- }
- public function apiPost($path, $arr, $type = 0)
- {
- $ch = @curl_init();
- $result = FALSE;
- if ($ch) {
- $data = json_encode($arr);
- $url = Yii::app()->params['api'][$type]['prefix'] . $path;
- $username = Yii::app()->params['api'][$type]['username'];
- $password = Yii::app()->params['api'][$type]['password'];
- // Digest认证
- curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
- curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);
- // 不输出头部
- curl_setopt($ch, CURLOPT_HEADER, 0);
- // curl_exec 获取到的内容不直接输出, 而是返回
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- // 请求重启路由器的地址 传参 进行重启
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_USERAGENT, 'Api Client/1.0.0 (chengfei@liancaitech.com)');
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
- 'Content-Type: application/json',
- 'Content-Length: ' . strlen($data),
- ));
- if (!curl_errno($ch)) {
- $result = json_decode(curl_exec($ch),1);
- }
- // 释放资源
- curl_close($ch);
- }
- return $result;
- }
- //编辑考试信息
- public function actionModifyThirdExam(){
- $exam_group_id = Req::post("examGroupId");
- if(!$exam_group_id){
- $exam_group_id = Req::get("exam_group_id");
- }
- $findInfo = SExamGroup::model()->find('exam_group_id=:eg_id',array('eg_id'=>$exam_group_id));
- $exam_data = Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- if(!$exam_data)
- {
- Yii::app()->jump->error('非法试卷!');
- }
- @$tplData=json_decode($exam_data['tpl_data'],true);
- if(!$tplData){
- Yii::app()->jump->error('非法试卷!');
- }
- if (Yii::app()->request->getIsPostRequest()){
- $type=Req::post('type');
- $name=Req::post('examName');
- $examDate=Req::post('examDate');
- $isCustomTpl=Req::post('isCustomTpl');
- $tplDataPaper=Req::post('tplDataPaper');
- $printTypeCard=Req::post('printTypeCard');
- $tianType=Req::post('tianType');
- $jieType=Req::post('jieType');
- $dtkType=Req::post('dtkType');
- $tplIndex=0;
- if(!matchStrChar($name)){
- Yii::app()->jump->error('考试名称不能包含特殊字符!');
- }
- $paperData=$this->sConn->createCommand("select paper_id,is_labelled from paper where exam_id ='{$exam_data['exam_id']}'")->queryRow();
- if($findInfo->status==2){
- $examSql="update `exam` set `name`='".$name."' ";
- $examSql.=" where exam_group_id='".$exam_group_id."'";
- $this->sConn->createCommand($examSql)->execute();
- if($paperData['is_labelled']>0 || $findInfo['is_tagging']>0){
- updateExamNameToTiku($exam_group_id,$name,$this->schoolId);
- }
- $this->redirect($this->createUrl('print/index'));
- }
- //解答题大分值特殊index值
- $tplIndexArrJieDa=array(
- 1=>array(
- 3=>array( //29分
- 1=>3016,
- 2=>3017,
- 3=>3018,
- 4=>3019
- ),
- 4=>array( //49分
- 1=>4016,
- 2=>4017,
- 3=>4018,
- 4=>4019
- )
- ),
- 2=>array(
- 3=>array( //29分
- 1=>3012,
- 2=>3013,
- 3=>3014,
- 4=>3015
- ),
- 4=>array( //49分
- 1=>4012,
- 2=>4013,
- 3=>4014,
- 4=>4015
- )
- )
- );
- //解答题小分值index值
- $tplIndexArr=array(
- 1=>array(
- 11=>array(
- 1=>1016,
- 2=>1017,
- 3=>1018,
- 4=>1019
- ),
- 12=>array(
- 1=>2016,
- 2=>2017,
- 3=>2018,
- 4=>2019
- ),
- 13=>array(
- 1=>16,
- 2=>17,
- 3=>18,
- 4=>19
- )
- ),
- 2=>array(
- 11=>array(
- 1=>1012,
- 2=>1013,
- 3=>1014,
- 4=>1015
- ),
- 12=>array(
- 1=>2012,
- 2=>2013,
- 3=>2014,
- 4=>2015
- ),
- 13=>array(
- 1=>12,
- 2=>13,
- 3=>14,
- 4=>15
- )
- ),
- );
- if($isCustomTpl){
- if($printTypeCard){
- if($jieType>2){
- if(isset($tplIndexArrJieDa[$printTypeCard][$jieType][$dtkType])){
- $tplIndex=$tplIndexArrJieDa[$printTypeCard][$jieType][$dtkType];
- }else{
- // Yii::app()->jump->error('编辑失败,解答题分值格式有误!');
- }
- }else{
- if(!inArray($this->schoolInfo->province_id,array(11,12))){
- $tplIndex=$tplIndexArr[$printTypeCard][13][$dtkType];
- }else{
- if(isset($tplIndexArr[$printTypeCard][$this->schoolInfo->province_id][$dtkType])){
- $tplIndex=$tplIndexArr[$printTypeCard][$this->schoolInfo->province_id][$dtkType];
- }
- }
- }
- }
- //判断题量,
- // if (inArray($tplIndex, array(12,16,1012, 1016, 2012, 2016,3016,3012,3007,4012,4016))) {
- // if(isset($tplData['items'][1]) && $tplData['items'][1]['total']>90){
- // Yii::app()->jump->error('试卷的选择题数量超出了当前选择的答题卡题量上限!');
- // }
- // if(isset($tplData['items'][5]) && $tplData['items'][5]['total']>45){
- // Yii::app()->jump->error('试卷的填空题数量超出了当前选择的答题卡题量上限!');
- // }
- // if(isset($tplData['items'][2]) && $tplData['items'][2]['total']>30){
- // Yii::app()->jump->error('试卷的多选题数量超出了当前选择的答题卡题量上限!');
- // }
- // }else{
- // if(isset($tplData['items'][1]) && $tplData['items'][1]['total']>30){
- // Yii::app()->jump->error('试卷的选择题数量超出了当前选择的答题卡题量上限!');
- // }
- // if(isset($tplData['items'][5]) && $tplData['items'][5]['total']>30){
- // Yii::app()->jump->error('试卷的填空题数量超出了当前选择的答题卡题量上限!');
- // }
- // if(isset($tplData['items'][2]) && $tplData['items'][2]['total']>30){
- // Yii::app()->jump->error('试卷的多选题数量超出了当前选择的答题卡题量上限!');
- // }
- // }
- //校验分数
- $tianType=Req::post('tianType');
- $jieType=Req::post('jieType');
- // if($tianType){
- // $maxScore=100;
- // if($tianType==2){
- // $maxScore=5;
- // }elseif($tianType==3) {
- // $maxScore = 6;
- // }elseif($tianType==4){
- // $maxScore = 4;
- // }
- // if(isset($tplData['items'][5]) && $tplData['items'][5]['perScores']){
- // foreach($tplData['items'][5]['perScores'] as $val){
- // if($val>$maxScore){
- // Yii::app()->jump->error('试卷的填空题分数超出了当前选择的答题卡分数上限!');
- // }
- // }
- // }
- // }
- // if($jieType){
- // $maxScore=0;
- // if($jieType==1){
- // $maxScore=15;
- // }elseif($jieType==2) {
- // $maxScore = 16;
- // }elseif($jieType==3){
- // $maxScore = 29;
- // }elseif($jieType==4){
- // $maxScore = 49;
- // }
- // if(isset($tplData['items'][7]) && $tplData['items'][7]['perScores']){
- // foreach($tplData['items'][7]['perScores'] as $val){
- // if($val>$maxScore){
- // Yii::app()->jump->error('试卷的解答题分数超出了当前选择的答题卡分数上限!');
- // }
- // }
- // }
- // }
- }
- $transaction = $this->sConn->beginTransaction();
- try{
- $tplData['examDate']=$examDate;
- if($tplDataPaper){
- if($tplDataPaper==1){
- $tplData['paper']=1;
- }else{
- $tplData['paper']=0;
- }
- }
- if($tianType){
- $tplData['tianType']=$tianType;
- }
- if($jieType){
- $tplData['jieType']=$jieType;
- }
- $examSql="update `exam` set `type`='".$type."',`name`='".$name."' ";
- if($tplIndex){
- $examSql.=" , tpl_index='".$tplIndex."'";
- }
- $examSql.=" , tpl_data='".jsonEncode($tplData)."' where exam_group_id='".$exam_group_id."'";
- $this->sConn->createCommand($examSql)->execute();
- $transaction->commit();
- if($paperData['is_labelled']>0 || $findInfo['is_tagging']>0){
- updateExamNameToTiku($exam_group_id,$name,$this->schoolId);
- }
- if(Yii::app()->params['handle_log_on_off'])
- {
- writeFileLog(jsonEncode(array(
- "examGroupId" => $exam_group_id,
- "operate_project" => 'zsyas2',
- "school_id" => $this->schoolId,
- "title" => '编辑考试',
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $this->getRoute(),
- "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
- "date"=>date('Y-m-d H:i:j')
- )));
- }
- $this->redirect($this->createUrl('print/index'));
- }catch(Exception $e){
- $transaction->rollBack();
- Yii::app()->jump->error('编辑失败!');
- }
- }
- $a3=array(12,16,1012,1016,2012,2016,3012,3016,4012,4016);
- $a4=array(13,17,1013,1017,2013,2017,3013,3017,4013,4017);
- $k8=array(14,18,1014,1018,2014,2018,3014,3018,4014,4018);
- $k16=array(15,19,1015,1019,2015,2019,3015,3019,4015,4019);
- if(in_array($exam_data['tpl_index'], Yii::app()->params['custom_tpls_ids'])){
- //自定义模板
- $data['is_custom_tpl'] = 1;
- }else{
- //非自定义模板
- $data['is_custom_tpl'] = 0;
- }
- if (in_array($exam_data['tpl_index'], Yii::app()->params['no_template_id']) ) {
- //题卡分离
- $data['paper_tpl_type'] = 2;
- }else{
- $data['paper_tpl_type'] = 1;
- }
- $data['dtkType']=0;
- $data['dtk']='';
- if(in_array($exam_data['tpl_index'], $a3)){
- $data['dtk']='A3';
- $data['dtkType']=1;
- }elseif(in_array($exam_data['tpl_index'], $a4)){
- $data['dtk']='A4';
- $data['dtkType']=2;
- }elseif(in_array($exam_data['tpl_index'], $k8)){
- $data['dtk']='8k';
- $data['dtkType']=3;
- }elseif(in_array($exam_data['tpl_index'], $k16)){
- $data['dtk']='16k';
- $data['dtkType']=4;
- }
- $data['examGroupId']=$exam_group_id;
- $data['createType']=$findInfo->create_type;
- $data['name']=$exam_data['name'];
- $data['markType']=$findInfo->mark_type;
- $data['paperType']=$exam_data['tpl_index'];
- $data['type']=$exam_data['type'];
- $data['paper']=$tplData['paper'];
- $data['examDate']=$tplData['examDate'];
- $data['qxkPaperId']=$findInfo->qxk_paper_id;
- $data['examStatus']=$findInfo->status;
- if(isset($tplData['tianType'])){
- $data['tianType']=$tplData['tianType'];
- }else{
- $data['tianType']='';
- }
- if(isset($tplData['jieType'])){
- $data['jieType']=$tplData['jieType'];
- }else{
- $data['jieType']='';
- }
- $data['subjectId']=$exam_data['subject_id'];
- $this->render('modify_exam',$data);
- }
- //在线答题卡批量下载
- public function actionDownloadOnlineBatch(){
- $exam_id = Req::post("exam_id");
- $student_id = Req::post("student_id");
- $result['status']=0;
- if(!$exam_id ) {
- echo json_encode(array("status"=>0,"result"=>"参数不能为空"));
- }
- if(empty($student_id) ) {
- echo json_encode(array("status"=>0,"result"=>"请至少选择一个学生"));
- }
- $studentIds = explode(',',$student_id);
- foreach ($studentIds as $v)
- {
- if($v)
- {
- $student_ids[] = $v;
- }
- }
- $studentPdf=$this->sConn->createCommand("select student_id,answer_card_online_url from student_answer_card_online where answer_card_online_created=1 and exam_id='".$exam_id."' and student_id in(".implode(',',$student_ids).")")->queryAll();
- if($studentPdf){
- ClassExamPrinter::model()->updateAll(array('is_print_online'=>1),'exam_id=:exam_id',array(':exam_id'=>$exam_id));
- $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id));
- //读取班级
- $class=SClass::model()->find('class_id=:class_id',array(':class_id'=>$exam_data['class_id']));
- $thirdAnswerSheet=$this->sConn->createCommand("select multiplex_id from third_answer_sheet where exam_group_id='{$exam_data['exam_group_id']}' ")->queryRow();
- if($thirdAnswerSheet['multiplex_id']){
- $this->sConn->createCommand("update online_card_multiplex set is_download=1,update_time=".time()." where multiplex_id='{$thirdAnswerSheet['multiplex_id']}'")->execute();
- }
- //$tmpFile = tempnam('/tmp', '');
- // $zipFileNameNew=$exam_data['name'].'-'.$class['class_name'].'.zip';
- $zipFileName=$exam_id.'.zip';
- $dirFile='upload/tmpDir/BatchDownLoadFile/'.date('Y').'/'.date('m').'/'.date('j');
- if(!is_dir($dirFile)){
- $this->mkdir($dirFile);
- }
- $dirFile.='/'.$zipFileName;
- if(file_exists($dirFile)){
- unlink($dirFile);
- }
- $zip = new ZipArchive;
- $zip->open($dirFile, ZipArchive::CREATE);
- foreach ($studentPdf as $val) {
- // download file
- // $fileContent = file_get_contents($file);
- if($val['answer_card_online_url']){
- $file=$val['answer_card_online_url'];
- $fileUrl=$file.'?r='.mt_rand(1,999);
- $fileContent=fileGetContents($fileUrl);
- $zip->addFromString(iconv('utf-8', 'gbk//ignore', get_basename($file)), $fileContent);
- }
- }
- $zip->close();
- $result['status']=1;
- $result['result']=Yii::app()->request->hostInfo.'/'.$dirFile;
- exit(json_encode($result));
- }else{
- $result['result']='答题卡尚未生成';
- exit(json_encode($result));
- }
- }
- //在线答题卡班级下载
- public function actionDownloadOnlineClass(){
- $exam_id = Req::post("exam_id");
- if(!$exam_id ) {
- Yii::app()->jump->error('参数错误!');
- }
- $result['status']=0;
- if(!$exam_id ) {
- echo json_encode(array("status"=>0,"result"=>"参数不能为空"));
- }
- $studentPdf=$this->sConn->createCommand("select student_id,answer_card_online_url from student_answer_card_online where answer_card_online_created=1 and exam_id='".$exam_id."' ")->queryAll();
- if($studentPdf){
- $files=array();
- foreach ($studentPdf as $value){
- $files[]=$value['answer_card_online_url'];
- }
- ClassExamPrinter::model()->updateAll(array('is_print_online'=>1),'exam_id=:exam_id',array(':exam_id'=>$exam_id));
- //$tmpFile = tempnam('/tmp', '');
- $zipFileName=$exam_id.'.zip';
- $dirFile='upload/tmpDir/BatchDownLoadFile/'.date('Y').'/'.date('m').'/'.date('j');
- if(!is_dir($dirFile)){
- $this->mkdir($dirFile);
- }
- $dirFile.='/'.$zipFileName;
- if(file_exists($dirFile)){
- unlink($dirFile);
- }
- $zip = new ZipArchive;
- $zip->open($dirFile, ZipArchive::CREATE);
- foreach ($studentPdf as $val) {
- if($val['answer_card_online_url']){
- $file=$val['answer_card_online_url'];
- $fileUrl=$file.'?r='.mt_rand(1,999);
- $fileContent=fileGetContents($fileUrl);
- $zip->addFromString(iconv('utf-8', 'gbk//ignore', get_basename($file)), $fileContent);
- }
- }
- $zip->close();
- $result['status']=1;
- $result['result']=Yii::app()->request->hostInfo.'/'.$dirFile;
- exit(json_encode($result));
- }else{
- $result['result']='班级答题卡尚未生成';
- exit(json_encode($result));
- }
- }
- //发送生成在线答题卡任务(班级)
- public function actionSendCreateOnline(){
- $examId=Req::post('exam_id');
- $result['status']=0;
- if(!$examId || !is_numeric($examId)){
- $result['msg']='参数不正确';
- exit(json_encode($result));
- }
- $examInfo = Exam::model()->findByPk($examId);
- if(!$examInfo){
- $result['msg']='未找到考试信息';
- exit(json_encode($result));
- }
- $onlineCard=$this->schoolManager->getAnswerSheetOnline($examInfo->exam_group_id);
- if(!$onlineCard){
- $result['msg']='考试还没有使用在线答题卡';
- exit(json_encode($result));
- }
- $arr=array(
- 'schoolId'=>$this->schoolId,
- 'examId'=>$examId,
- 'examGroupId'=>$examInfo->exam_group_id,
- 'savedInfoUrl'=>$onlineCard['file_path'],
- 'isClassTask'=>1
- );
- $url=Yii::app()->params['answerCardOnlineCreateUrl'].'classesTopdf';
- $ch = @curl_init();
- $return=array();
- if ($ch) {
- $data = json_encode($arr);
- // 不输出头部
- curl_setopt($ch, CURLOPT_HEADER, 0);
- // curl_exec 获取到的内容不直接输出, 而是返回
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- // 请求重启路由器的地址 传参 进行重启
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_USERAGENT, 'Api Client/1.0.0 (chengfei@liancaitech.com)');
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
- 'Content-Type: application/json',
- 'Content-Length: ' . strlen($data),
- ));
- if (!curl_errno($ch)) {
- $return = json_decode(curl_exec($ch),1);
- }
- curl_close($ch);
- }
- if(isset($return['code']) && $return['code']==1){
- $result['status']=1;
- $this->sConn->createCommand("update student_answer_card_online set answer_card_online_created=0 where exam_id='".$examId."' ")->execute();
- }elseif($return['code']==2){
- $result['msg']='任务队列已存在该任务';
- }elseif(isset($return['msg'])){
- $result['msg']=$return['msg'];
- }
- exit(json_encode($result));
- }
- //发送生成在线答题卡任务(学生)
- public function actionSendCreateOnlineStudents(){
- $examId=Req::post('exam_id');
- $students=Req::post('students');
- $className=Req::post('class_name');
- $checkOrder=Req::post('check_order'); //是否检查订单
- $result['status']=0;
- if(!$examId || !is_numeric($examId)){
- $result['msg']='参数不正确';
- exit(json_encode($result));
- }
- if($checkOrder){
- //检查订单
- $orderClass=0;
- if(!$students){
- $allClassStudents=$this->sConn->createCommand("select student_id,class_id from student_paper_relation where exam_id='{$examId}' and is_del=0 ")->queryAll();
- if($allClassStudents){
- foreach ($allClassStudents as $student){
- $students[]=$student['student_id'];
- if(!$orderClass) $orderClass=$student['class_id'];
- }
- }
- }
- $semester=new SSemester();
- $nowsem=$semester->getCurrentSemester();
- $classinfo= ClassModel::model()->find("class_id=:id",array(":id"=>$orderClass));
- $subjectId=Yii::app()->session['session_subject_id'];
- if(in_array($subjectId,$this->mathSubjectId)){
- $subjectId=3;
- }
- $intarr=array(
- "schoolId"=>$this->schoolId,
- "clazzId"=>$orderClass,
- "semester"=>$nowsem['refer_code'],
- "grade"=>$classinfo['grade'],
- "students"=>array(),
- "examTime"=>time(),
- "classify"=>1,
- "subject"=>$subjectId,
- );
- $students=$this->getManyProductOrder($intarr,array(1,2,3,31),$students);
- if(!$students){
- $result['msg']='当前班级没查询到订单';
- exit(json_encode($result));
- }
- }
- if(!$students || !is_array($students)){
- $result['msg']='请选择要生成的学生';
- exit(json_encode($result));
- }
- $examInfo = Exam::model()->findByPk($examId);
- if(!$examInfo){
- $result['msg']='未找到考试信息';
- exit(json_encode($result));
- }
- $onlineCard=$this->schoolManager->getAnswerSheetOnline($examInfo->exam_group_id);
- if(!$onlineCard){
- $result['msg']='考试还没有使用在线答题卡';
- exit(json_encode($result));
- }
- $postStudents=$this->sConn->createCommand("select student_id,paper_id,class_id,student_card,school_student_card,exam_id from student_paper_relation where exam_id='{$examId}' and is_del=0 and student_id in(".implode(',',$students).")")->queryAll();
- if($postStudents){
- foreach ($postStudents as $key =>$val){
- $studentInfo=$this->sConn->createCommand("select `realname` from student_info where student_id='{$val['student_id']}'")->queryRow();
- $postStudents[$key]['student_name']=$studentInfo['realname'];
- $postStudents[$key]['class_name']=$className;
- if($examInfo->school_card_status==1){
- $postStudents[$key]['student_card']=$val['school_student_card'];
- }
- }
- }
- $error=array();
- if(count($postStudents)>100){
- $newPushArr=array();
- $newPushArr=array_chunk($postStudents,100);
- foreach ($newPushArr as $item){
- $arr=array(
- 'schoolId'=>$this->schoolId,
- 'examId'=>$examId,
- 'examGroupId'=>$examInfo->exam_group_id,
- 'savedInfoUrl'=>$onlineCard['file_path'],
- 'students'=>$item,
- 'groupId'=>$this->schoolGroupId,
- 'qrcode'=>$onlineCard['is_qrcode_online'],
- 'semesterId'=>$this->semesterId
- );
- $key='zsyas2-online-card-notify';
- $return=sendDataToKafka($key,$arr);
- $updateStudentId=array();
- $updateStudentName=array();
- foreach ($item as $v){
- $updateStudentId[]=$v['student_id'];
- $updateStudentName[]=$v['student_name'];
- }
- if($return){
- $this->sConn->createCommand("update student_answer_card_online set answer_card_online_created=0 where exam_id='" . $examId . "' and student_id in(" . implode(',', $updateStudentId) . ") ")->execute();
- }else{
- $error=array_merge($error,$updateStudentName);
- //$result['msg']='发送任务失败';
- }
- }
- if($error){
- $result['status'] = 1;
- $result['msg'] = '部分学生发送失败';
- }else{
- $result['status'] = 1;
- }
- }else{
- $arr=array(
- 'schoolId'=>$this->schoolId,
- 'examId'=>$examId,
- 'examGroupId'=>$examInfo->exam_group_id,
- 'savedInfoUrl'=>$onlineCard['file_path'],
- 'students'=>$postStudents,
- 'groupId'=>$this->schoolGroupId,
- 'qrcode'=>$onlineCard['is_qrcode_online'],
- 'semesterId'=>$this->semesterId
- );
- $key='zsyas2-online-card-notify';
- $return=sendDataToKafka($key,$arr);
- if($return){
- $result['status'] = 1;
- $this->sConn->createCommand("update student_answer_card_online set answer_card_online_created=0 where exam_id='" . $examId . "' and student_id in(" . implode(',', $students) . ") ")->execute();
- }else{
- $result['msg']='发送任务失败';
- }
- }
- $this->sConn->createCommand("update online_card_multiplex set is_download=1,update_time='".time()."' where multiplex_id='" . $onlineCard['multiplex_id'] . "' ")->execute();
- $this->schoolManager->saveExamProcess($examInfo->exam_group_id,13,time(),$examId,$examInfo->class_id);
- exit(json_encode($result));
- }
- //发送生成在线答题卡任务(全部学生)
- public function actionSendCreateOnlineAllStudents(){
- $examGroupId=Req::post('exam_group_id');
- $result['status']=0;
- if(!$examGroupId || !is_numeric($examGroupId)){
- $result['msg']='参数不正确';
- exit(json_encode($result));
- }
- $exam_data = $this->schoolManager->getExamsByExamGroupId($examGroupId);
- $examIds = array();
- $examClass=array();
- if($exam_data) {
- foreach ($exam_data as $val) {
- $examIds[] = $val['exam_id'];
- $examClass[$val['exam_id']]=$val['class_id'];
- }
- }
- if(!$examIds){
- $result['msg']='未找到考试信息';
- exit(json_encode($result));
- }
- $onlineCard=$this->schoolManager->getAnswerSheetOnline($examGroupId);
- if(!$onlineCard){
- $result['msg']='考试还没有使用在线答题卡';
- exit(json_encode($result));
- }
- $postStudents=$this->sConn->createCommand("select student_id,paper_id,class_id,student_card,school_student_card,exam_id from student_paper_relation where exam_id in(".implode(',',$examIds).") and is_del=0 ")->queryAll();
- if($postStudents){
- foreach ($postStudents as $key =>$val){
- $studentInfo=$this->sConn->createCommand("select `realname` from student_info where student_id='{$val['student_id']}'")->queryRow();
- $postStudents[$key]['student_name']=$studentInfo['realname'];
- $classInfo=$this->sConn->createCommand("select `class_name` from class where class_id='{$val['class_id']}'")->queryRow();
- $postStudents[$key]['class_name']=$classInfo['class_name'];
- if($exam_data[0]['school_card_status']==1){
- $postStudents[$key]['student_card']=$val['school_student_card'];
- }
- }
- }
- $error=array();
- if(count($postStudents)>100){
- $newPushArr=array();
- $newPushArr=array_chunk($postStudents,100);
- foreach ($newPushArr as $item){
- $arr=array(
- 'schoolId'=>$this->schoolId,
- 'examGroupId'=>$examGroupId,
- 'savedInfoUrl'=>$onlineCard['file_path'],
- 'students'=>$item,
- 'groupId'=>$this->schoolGroupId,
- 'qrcode'=>$onlineCard['is_qrcode_online'],
- 'semesterId'=>$this->semesterId
- );
- $key='zsyas2-online-card-notify';
- $return=sendDataToKafka($key,$arr);
- $updateStudentId=array();
- $updateStudentName=array();
- foreach ($item as $v){
- $updateStudentId[]=$v['student_id'];
- $updateStudentName[]=$v['student_name'];
- }
- if($return){
- $this->sConn->createCommand("update student_answer_card_online set answer_card_online_created=0 where exam_id in(".implode(',',$examIds).") and student_id in(" . implode(',', $updateStudentId) . ") ")->execute();
- $this->sConn->createCommand("update online_card_multiplex set is_download=1,update_time='".time()."' where multiplex_id='" . $onlineCard['multiplex_id'] . "' ")->execute();
- }else{
- $error=array_merge($error,$updateStudentName);
- //$result['msg']='发送任务失败';
- }
- }
- if($error){
- $result['status'] = 1;
- $result['msg'] = '部分学生发送失败';
- exit(json_encode($result));
- }else{
- $result['status'] = 1;
- exit(json_encode($result));
- }
- }else{
- $arr=array(
- 'schoolId'=>$this->schoolId,
- 'examGroupId'=>$examGroupId,
- 'savedInfoUrl'=>$onlineCard['file_path'],
- 'students'=>$postStudents,
- 'groupId'=>$this->schoolGroupId,
- 'qrcode'=>$onlineCard['is_qrcode_online'],
- 'semesterId'=>$this->semesterId
- );
- $key='zsyas2-online-card-notify';
- $return=sendDataToKafka($key,$arr);
- if($return){
- $result['status'] = 1;
- $this->sConn->createCommand("update student_answer_card_online set answer_card_online_created=0 where exam_id in(".implode(',',$examIds).") ")->execute();
- $this->sConn->createCommand("update online_card_multiplex set is_download=1,update_time='".time()."' where multiplex_id='" . $onlineCard['multiplex_id'] . "' ")->execute();
- }else{
- $result['msg']='发送任务失败';
- }
- }
- foreach ($examClass as $examId =>$classId){
- $this->schoolManager->saveExamProcess($examGroupId,13,time(),$examId,$classId);
- }
- exit(json_encode($result));
- }
- // // 更新试卷在线答题卡打印状态、时间
- public function actionUpdateOnlinePaperPrintTime() {
- $cid = Req::post("cid");
- $eid = Req::post("eid");
- $type = Req::post("type");
- $getResult = ClassExamPrinter::model()->find('class_id=:cid and exam_id=:eid and type=:type',array(':cid'=>$cid,':eid'=>$eid,':type'=>$type));
- if (!empty($getResult)) {
- $getResult->is_print_online = 1;
- if ($getResult->save()) {
- exit('1');
- } else {
- exit('2');
- }
- }
- }
- //客户端打印在线答题卡
- public function actionPrintPdfOnline(){
- $examId=Req::post('exam_id');
- $students=Req::post('students');
- $className=Req::post('class_name');
- $checkOrder=Req::post('check_order');
- $result['success']=0;
- if(!$examId || !is_numeric($examId)){
- $result['msg']='参数不正确';
- exit(json_encode($result));
- }
- $examInfo = Exam::model()->findByPk($examId);
- if(!$examInfo){
- $result['msg']='未找到考试信息';
- exit(json_encode($result));
- }
- $onlineCard=$this->schoolManager->getAnswerSheetOnline($examInfo->exam_group_id);
- if(!$onlineCard){
- $result['msg']='考试还没有使用在线答题卡';
- exit(json_encode($result));
- }
- if($checkOrder){
- //检查订单
- $orderClass=0;
- if(!$students){
- $allClassStudents=$this->sConn->createCommand("select student_id,class_id from student_paper_relation where exam_id='{$examId}' and is_del=0 ")->queryAll();
- if($allClassStudents){
- foreach ($allClassStudents as $student){
- $students[]=$student['student_id'];
- if(!$orderClass) $orderClass=$student['class_id'];
- }
- }
- }
- $semester=new SSemester();
- $nowsem=$semester->getCurrentSemester();
- $classinfo= ClassModel::model()->find("class_id=:id",array(":id"=>$orderClass));
- $intarr=array(
- "schoolId"=>$this->schoolId,
- "clazzId"=>$orderClass,
- "semester"=>$nowsem['refer_code'],
- "grade"=>$classinfo['grade'],
- "students"=>array(),
- "examTime"=>time(),
- "classify"=>1,
- "subject"=>3,
- );
- $students=$this->getManyProductOrder($intarr,array(1,2,3,31),$students);
- }
- if(!$students || !is_array($students)){
- $students=array();
- $studentPaperRelation=$this->sConn->createCommand("select student_id from student_paper_relation where exam_id='".$examId."' and is_del=0 ")->queryAll();
- if($studentPaperRelation){
- foreach ($studentPaperRelation as $val){
- $students[]=$val['student_id'];
- }
- }
- }
- if(!$students){
- $result['msg']='考试班级没有学生';
- exit(json_encode($result));
- }
- $studentPdf=$this->sConn->createCommand("select student_id,answer_card_online_url from student_answer_card_online where answer_card_online_created=1 and exam_id='".$examId."' and student_id in(".implode(',',$students).") ")->queryAll();
- $studentData=array();
- if($studentPdf){
- foreach ($studentPdf as $val){
- $studentInfo=$this->sConn->createCommand("select `realname` from student_info where student_id='{$val['student_id']}'")->queryRow();
- $studentData[]=array(
- 'studentName'=>$studentInfo['realname'],
- 'studentCode'=>$val['student_id'],
- 'pdfUrl'=>$val['answer_card_online_url']
- );
- }
- }else{
- $result['msg']='答题卡还未生成';
- exit(json_encode($result));
- }
- $result['success']=1;
- $result['className']=$className;
- $result['students']=$studentData;
- $result['studentIds']=$students;
- exit(json_encode($result));
- }
- /**
- * 英语外刊阅读列表
- */
- public function actionEnglish_reading(){
- Url::clean();
- $data = array();
- $printName = Req::get("name");
- $classId = Req::get("classId");
- $grade = (int)Req::get("grade");
- $cg = (int)Req::get('cg');
- $pt = (int)Req::get('pt');
- if(!$cg) $cg=1;
- $newCondition = array();
- if($grade){
- $newCondition[] = 'er.grade='.$grade;
- }
- if($printName){
- $newCondition[] = 'er.name like "%'.$printName.'%"';
- }
- if($classId){
- $newCondition[] = 'er.class_id='.$classId;
- }
- $newCondition[] = 'ers.category='.$cg;
- if($cg==2){
- $newCondition[] = 'ers.product_type='.$pt;
- }
- $resultList = $this->schoolManager->getEnglishReading($newCondition,array('er.create_time desc','er.week_id desc'),9);
- $printList = array();
- if($resultList["rs"]){
- foreach ($resultList['rs'] as $k=>$v) {
- $isTeacher=false;
- //仅经典模式中,基础宝、外刊宝-共性外刊、热点宝-共性外刊有教师讲义
- if($v['recommend_mode']==1 && (($v['product_type']==1) || (in_array($v['product_type'],array(2,3)) && $v['type']==2)) ){
- $isTeacher=true;
- }
- $v['is_teacher']=$isTeacher;
- $printList[$k]=$v;
- }
- }
- if (empty($grade)) {
- $grade = 'ALL';
- }
- $classes = $this->schoolManager->getClasses($grade);
- $data['pages'] = $resultList['pager'];
- $data['page_total'] = $resultList['pager']->rowsCount;
- $data['printList'] = $printList;
- $data["printName"] = $printName;
- $data["classes"] = $classes;
- $data["classId"] = $classId;
- $data["grade"] = $grade;
- $data['printType'] = 'mrv';
- $data['category'] = $cg;
- $data['eProductType'] = $pt;
- //debug($printList);
- $this->render('english_reading',$data);
- }
- /**
- * 英语外刊阅读高一高二设置
- */
- public function actionEnglishReadingSetting(){
- $data = array();
- $time = time();
- // $data['year'] = $year = date("Y");
- // $data['month'] = $month = (int)date("m");
- // $data['week'] = $week = date("W", time()) - date("W", strtotime(date("Y-m-01", time()))) + 1;
- $data_msg = $this->getWeekOnMonth();
- $data['year'] = $data_msg['year'];
- $data['month'] = $data_msg['month'];
- $data['week'] = numToUpper($data_msg['week']);
- $textboookTree = new MongodbEnglishTree();
- $criteria = new EMongoCriteria();
- $textbookData = $textboookTree->find($criteria,array());
- if($textbookData){
- foreach ($textbookData as $doc) {
- foreach($doc->attributes as $key => $value){
- if($key !== '_id'){
- if(isset($value['textbook_id']) && isset($value['name'])){
- $data['textbookNames'][$value['textbook_id']] = $value['name'];
- if(!isset($textbookId)){
- $textbookId = $value['textbook_id'];
- }
- if($textbookId == $value['textbook_id']){
- if(isset($value['module']) && $value['module']){
- foreach($value['module'] as $kk=>$vv){
- $data['moduleNames'][$vv['textbook_module_id']] = $vv['name'];
- if(!isset($moduleId)){
- $moduleId = $vv['textbook_module_id'];
- }
- if($moduleId == $vv['textbook_module_id']){
- if(isset($vv['unit']) && $vv['unit']){
- foreach($vv['unit'] as $kkk=>$vvv){
- $data['unitNames'][$vvv['textbook_unit_id']] = $vvv['name'];
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- $data['printType'] = 'english_reading_setting';
- $this->render('english_reading_setting',$data);
- }
- /**
- * 设置英语外刊阅读高一高二
- */
- public function actionAjaxSaveEnglishReading(){
- $result = array();
- $error = array();
- if (! Yii::app()->request->isAjaxRequest OR ! Yii::app()->request->isPostRequest){
- $error[] = '错误的来源!';
- }else{
- $grade=(int)Req::post('grade');
- $textbookId = (int)Req::post('textbookId');
- $moduleId = (int)Req::post('moduleId');
- $unitId = (int)Req::post('unitId');
- $moduleName = (string)Req::post('moduleName');
- $unitName = (string)Req::post('unitName');
- $classIds = Req::post('selectClassIds');
- $itemIds = (array)Req::post('selectedItemIds');
- $type = (int)Req::post('type');
- $level = (int)Req::post('level');
- $isAnswerSeparate = (int)Req::post('isAnswerSeparate');
- if($itemIds && ($textbookId || $moduleId || $unitId)){
- $error[] = '设置错误1';
- }
- if(!$itemIds && (!$textbookId || !$moduleId || !$unitId)){
- $error[] = '设置错误2';
- }
- if(!$grade){
- $error[] = '请选择年级';
- }
- if(!$classIds){
- $error[] = '请选择班级';
- }
- if(!in_array($type,array(1,2))){
- $error[] = '外刊类别错误';
- }
- if($type == 2){
- if(!in_array($level,array(1,2,3))){
- $error[] = '外刊分级错误';
- }
- }
- }
- if(!$error){
- $time = time();
- // $month = (int)date("m");
- // $week = date("W", time()) - date("W", strtotime(date("Y-m-01", time()))) + 1;
- // $week = date("W");
- // $year = date("Y");
- $date_msg = $this->getWeekOnMonth();
- $year = $date_msg["year"];
- $month = $date_msg["month"];
- $week = $date_msg["week"];
- $weekUpper = numToUpper($week);
- $strModel = new SStudentClassRelation();
- $transaction = $this->sConn->beginTransaction();
- try{
- $weekName = $year.'年'.$month.'月'.'第'.$weekUpper.'周"外刊宝"';
- $reading_id = getUniqueId($this->schoolId);
- $this->sConn->createCommand()->insert('english_reading_setting',array(
- 'reading_id'=>$reading_id,
- 'grade' => $grade,
- 'semester_id' => $this->semesterId,
- 'textbook_id' => $textbookId,
- 'module_id' => $moduleId,
- 'unit_id' => $unitId,
- 'special_ids' => implode(',',$itemIds),
- 'create_time' => $time,
- 'type' => $type,
- 'level'=>$level,
- 'is_answer_separate'=>$isAnswerSeparate
- ));
- foreach($classIds as $k=>$v){
- $weekId = getUniqueId($this->schoolId);
- $this->sConn->createCommand()->insert('english_reading',array(
- 'week_id' => $weekId,
- 'name' => $weekName,
- 'class_id' => $v,
- 'grade' => $grade,
- 'semester_id' => $this->semesterId,
- 'year_num' => $year,
- 'week_num' => $week,
- 'month_num' => $month,
- 'reading_id'=>$reading_id,
- 'create_time' => $time,
- ));
- //获取班级学生
- $stuData = $strModel->getRelationsByClassId_Status_0($v);
- if($stuData){
- foreach($stuData as $kk=>$vv){
- $this->sConn->createCommand()->insert('english_reading_student',array(
- 'week_id' => $weekId,
- 'student_id' => $vv['student_id'],
- ));
- }
- }
- }
- $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'=>$error));exit;
- }else{
- echo json_encode(array('status'=>1));exit;
- }
- }
- /**
- * 外刊主题语境(高三)
- */
- public function actionEnglishReading3(){
- $data = array();
- $time = time();
- $theme_context = array();
- // $data['year'] = $year = date("Y");
- // $data['month'] = $month = (int)date("m");
- // $data['week'] = $week = date("W", time()) - date("W", strtotime(date("Y-m-01", time()))) + 1;
- $data_msg = $this->getWeekOnMonth();
- $data['year'] = $data_msg['year'];
- $data['month'] = $data_msg['month'];
- $data['week'] = numToUpper($data_msg['week']);
- $theme_context_data = $this->aipost('/zsytk2/label', array('type_id' => 3));
- if($theme_context_data && isset($theme_context_data['data']) && $theme_context_data['data']){
- $i = 0;
- foreach($theme_context_data['data'] as $k=>$v){
- if(isset($v['label_id']) && isset($v['content']) && $v['label_id'] && $v['content']){
- $theme_context[$i]['label_id'] = $v['label_id'];
- $theme_context[$i]['content'] = $v['content'];
- $i++;
- }
- }
- }
- $data['theme_context'] = $theme_context;
- $data['printType'] = 'englishreading3';
- $this->render('english_reading_3',$data);
- }
- /**
- * 外刊时间有限设置
- */
- public function actionEnglishReadingTime(){
- $data = array();
- $theme_context = array();
- $data_msg = $this->getWeekOnMonth();
- $data['year'] = $data_msg['year'];
- $data['month'] = $data_msg['month'];
- $data['week'] = numToUpper($data_msg['week']);
- // $theme_context_data = $this->aipost('/zsytk2/label', array('type_id' => 3));
- // if($theme_context_data && isset($theme_context_data['data']) && $theme_context_data['data']){
- // $i = 0;
- // foreach($theme_context_data['data'] as $k=>$v){
- // if(isset($v['label_id']) && isset($v['content']) && $v['label_id'] && $v['content']){
- // $theme_context[$i]['label_id'] = $v['label_id'];
- // $theme_context[$i]['content'] = $v['content'];
- // $i++;
- // }
- // }
- // }
- // $data['theme_context'] = $theme_context;
- $data['printType'] = 'englishreadingtime';
- $this->render('english_reading_time',$data);
- }
- /**
- * 外刊时间优先推送设置
- */
- public function actionAjaxSaveReadingTime(){
- $result = array();
- $error = array();
- if (! Yii::app()->request->isAjaxRequest OR ! Yii::app()->request->isPostRequest){
- $error[] = '错误的来源!';
- }else{
- $grade=(int)Req::post('grade');
- $classIds = Req::post('selectClassIds');
- $type = (int)Req::post('type');
- $level = (int)Req::post('level');
- $isAnswerSeparate = (int)Req::post('isAnswerSeparate');
- if(!$grade){
- $error[] = '请选择年级';
- }
- if(!$classIds){
- $error[] = '请选择班级';
- }
- if(!in_array($type,array(1,2))){
- $error[] = '外刊类别错误';
- }
- if($type == 2){
- if(!in_array($level,array(1,2,3))){
- $error[] = '外刊分级错误';
- }
- }
- }
- if(!$error){
- $time = time();
- $date_msg = $this->getWeekOnMonth();
- $year = $date_msg["year"];
- $month = $date_msg["month"];
- $week = $date_msg["week"];
- $weekUpper = numToUpper($week);
- $strModel = new SStudentClassRelation();
- $transaction = $this->sConn->beginTransaction();
- try{
- $weekName = $year.'年'.$month.'月'.'第'.$weekUpper.'周"外刊宝"';
- $reading_id = getUniqueId($this->schoolId);
- $this->sConn->createCommand()->insert('english_reading_setting',array(
- 'reading_id'=>$reading_id,
- 'grade' => $grade,
- 'semester_id' => $this->semesterId,
- 'textbook_id' => 0,
- 'module_id' => 0,
- 'unit_id' => 0,
- 'special_ids' => '',
- 'create_time' => $time,
- 'type' => $type,
- 'level'=>$level,
- 'is_answer_separate'=>$isAnswerSeparate,
- 'is_time_priority' => 1
- ));
- foreach($classIds as $k=>$v){
- $weekId = getUniqueId($this->schoolId);
- $this->sConn->createCommand()->insert('english_reading',array(
- 'week_id' => $weekId,
- 'name' => $weekName,
- 'class_id' => $v,
- 'grade' => $grade,
- 'semester_id' => $this->semesterId,
- 'year_num' => $year,
- 'week_num' => $week,
- 'month_num' => $month,
- 'reading_id'=>$reading_id,
- 'create_time' => $time,
- ));
- //获取班级学生
- $stuData = $strModel->getRelationsByClassId_Status_0($v);
- if($stuData){
- foreach($stuData as $kk=>$vv){
- $this->sConn->createCommand()->insert('english_reading_student',array(
- 'week_id' => $weekId,
- 'student_id' => $vv['student_id'],
- ));
- }
- }
- }
- $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'=>$error));exit;
- }else{
- echo json_encode(array('status'=>1));exit;
- }
- }
- /*
- * 获取外刊美文产品班级
- */
- public function actionAjaxGetClassesBySettingReading(){
- $grade=(int)Req::post('grade');
- $result=$this->getClassesBySettingReading($grade);
- echo json_encode($result);exit;
- }
- /*
- * 获取外刊美文产品班级
- */
- public function getClassesBySettingReading($grade=1,$gc=1,$pt=1){
- $result = array();
- $error = array();
- //$grade=(int)Req::post('grade');
- // $year = date("Y");
- // $month = (int)date("m");
- // $week = date("W", time()) - date("W", strtotime(date("Y-m-01", time()))) + 1;
- // $week = date("W");
- $data_msg = $this->getWeekOnMonth();
- $year = $data_msg['year'];
- $month = $data_msg['month'];
- $week = $data_msg['week'];
- //获取班级
- $hasSettingClassIds = array();
- $sql="select class_id,count(*) as count from english_reading er";
- $sql.=" left join english_reading_setting ers on er.reading_id= ers.reading_id ";
- $sql.=" where year_num = {$year} and week_num = {$week} and month_num = {$month} ";
- if($gc==1){
- $sql.=" and ers.category=1";
- }else{
- $sql.=" and ers.category=2 and product_type='{$pt}'";
- }
- $sql.=" group by class_id";
- //$sql = "select class_id,count(*) count from english_reading where year_num = {$year} and week_num = {$week} and month_num = {$month} group by class_id";
- $data = $this->sConn->createCommand($sql)->queryAll();
- if($data){
- foreach($data as $k=>$v){
- if($v['count'] > 0){
- $hasSettingClassIds[] = (string)$v['class_id'];
- }
- }
- }
- if($grade){
- //先判断是否走班
- $zouban_sql = "select * from classified where subject_id = 8 and semester_id = '{$this->semesterId}' and grade = {$grade} and `status` = 1";
- $classified_data = $this->sConn->createCommand($zouban_sql)->queryRow();
- if($classified_data){
- $is_zouban = 1;
- $class_type = 2;
- $sql = "select c.class_id,c.class_name "
- . "from class c join class_subject_relation csr on c.class_id=csr.class_id "
- . "where c.semester_id='{$this->semesterId}' and csr.subject_id = 8 and c.grade = {$grade} and c.class_type = 2 and c.is_hide=0 group by c.class_id";
- }else{
- $is_zouban = 0;
- $class_type = 1;
- $sql = "select class_id,class_name from class where semester_id = '{$this->semesterId}' and grade = {$grade} and class_type = 1 and is_hide=0";
- }
- // $sql = "select class_id,class_name from class where semester_id = '{$this->semesterId}' and grade = {$grade} and class_type = {$class_type} and is_hide=0";
- $data = $this->sConn->createCommand($sql)->queryAll();
- if($data){
- $i = 0;
- foreach($data as $k => $v){
- $sql = "select count(student_id) count from student_class_relation where class_id = '{$v['class_id']}' and status = 0";
- $class_student = $this->sConn->createCommand($sql)->queryRow();
- if($class_student && $class_student['count']>0){
- $result[$i]['class_id'] = $v['class_id'];
- $result[$i]['class_name'] = $v['class_name'];
- if(in_array((string)$v['class_id'],$hasSettingClassIds,true)){
- $result[$i]['status'] = 1;
- }else{
- $result[$i]['status'] = 0;
- }
- $i++;
- }
- }
- }
- }
- return $result;
- }
- /**
- * 下载外刊美文个性化学习宝
- */
- public function actionGetEnglishReadingFile(){
- $weekId = (string)Req::get("weekId");
- $studentsIds = (string)Req::get("studentsIds");
- $params = array();
- if(!$weekId){
- echo json_encode(array("success" => 0, "message" => "缺少参数"));
- exit();
- }
- if(!$studentsIds){
- $studentsIds = array();
- $sql = "select student_id from english_reading_student where week_id = '{$weekId}' and is_week_pdf = 1";
- $stuArr = $this->sConn->createCommand($sql)->queryAll();
- if($stuArr){
- foreach($stuArr as $k=>$v){
- $studentsIds[] = $v['student_id'];
- }
- }
- }else{
- $studentsIds = explode(',',$studentsIds);
- }
- if(!$studentsIds || empty($studentsIds)){
- echo json_encode(array("success" => 0, "message" => "无生成的学生"));
- exit();
- }
- $params['weekId'] = $weekId;
- $apiUrl = isset(Yii::app()->params["improve_url"][$this->schoolGroupId]) ? Yii::app()->params["improve_url"][$this->schoolGroupId] : null;
- if(!$apiUrl){
- echo json_encode(array("success" => 0, "message" => "接口配置信息错误"));
- exit();
- }
- $sql = "select class_id,grade,create_time,semester_id from english_reading where week_id = '{$weekId}'";
- $msg = $this->sConn->createCommand($sql)->queryRow();
- $Sem=new SSemester();
- $code= $Sem->conn->createQuery()
- ->from('semester')
- ->where("semester_id = '".$msg['semester_id']."'")
- ->limit(1)
- ->query()
- ->read();
- $intarr=array(
- "schoolId"=>$this->schoolId,
- "clazzId"=>$msg['class_id'],
- "semester"=>$code['refer_code'],
- "grade"=>$msg['grade'],
- "students"=>$studentsIds,
- "examTime"=>$msg['create_time'],
- "classify"=>6,
- "subject"=>8
- );
- $schoolInfo = BusinessSchool::model()->find('school_id=:school_id', array(':school_id' => $this->schoolId));
- if(isset($schoolInfo['is_allow_download']) && ($schoolInfo['is_allow_download']==1)){
- if($studentsIds){
- $params["studentIds"] = $studentsIds;
- }
- }else{
- if(Yii::app()->params["limit_open"]){
- $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]);
- $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr),$basic));
- if(!$rs){
- Yii::app()->jump->error("接口错误");
- }
- if($rs->errCode!="00"){
- echo json_encode(array("success" => 0, "message" => $rs->errMsg));
- exit();
- }
- if(!empty($rs->data)){
- $params["studentIds"]=$rs->data;
- if(count($rs->data)<count($intarr['students'])){
- $limitinfo="购买过的".count($intarr['students'])-count($rs->data)."位学生可下载";
- }
- } else{
- echo json_encode(array("success" => 0, "message" =>"请先购买商品"));
- exit();
- }
- }else{
- if($studentsIds){
- $params["studentIds"] = $studentsIds;
- }
- }
- }
- $params['schoolId'] = $this->schoolId;
- $params['type'] = 3;
- $rs = Curl::post($apiUrl."/rest/download_week_pdf/index", $params);
- if(!($rs = json_decode($rs))){
- $rs = array(
- "success" => 0,
- "message" => "请求接口失败",
- );
- }else{
- //更新下载时间
- if($rs->success==1 || $rs->success==2){
- $time = time();
- if($studentsIds){
- $sql = "update english_reading_student set is_week_download = 1,week_download_time={$time} where week_id = '{$weekId}' and student_id in (".implode(',',$studentsIds).") and week_download_time = 0";
- $this->sConn->createCommand($sql)->execute();
- }
- }
- }
- // if(isset($rs->downloadPath)){
- // if (YII_ENV == 'pro' || YII_ENV == 'production') {
- // $rs->downloadPath = preg_replace('/http\:\/\/zstatic\d{1,2}/','http://zstatic'.$groupId,$rs->downloadPath);
- // }
- // }
- echo json_encode($rs);exit;
- }
- /**
- * 获取当天是第几周(按周一计算)
- */
- public function getWeekOnMonth(){
- $a = time();
- $monDay = $a - ((date('w',$a) == 0 ? 7 : date('w',$a)) - 1) * 24 * 3600;//当前时间周一的时间
- $a_month = date('n',$monDay);//当前周一月份
- $a_year = date('Y',$monDay);//当前周一年份
- $date_now=date('j',$monDay); //得到周一是几号
- $cal_result=ceil($date_now/7); //计算是第几周
- return array("year"=>$a_year,"month"=>$a_month,"week"=>$cal_result);
- }
- /**
- * 重置外刊美文
- */
- public function actionResetEnglishReading(){
- $readingId = (string)Req::get("readingId");
- $data = array();
- $resetCount = 0;
- $productName='';
- if($readingId){
- $sql = "select er.week_id,er.`name`,er.class_id,er.is_reset,c.class_name,ers.product_type,ers.category from english_reading er join english_reading_setting ers on ers.reading_id=er.reading_id join class c on er.class_id = c.class_id where er.reading_id = '{$readingId}'";
- $msg = $this->sConn->createCommand($sql)->queryAll();
- if($msg){
- $i=0;
- foreach($msg as $k=>$v){
- if($v["is_reset"]){
- $resetCount++;
- }
- if(!$productName){
- if($v['category']==2){
- if($v['product_type']==1){
- $productName='基础宝';
- }elseif($v['product_type']==2){
- $productName='外刊宝';
- }elseif($v['product_type']==3){
- $productName='热点宝';
- }
- }else{
- $productName='外刊宝';
- }
- }
- $weekId = $v["week_id"];
- $data[$i]['total_count'] = 0;
- $data[$i]['create_count'] = 0;
- $data[$i]['name'] = $v["name"];
- $sql = "select count(*) total_count,count(case when is_week_pdf = 1 then 1 end) create_count from english_reading_student where week_id = '{$weekId}'";
- $msg_student = $this->sConn->createCommand($sql)->queryRow();
- if($msg_student){
- $data[$i]['total_count'] = $msg_student["total_count"];
- $data[$i]['create_count'] = $msg_student["create_count"];
- }
- $data[$i]['week_id'] = $weekId;
- $data[$i]['class_name'] = $v["class_name"];
- $data[$i]['is_reset'] = $v["is_reset"];
- $i++;
- }
- }
- }
- if(!isset(Yii::app()->session['testFlag']) || Yii::app()->session['testFlag']==1 ){
- $resetCount = 0;
- }
- // debug($data);
- $this->render('english_reading_reset',array("data"=>$data,"resetCount"=>$resetCount,"readingId"=>$readingId,'productName'=>$productName));
- }
- /**
- * 重置外刊美文功能
- */
- public function actionAjaxResetEnglishReading(){
- $result = array();
- $error = array();
- if (! Yii::app()->request->isAjaxRequest OR ! Yii::app()->request->isPostRequest){
- $error[] = '错误的来源!';
- }else{
- $classExam=Req::post('classExam');
- if(!$classExam || !is_array($classExam)){
- $error[] = '请选择班级';
- }
- $redingId=Req::post('readingId');
- if(!$redingId){
- $error[] = '请刷新后再尝试';
- }
- }
- if(!$error){
- $time = time();
- $transaction = $this->sConn->beginTransaction();
- try{
- $sql = "select reading_id,week_id,is_new_version,grade from english_reading where reading_id='{$redingId}' and week_id in (".implode(',',$classExam).")";
- $englishReading = $this->sConn->createCommand($sql)->queryAll();
- if(!$englishReading){
- throw new Exception('无重置外刊阅读推送数据');
- }
- $this->sConn->createCommand("update english_reading set is_all_html = 0,is_reset=1,teacher_general_pdf_path='' where week_id in (".implode(',',$classExam).") ")->execute();
- //重置时common_topic:班级间相同的共性数据 更新为空
- $this->sConn->createCommand("update english_reading_setting set common_topic = '' where reading_id='{$redingId}'")->execute();
- $sql = "update english_reading_student set week_download_time = 0,is_week_download=0,is_week_html=0,week_html_path='',is_week_pdf=0,week_pdf_path='' where week_id in (".implode(',',$classExam).") ";
- $this->sConn->createCommand($sql)->execute();
- //重置后清除已存在的下载任务
- $task_sql = "delete from pack_product_task where school_id ={$this->schoolId} and unique_key in (". implode(",", $classExam).") and product_type=10";
- $this->conn->createCommand($task_sql)->execute();
- $weekIds=array();
- $grade=0;
- foreach($englishReading as $item){
- if($item['is_new_version']){
- $weekIds[]=$item['week_id'];
- $grade=$item['grade'];
- }
- }
- $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'=>$error));exit;
- }else{
- //新设置重置才发消息
- if($weekIds && $grade) {
- $kafkaData = array(
- 'school_id' => $this->schoolId,
- 'msg_type' => 90,//90:重置 1:新设置
- 'grade' => $grade,
- 'subject_id' => 8,
- 'send_type' => 'english_reading',
- 'product_type' => array(19),
- 'gp_group_id' => $redingId,//reading_id
- 'gp_ids' => $weekIds,//week_id
- );
- sendDataToKafka("php-product-english-reading-html", $kafkaData);
- }
- echo json_encode(array('status'=>1));exit;
- }
- }
- /**
- * 外刊美文选择学生
- */
- public function actionSelectStuByEnglishReading(){
- $data = array();
- $sname = (string)Req::get("sname"); //学生名字
- $weekId = (string)Req::get("weekId");
- if(!$weekId){
- Yii::app()->jump->error('参数错误!');
- }
- //获取班级名称以及周后推送名称
- $sql = "select er.name,c.class_name,er.grade,er.class_id,er.create_time,er.semester_id,ers.category,ers.product_type from english_reading er join english_reading_setting ers on ers.reading_id=er.reading_id join class c on er.class_id = c.class_id where er.week_id = '{$weekId}'";
- $names = $this->sConn->createCommand($sql)->queryRow();
- if(!$names){
- $names = array();
- $names['name'] = '';
- $names['class_name'] = '';
- $names['grade'] = 0;
- }else{
- $data['name'] = isset($names['name']) && isset($names['class_name'])?$names['class_name'].$names['name']:'';
- }
- $sql = "select student_id,is_week_pdf,product_type from english_reading_student where week_id = '{$weekId}'";
- $relateStudent = $this->sConn->createCommand($sql)->queryAll();
- $studentIds = array();
- $stuIsPdf = array();
- if($relateStudent){
- foreach ($relateStudent as $studentInfo) {
- $studentIds[] = (string)$studentInfo['student_id'];
- $stuIsPdf[(string)$studentInfo['student_id']] = $studentInfo['is_week_pdf'];
- $productTypeName='';
- if($studentInfo['product_type']==1){
- $productTypeName='基础宝';
- }elseif($studentInfo['product_type']==2){
- $productTypeName='外刊宝';
- }elseif($studentInfo['product_type']==3){
- $productTypeName='热点宝';
- }
- $productTypeNames[(string)$studentInfo['student_id']] = $productTypeName;
- }
- }
- if($studentIds){
- $studentNames = SStudentInfo::model()->getStudentNames($studentIds); //求学生名字
- if($studentNames){
- if($sname){
- $i = 1;
- foreach($studentNames as $k=>$v){
- if(strpos($v,$sname) !== false){
- $data['list'][$i]['stu_id'] = (string)$k;
- $data['list'][$i]['stu_name'] = $v;
- $data['list'][$i]['name'] = $names['class_name'].$v.$names['name'];
- $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$k])?$stuIsPdf[(string)$k]:0;
- $data['list'][$i]['product_type_name'] = isset($productTypeNames[(string)$k])?$productTypeNames[(string)$k]:'';
- $i++;
- }
- }
- }else{
- $i = 1;
- foreach($studentNames as $k=>$v){
- $data['list'][$i]['stu_id'] = (string)$k;
- $data['list'][$i]['stu_name'] = $v;
- $data['list'][$i]['name'] = $names['class_name'].$v.$names['name'];
- $data['list'][$i]['is_pdf'] = isset($stuIsPdf[(string)$k])?$stuIsPdf[(string)$k]:0;
- $data['list'][$i]['product_type_name'] = isset($productTypeNames[(string)$k])?$productTypeNames[(string)$k]:'';
- $i++;
- }
- }
- }
- }
- $Sem=new SSemester();
- $code= $Sem->conn->createQuery()
- ->from('semester')
- ->where("semester_id = '".$names['semester_id']."'")
- ->limit(1)
- ->query()
- ->read();
- $classify=6;
- if($names['category']==2){
- if($names['product_type']==1){
- $classify=57;
- }elseif($names['product_type']==2){
- $classify=61;
- }elseif($names['product_type']==3){
- $classify=58;
- }
- }
- $intarr=array(
- "schoolId"=>$this->schoolId,
- "clazzId"=>$names['class_id'],
- "semester"=>$code['refer_code'],
- "grade"=>$names['grade'],
- "students"=>$studentIds,
- "examTime"=>$names['create_time'],
- "classify"=>$classify,
- "subject"=>8
- );
- $basic = imsBasicAuth($this->schoolId.'_'.Yii::app()->session['coachInfo']['coach_name'],Yii::app()->params["zsy_api_key"]);
- $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr),$basic));
- if(!$rs){
- Yii::app()->jump->error("接口错误");
- }
- if($rs->errCode!="00"){
- Yii::app()->jump->error($rs->errMsg);
- }
- if(!empty($rs->data)){
- $data['limitstu']=$rs->data;
- }
- $data['weekId'] = $weekId;
- $data['sname'] = $sname;
- $data['printType'] = 'english_reading';
- $this->render('english_reading_stu',$data);
- }
- public function actionPhpInfo(){
- phpinfo();exit;
- }
- public function actionSendKafka(){
- $conf = new RdKafka\Conf();
- $conf->set('metadata.broker.list', '192.168.1.239:9092,192.168.1.247:9092,192.168.1.248:9092');
- $producer = new RdKafka\Producer($conf);
- $topic = $producer->newTopic("zsyte-marking-finished-notify");
- $topic->produce(RD_KAFKA_PARTITION_UA, 0, '{"examGroupId":"582547523696889856","schoolId":3912,"examIds":["582547523780775936","5825475237807759363"]}');
- $producer->poll(0);
- $result = $producer->flush(10000);
- var_dump($result);
- if (RD_KAFKA_RESP_ERR_NO_ERROR !== $result) {
- throw new \RuntimeException('Was unable to flush, messages might be lost!');
- }
- }
- //考试扫描异常处理状态查看
- public function actionGetTaskDetail(){
- $examGroupId = Req::get('exam_group_id');
- $grade = Req::get('grade');
- $branch = Req::get('branch');
- $taskModel=new AScanTask();
- $task=$taskModel->getTaskByExamGroupId($examGroupId);
- if($task){
- $task=$task->attributes;
- if($task['operator']){
- $user=AssistUser::model()->findByPk($task['operator']);
- $task['user']=$user->real_name;
- }else{
- $task['user']='--';
- }
- //答题卡任务耗时
- if($task['scan_task_apply_time']){
- if($task['scan_task']>2){
- if($task['scan_task_update_time'] && ($task['scan_task_update_time']-$task['scan_task_apply_time'])>0){
- $task['AstConsuming']=consuming($task['scan_task_update_time'],$task['scan_task_apply_time']);
- }else{
- $task['AstConsuming']='--';
- }
- }elseif($task['scan_task']==2){
- if($task['scan_task_apply_time'] && (time()-$task['scan_task_apply_time'])>0){
- $task['AstConsuming']=consuming(time(),$task['scan_task_apply_time']);
- }else{
- $task['AstConsuming']='--';
- }
- }
- }else{
- $task['AstConsuming']='--';
- }
- }
- //读取扫描数量
- $count=$this->schoolManager->getStudentCountByExamGroupId($examGroupId,1);
- $task['count']=$count;
- $data['task']=$task;
- $data['exam_group_id']=$examGroupId;
- $_num= '';
- $use_version = '';
- if(isset(Yii::app()->session['coachInfo']->use_version))
- {
- $use_version = Yii::app()->session['coachInfo']->use_version;
- }else
- {
- $use_version = Yii::app()->session['coachInfo']['use_version'];
- }
- if(!$use_version)
- {
- $use_version = 100;
- }
- $version_number = implode('',explode('.',$use_version));
- if(strlen($version_number)<7)
- {
- for($i=0;$i<7-strlen($version_number);$i++)
- {
- $_num.='0';
- }
- }
- $version_number=(int)$version_number.$_num;
- $data['version_number']=$version_number;
- $data['grade']=$grade;
- $data['branch']=$branch;
- $this->render('scan_detail',$data);
- }
- /**
- * 下载英语外刊教师外刊
- *
- */
- public function actiondown_load() {
- set_time_limit(0);
- $gradeRel = array(1=>"高一",2=>"高二",3=>"高三");
- $weekId = safe_replace(Yii::app()->request->getQuery('weekId'));
- $sql = "select teacher_general_pdf_path,grade,is_new_version,reading_id,class_id from english_reading where week_id = '{$weekId}'";
- $week_info = $this->sConn->createCommand($sql)->queryRow();
- if (empty($week_info['teacher_general_pdf_path'])) {
- if($week_info['is_new_version']){//新版本
- $this->new_en_reading($weekId,$week_info);
- exit;
- }
-
- $grade = isset($gradeRel[$week_info['grade']]) ? $gradeRel[$week_info['grade']] : '';
- $sql = "select distinct topic_id from student_reading_topic where week_id = '{$weekId}' order by create_time asc";
- $topic_info = $this->sConn->createCommand($sql)->queryAll();
- if (empty($topic_info)) {
- Yii::app()->jump->error('学生外刊宝尚未生成');
- } else {
- $push_topics = _array_column($topic_info, 'topic_id');
- $_params = array('isFormat' => 1, 'isTird' => 1, 'isNewEnglish' => 1, 'isNoReplaceLable' => 1);
- $topicDetails = $this->apiBrainPost('/topic/batchAll', array('topicIds' => $push_topics, 'subjectId' => $this->subjectId, 'params' => $_params), 25, true);
- if (!$topicDetails) {
- echo json_encode(array("status" => 1, "error" => "获取接口batchALL无数据!"));
- exit();
- } elseif (isset($topicDetails['status']) && $topicDetails['status'] == 0) {
- echo json_encode(array("status" => 1, "error" => $topicDetails['error'][0]));
- exit();
- } else {
- foreach($topicDetails as $node=>$td){
- if (isset($td['slave'])) {
- $topicDetails[$node]['diff_str'] = $this->getLargeDifficulty($td['slave']);
- }else {
- $topicDetails[$node]['diff_str'] = '';
- }
- }
- $data = array();
- $data['all_topics'] = $push_topics;
- $data['reading_detail'] = $topicDetails;
- $html_name = 'en_reading';
- $html = $this->renderPartial("{$html_name}", $data,true);
- unset($data);
- $htmlpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/reading/'; //存放生成的HTML路径
- $pdfpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/reading/' . $this->schoolId . "/"; //存放生成的PDF路径
- $pdfurl = '/upload/tmpDir/reading/' . $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 .= $weekId . ".html";
- $f = fopen($htmlpath, "w");
- fwrite($f, $html);
- fclose($f);
- $htmlurl = '/upload/tmpDir/reading/' . $weekId . ".html"; //访问HTML的路径
- //防止exec 执行命令行导致中文乱码
- $locale='en_US.UTF-8';
- setlocale(LC_ALL,$locale);
- putenv('LC_ALL='.$locale);
- if (Yii::app()->basePath == "E:\wamp64\www\zsyas2\protected") {//本地的basePath
- $htmlurl = " http://local.zsyas2teaching.com" . '/' . $weekId . '.html';
- $pdffname = $weekId . ".pdf";
- $pdfpath = $pdfpath . $pdffname;
- $pdfurl = $pdfurl . $pdffname;
- $commond = Yii::app()->params['phantomjs'] . " "
- . Yii::app()->params['html2pdf'] . " "
- . " {$htmlurl}"
- . " {$pdfpath}"
- . " 176mm*250mm '".$grade." || ".date('Y-m-d',time())."'";
- } else {
- $htmlurl = "http://" . $_SERVER['SERVER_NAME'] . $htmlurl;
- $pdffname = $weekId . ".pdf";
- $pdfpath = $pdfpath . $pdffname;
- $pdfurl = $pdfurl . $pdffname;
- $commond = Yii::app()->params['phantomjs_server_en'] . " "
- . Yii::app()->basePath . '/../js/html2pdf_en.js' . " "
- . " {$htmlurl}"
- . " {$pdfpath}"
- . ' 176mm*250mm "'.$grade.'|||'.date('Y-m-d',time()).'"';
- }
- exec($commond, $res, $code);
- if(isset($res[0])){
- $isBool = false;
- foreach ($res as $msg) {
- if (strpos($msg, 'succeed') !== false) {
- $isBool = true;
- }
- }
- if ($isBool) {//命令返回成功
- if (file_exists($pdfpath)) {
- // $pdfurl=iconv("GBK", "UTF-8",$pdfurl);
- $repdf = $weekId . ".pdf";
- $rename = 'zsyas2/reading/' . $this->schoolId . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/' . uniqid() . '.' . $repdf;
- $ucloud = new HuaweiCloud();
- $uploadInfo = $ucloud->putFile($rename, $pdfpath);
- if ($uploadInfo['status'] == 0) {
- $pdfurl = "http://" . $_SERVER['SERVER_NAME'] . $pdfurl;
- $this->sConn->createCommand()->update("english_reading", array("teacher_general_pdf_path" => $pdfurl), "week_id = '{$weekId}'");
- $week_info['teacher_general_pdf_path'] = $pdfurl;
- }else{
- $pdfurl = $uploadInfo['url'];
- $this->sConn->createCommand()->update("english_reading", array("teacher_general_pdf_path" => $pdfurl), "week_id = '{$weekId}'");
- $week_info['teacher_general_pdf_path'] = $pdfurl;
- @unlink($pdfpath);
- }
- @unlink($htmlpath);
- } else {
- @unlink($htmlpath);
- echo json_encode(array("status" => 1, "error" => "PDF文件未找到!"));
- exit;
- }
- } else {
- @unlink($htmlpath);
- echo json_encode(array("status" => 1, "error" => "PDF创建失败!", 'exec_rs' => json_encode($res)));
- exit;
- }
- } else {
- echo json_encode(array("status" => 1, "error" => "PDF创建失败!"));
- exit;
- }
- }
- }
- }
- if($week_info['teacher_general_pdf_path']){
- $url = $week_info['teacher_general_pdf_path'];
- header('Content-Description: File Transfer');
- header('Content-Type: application/vnd.android.package-archive');
- header('Content-Disposition: attachment; filename=' . $this->filter_file_name('外刊宝教师版') . ".pdf");
- header('Content-Transfer-Encoding: binary');
- header('Expires: 0');
- header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
- header('Pragma: public');
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
- curl_setopt($ch, CURLOPT_WRITEFUNCTION, function ($ch, $buffer) {
- echo $buffer;
- return strlen($buffer);
- });
- curl_exec($ch);
- curl_close($ch);
- }else{
- Yii::app()->jump->error('尚未生成PDF');
- }
- }
- /**
- * 英语周推新版教师版下载
- */
- public function newEnTeacherWeek($weekId='',$weekMsg=array()){
- $sql = "select week_pdf_path from english_week_student where week_id='{$weekId}' and student_id=0";
- $week_info = $this->sConn->createCommand($sql)->queryRow();
- if($week_info && $week_info['week_pdf_path']){
- $classId = $weekMsg['class_id'];
- $sql = "select class_name from class where class_id = '{$classId}'";
- $classInfo = $this->sConn->createCommand($sql)->queryRow();
- $className = $classInfo ? $classInfo['class_name'] : '';
- $fileName = $className.'_周推教师版';
- $url = $week_info['week_pdf_path'];
- if(isset(Yii::app()->params["static_url"][$this->schoolGroupId]) && Yii::app()->params["static_url"][$this->schoolGroupId]){
- $url = Yii::app()->params["static_url"][$this->schoolGroupId].'/'.$url;
- }else{
- Yii::app()->jump->error('接口配置信息错误');
- }
- $handle = @fopen($url, 'r');
- if(!$handle){
- Yii::app()->jump->error('尚未生成PDF');
- }
- header('Content-Description: File Transfer');
- header('Content-Type: application/vnd.android.package-archive');
- header('Content-Disposition: attachment; filename=' . $this->filter_file_name($fileName) . ".pdf");
- header('Content-Transfer-Encoding: binary');
- header('Expires: 0');
- header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
- header('Pragma: public');
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
- curl_setopt($ch, CURLOPT_WRITEFUNCTION, function ($ch, $buffer) {
- echo $buffer;
- return strlen($buffer);
- });
- curl_exec($ch);
- curl_close($ch);
- }else{
- Yii::app()->jump->error('周推教师版尚未生成');
- }
- }
- /**
- * 英语周推教师版下载
- * @throws CException
- */
- public function actionTeacherWeek(){
- set_time_limit(0);
- $weekId = safe_replace(Yii::app()->request->getQuery('weekId'));
- $sql = "select * from teacher_week_extend where week_id = '{$weekId}'";
- $week_info = $this->sConn->createCommand($sql)->queryAll();
- $teacher_extend_arr = array();
- foreach($week_info as $info)
- {
- $content = $info['content'];
- $content = json_decode($content,true);
- $teacher_extend_arr[$info['type']] = $content;
- }
- $sql = "select grade,teacher_general_pdf_path,class_id,set_id from english_week where week_id = '{$weekId}'";
- $week_info = $this->sConn->createCommand($sql)->queryRow();
- $sql = "select class_id,semester_id,words_type,is_new_version from english_week_setting where id = '{$week_info['set_id']}'";
- $week_setting_info = $this->sConn->createCommand($sql)->queryRow();
- if($week_setting_info['is_new_version']){
- $this->newEnTeacherWeek($weekId,$week_info);
- exit;
- }
- $words_type = $week_setting_info['words_type'];
-
- $sql = "select ps_id from product_class_relation where class_id={$week_setting_info['class_id']} and semester_id={$week_setting_info['semester_id']} and set_type=7 order by ps_id desc limit 1";
- $arr = $this->sConn->createCommand($sql)->queryRow();
- $product_setting = '';
- if($arr){
- $sql = "select custom_config from product_setting where ps_id={$arr['ps_id']}";
- $product_setting = $this->sConn->createCommand($sql)->queryRow();
- $product_setting = $product_setting ? $product_setting['custom_config'] : '';
- }
- $setting = array(
- 'moduleName'=>'晨读词汇',
- 'moduleType'=>'english_4',
- 'setting'=>array(
- 'vocabularySelfTest' =>array( //词汇自测
- "coreVocabulary"=>array( //核心词汇开关
- "onOff" =>1,
- "vocabularyUse" =>1 //词汇运用
- ),
- "keyPhrases" =>1 //重点短语
- ),
- "focusOnGrammar" =>array(//语法聚焦
- "singleSentenceGrammar" =>1, //单句语法填空
- "grammaticalFillIn" =>1 //语法填空
- ),
- "writingTraining" =>array(//写作训练
- "commentsOnGoodSentences" =>1, // 佳句点拨
- "actualCombatDrill" =>1 //实战演练
- ),
- "extensiveReadingOfForeignJournals" =>array( //外刊泛读
- "accumulationOfNewWords" =>1, //新词积累
- "appreciationOfGoldenSentences" =>1, //金句赏析
- "fullTextTranslation" =>1, //全文翻译
- ),
- )
- );
- $product_setting = $product_setting ? json_decode($product_setting, true) : $setting;
- //$product_setting = $setting;
- //核心词区分派生非派生
- $single_words_derivative = array();
- if(isset($teacher_extend_arr[1])){
- foreach($teacher_extend_arr[1] as $k=>$v){
- if(isset($v['is_derivative'])){
- $single_words_derivative[$v['is_derivative']][] = $v;
- }
- }
- }
-
- $html_data = array(
- 'cur_grade' => $week_info['grade'],
- 'single_words' => isset($teacher_extend_arr[1]) ? $teacher_extend_arr[1] : array(),
- 'phrase' => isset($teacher_extend_arr[2]) ? $teacher_extend_arr[2] : array(),
- 'topic_type_six' => isset($teacher_extend_arr[4]) ? $teacher_extend_arr[4] : array(),
- 'topic_type_nineteen'=> isset($teacher_extend_arr[3]) ? $teacher_extend_arr[3] : array(),
- 'writing_training' => isset($teacher_extend_arr[5]) ? $teacher_extend_arr[5] : array(),
- 'single_translation' => isset($teacher_extend_arr[6]) ? $teacher_extend_arr[6] : array(),
- 'essayDetail' => isset($teacher_extend_arr[7]) ? $teacher_extend_arr[7] : array(),
- 'word_single_translation' => isset($teacher_extend_arr[8]) ? $teacher_extend_arr[8] : array(), //词汇运用(单句翻译)
- 'word_grammar_blank' => isset($teacher_extend_arr[9]) ? $teacher_extend_arr[9] : array(), //词汇运用(单句语法填空)
- 'word_spelling' => isset($teacher_extend_arr[20]) ? $teacher_extend_arr[20] : array(), //词汇运用(单词拼写)
- 'complete_sentence' => isset($teacher_extend_arr[21]) ? $teacher_extend_arr[21] : array(), //词汇运用(完成句子)
- 'product_setting' => $product_setting['setting'],
- 'words_type'=>$words_type,
- 'single_words_derivative'=>$single_words_derivative
- );
-
- $classId = $week_info['class_id'];
- $sql = "select class_name from class where class_id = '{$classId}'";
- $classInfo = $this->sConn->createCommand($sql)->queryRow();
- $className = $classInfo ? $classInfo['class_name'] : '';
- if (empty($week_info['teacher_general_pdf_path'])) {
- $sql = "select topic_id from teacher_week where week_id = '{$weekId}' order by topic_id desc";
- $topic_info = $this->sConn->createCommand($sql)->queryAll();
- if (empty($topic_info)) {
- Yii::app()->jump->error('周推教师版尚未生成');
- } else {
- $html_name = 'english_week_teacher';
- //$this->render("{$html_name}", $html_data);exit;
- $html = $this->renderPartial("{$html_name}", $html_data,true);
- unset($html_data);
- $htmlpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/reading/'; //存放生成的HTML路径
- $pdfpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/reading/' . $this->schoolId . "/"; //存放生成的PDF路径
- $pdfurl = '/upload/tmpDir/reading/' . $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);
- }
- }
- $gradeRel = array(1=>"高一",2=>"高二",3=>"高三");
- $grade = isset($gradeRel[$week_info['grade']]) ? $gradeRel[$week_info['grade']] : '';
- $htmlpath .= $weekId . ".html";
- $f = fopen($htmlpath, "w");
- fwrite($f, $html);
- fclose($f);
- $htmlurl = '/upload/tmpDir/reading/' . $weekId . ".html"; //访问HTML的路径
- $locale='en_US.UTF-8';
- setlocale(LC_ALL,$locale);
- putenv('LC_ALL='.$locale);
- if (Yii::app()->basePath == 'D:\xampp\htdocs\zsy-as2-php\protected') {//本地的basePath
- $htmlurl = " http://192.168.1.48:8077/upload/tmpDir/reading" . '/' . $weekId . '.html';
- $pdffname = $weekId . ".pdf";
- $pdfpath = $pdfpath . $pdffname;
- $pdfurl = $pdfurl . $pdffname;
- $commond = Yii::app()->params['phantomjs'] . " "
- . Yii::app()->params['html2pdf'] . " "
- . " {$htmlurl}"
- . " {$pdfpath}"
- . ' 176mm*250mm "'.$grade.'|||'.date('Y-m-d',time()).'"';
- } else {
- $htmlurl = "http://" . $_SERVER['SERVER_NAME'] . $htmlurl;
- $pdffname = $weekId . ".pdf";
- $pdfpath = $pdfpath . $pdffname;
- $pdfurl = $pdfurl . $pdffname;
- $commond = Yii::app()->params['phantomjs_server_en'] . " "
- . Yii::app()->basePath . '/../js/html2pdf_en.js' . " "
- . " {$htmlurl}"
- . " {$pdfpath}"
- . ' 176mm*250mm "'.$grade.' '.$className.'|||'.date('Y-m-d',time()).'"';
- }
- exec($commond, $res, $code);
- if(isset($res[0])){
- $isBool = false;
- foreach ($res as $msg) {
- if (strpos($msg, 'succeed') !== false) {
- $isBool = true;
- }
- }
- if ($isBool) {//命令返回成功
- if (file_exists($pdfpath)) {
- // $pdfurl=iconv("GBK", "UTF-8",$pdfurl);
- $repdf = $weekId . ".pdf";
- $rename = 'zsyas2/reading/' . $this->schoolId . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/' . uniqid() . '.' . $repdf;
- $ucloud = new HuaweiCloud();
- $uploadInfo = $ucloud->putFile($rename, $pdfpath);
- if ($uploadInfo['status'] == 0) {
- $pdfurl = "http://" . $_SERVER['SERVER_NAME'] . $pdfurl;
- $this->sConn->createCommand()->update("english_week", array("teacher_general_pdf_path" => $pdfurl), "week_id = '{$weekId}'");
- $week_info['teacher_general_pdf_path'] = $pdfurl;
- }else{
- $pdfurl = $uploadInfo['url'];
- $this->sConn->createCommand()->update("english_week", array("teacher_general_pdf_path" => $pdfurl), "week_id = '{$weekId}'");
- $week_info['teacher_general_pdf_path'] = $pdfurl;
- @unlink($pdfpath);
- }
- @unlink($htmlpath);
- } else {
- @unlink($htmlpath);
- echo json_encode(array("status" => 1, "error" => "PDF文件未找到!"));
- exit;
- }
- } else {
- @unlink($htmlpath);
- echo json_encode(array("status" => 1, "error" => "PDF创建失败!", 'exec_rs' => json_encode($res)));
- exit;
- }
- } else {
- echo json_encode(array("status" => 1, "error" => "PDF创建失败!"));
- exit;
- }
- }
- }
- if($week_info['teacher_general_pdf_path']){
- $fileName = $className.'_周推教师版';
- $url = $week_info['teacher_general_pdf_path'];
- header('Content-Description: File Transfer');
- header('Content-Type: application/vnd.android.package-archive');
- header('Content-Disposition: attachment; filename=' . $this->filter_file_name($fileName) . ".pdf");
- header('Content-Transfer-Encoding: binary');
- header('Expires: 0');
- header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
- header('Pragma: public');
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
- curl_setopt($ch, CURLOPT_WRITEFUNCTION, function ($ch, $buffer) {
- echo $buffer;
- return strlen($buffer);
- });
- curl_exec($ch);
- curl_close($ch);
- }else{
- Yii::app()->jump->error('尚未生成PDF');
- }
- }
- //数学公式
- public function actionAjaxGetMathtex()
- {
- $error = array();
- $result = array();
- $mathtex = Req::post('mathtex');
- if (strlen($mathtex)) {
- $data = $this->apiPost('/mathtex/url', array('mathtex' => $mathtex,"is_fdfs"=>1), 1);
- if (isset($data->status) or isset($data->error)) {
- $error[] = $data->error;
- } elseif (! $data) {
- $error[] = '系统错误!';
- } else {
- $result['url'] = $data['url'].'?'.$mathtex;
- $result['width'] = $data['width'];
- $result['height'] = $data['height'];
- }
- } else {
- $error[] = '参数不能为空';
- }
- header('Content-Type: application/json');
- if ($error) {
- echo json_encode(array('status' => 0, 'error'=> implode('<br/>', $error)));
- } else {
- echo json_encode($result);
- }
- }
- //重新发送扫描任务
- public function actionResendScanTask(){
- $examGroupId = Req::post('exam_group_id');
- $result['status']=0;
- $taskModel=new AScanTask();
- $task=$taskModel->getTaskByExamGroupId($examGroupId)->attributes;
- if(!$task){
- $result['msg']='任务数据异常!';
- exit(json_encode($result));
- }
- //判断剩余任务量
- $studentTask=new AStudentScanTask();
- $taskCount=$studentTask->getTaskCount($examGroupId);
- if($taskCount['surplus']==0){
- $result['msg']='当前任务已无异常数据!';
- exit(json_encode($result));
- }
- $taskStatus=1;
- if($task['operator']){
- $taskStatus=2;
- }else{
- $taskStatus=1;
- }
- if($taskModel->updateAll(array('scan_task'=>$taskStatus,'resend_time'=>time(),'update_time'=>time()),'exam_group_id=:eid',array(':eid'=>$examGroupId))){
- $result['status']=1;
- }
- exit(json_encode($result));
- }
- //撤回发送扫描任务
- public function actionCancelScanTask(){
- $examGroupId = Req::post('exam_group_id');
- $result['status']=0;
- $taskModel=new AScanTask();
- $task=$taskModel->getTaskByExamGroupId($examGroupId)->attributes;
- if(!$task){
- $result['msg']='任务数据异常!';
- exit(json_encode($result));
- }
- if($task['scan_task']==2){
- $result['msg']='任务已受理不可撤回';
- exit(json_encode($result));
- }
- if($task['scan_task']==3){
- $result['msg']='任务已完成不可撤回';
- exit(json_encode($result));
- }
- if($task['scan_task']==4){
- $result['msg']='任务已撤回,请匆重复操作';
- exit(json_encode($result));
- }
- if($taskModel->updateAll(array('scan_task'=>4),'exam_group_id=:eid',array(':eid'=>$examGroupId))){
- $result['status']=1;
- }
- exit(json_encode($result));
- }
- //读取考试剩余任务量
- public function actionGetSurplus(){
- $examGroupId = Req::post('exam_group_id');
- $studentTask=new AStudentScanTask();
- $result['status']=0;
- $taskCount=$studentTask->getTaskCount($examGroupId);
- if($taskCount['surplus']==0){
- $result['msg']='当前任务已无异常数据!';
- exit(json_encode($result));
- }else{
- $result['status']=1;
- $result['msg']='数据正常!';
- exit(json_encode($result));
- }
- }
- //获取学校百万校
- public function checkSchoolBW(){
- $http = http('customer/school/coach/official/detail', 'GET', $this->authUsername);
- $response = formatResponse($http);
- $data = $response['data'];
- if(isset($data['isHuge']) && $data['isHuge']==1){
- return 1;
- }
- return 0;
- }
- private function getLargeDifficulty($slave)
- {
- if (empty($slave) || !is_array($slave)) {
- return false;
- }
- $difficultyLevel = array(
- 1 => array(
- 'range' => 0.90,
- 'name' => '超易',
- ),
- 2 => array(
- 'range' => 0.75,
- 'name' => '易',
- ),
- 3 => array(
- 'range' => 0.65,
- 'name' => '中档偏易',
- ),
- 4 => array(
- 'range' => 0.50,
- 'name' => '中档偏难',
- ),
- 5 => array(
- 'range' => 0.40,
- 'name' => '难',
- ),
- 6 => array(
- 'range' => 0.20,
- 'name' => '超难',
- ),
- );
- $difficulty = 0;
- $SlaveTopicDifficultySum = 0;
- $slaveCount = 0;
- foreach($slave as $slkey=>$slval){
- //计算大题难度
- if(!isset($slval['difficulty'])) $slval['difficulty'] = 0;
- if(isset($difficultyLevel[$slval['difficulty']]) && $slval['difficulty']) {
- $slaveCount++;
- $SlaveTopicDifficultySum += $difficultyLevel[$slval['difficulty']]['range'];
- }
- }
- if($SlaveTopicDifficultySum>0 && $slaveCount>0){
- $averageDiff=$SlaveTopicDifficultySum/$slaveCount;
- $difficulty=$this->diffChangeSix($averageDiff,8);
- }
- return $this->diffNameSix($difficulty);
- }
- private function diffChangeSix($degree,$sub_id = 3)
- {
- if ($sub_id == 3) {
- if($degree>=0 && $degree<=0.2){
- $diff = 6;
- }elseif($degree>0.2 && $degree<=0.4){
- $diff = 5;
- }elseif($degree>0.4 && $degree<=0.6){
- $diff = 4;
- }elseif($degree>0.6 && $degree<=0.7){
- $diff = 3;
- }elseif($degree>0.7 && $degree<=0.85){
- $diff = 2;
- }elseif($degree>0.85 && $degree<=1){
- $diff = 1;
- }else{
- $diff = 6;
- }
- }else{
- if($degree<=0.2){
- return 6;
- }elseif($degree<=0.4){
- return 5;
- }elseif($degree<=0.5){
- return 4;
- }elseif($degree<=0.65){
- return 3;
- }elseif($degree<=0.75){
- return 2;
- }else{
- return 1;
- }
- }
- return $diff;
- }
- private function diffNameSix($degree)
- {
- $diff_name_arr = array('1'=>'超易','2'=>'易','3'=>'中档偏易','4'=>'中档偏难','5'=>'难','6'=>'超难');
- return isset($diff_name_arr[$degree]) ? $diff_name_arr[$degree] : '';
- }
- //复用的答题卡编辑后保存
- private function saveMultiplex(){
- $examGroupId = isset($_POST['examGroupId'])?$_POST['examGroupId']:'';
- $multiplexId = isset($_POST['multiplexId'])?$_POST['multiplexId']:''; //复用模板id
- $pdfUrl =isset($_POST["pdf_url"])?$_POST["pdf_url"]:0;
- $positionJson=isset($_POST['position'])?$_POST['position']:'';
- $useQrCode=isset($_POST['useQrCode'])?$_POST['useQrCode']:0;
- //上传答题卡相关文件
- $files=$this->uploadAnswerCardPdf($examGroupId,$positionJson,$pdfUrl);
- $this->sConn->createCommand("update online_card_multiplex set file_path='{$files['ucloudZipUrl']}',online_card_pdf='{$files['ucloudPdfUrl']}',`position`='{$files['positionUrl']}',is_qrcode_online='".$useQrCode."',update_time='".time()."' where multiplex_id='{$multiplexId}'")->execute();
- $thirdAnswer= $this->sConn->createCommand("select multiplex_id from third_answer_sheet where exam_group_id='{$examGroupId}'")->queryRow();
- if($thirdAnswer['multiplex_id']==$multiplexId){
- $this->sConn->createCommand("update third_answer_sheet set file_path='{$files['ucloudZipUrl']}',online_card_pdf='{$files['ucloudPdfUrl']}',`position`='{$files['positionUrl']}',is_qrcode_online='".$useQrCode."',update_time='".time()."' where multiplex_id='{$multiplexId}'")->execute();
- }
- echo json_encode(array('success'=>1,'message'=>'保存成功','multiplex_id'=>$multiplexId,'exam_group_id'=>$examGroupId));exit;
- }
- // 上传答题卡相关文件
- private function uploadAnswerCardPdf($examGroupId,$positionJson,$pdfUrl){
- $card_file=array();
- if (empty($_FILES)) {
- $error['message'] = '未找到上传文件!';
- echo json_encode($error);exit();
- }else {
- // debug($_FILES);
- foreach ($_FILES as $k => $v) {
- if (isset($v) && !empty($v)) {
- if (!isset($v['size']) || $v['size'] >= 8388608) {
- $error['message'] = '文件超过8M!';
- echo json_encode($error);
- exit();
- }
- $ext = substr($v['name'], strrpos($v['name'], '.') + 1);
- if (!isset($v['name']) || !in_array($ext, array('doc', 'docx', 'pdf', 'bmp', 'jpg', 'jpeg', 'png', 'txt'))) {
- $error['message'] = '文件格式不正确!';
- echo json_encode($error);
- exit();
- }
- if ($ext == 'pdf') {
- $card_pdf = "upload/ThirdSheet/" . $examGroupId . '_'.time().'.pdf';
- if (!move_uploaded_file($v["tmp_name"], $card_pdf)) {
- $error['message'] = '保存Pdf文件失败!';
- echo json_encode($error);
- exit();
- }
- } else {
- $card_file[] = $v;
- }
- }
- }
- $fixName = 'upload/tmpDir/ThirdSheet/' . date('Y') . '/' . date('m') . '/' . date('j') . '/';
- $ucloudPdfUrl = '';
- if (!file_exists($fixName)) {
- mkdir($fixName, 0777, true);
- }
- $zipFileName = $examGroupId .'_'.time().'.zip';
- $pathName = $fixName . $zipFileName;
- $zip = new ZipArchive;
- $zip->open($pathName, ZipArchive::CREATE);
- foreach ($card_file as $k => $v) {
- $zip->addFile($v['tmp_name'], iconv('utf-8', 'gbk//ignore', $v['name']));
- }
- $zip->addFromString('json.txt', $positionJson);
- $zip->close();
- //FIXME 20191204
- $ucloud = new HuaweiCloud();
- //上传压缩包
- $rename = 'zsyas2/cardonline/' . $this->schoolId . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/' . $zipFileName;
- $uploadInfo = $ucloud->putFile($rename, $pathName);
- @unlink($pathName);
- if ($uploadInfo['status'] == 0) {
- $error['success'] = 0;
- $error['message'] = '答题卡文件上传失败! ';
- $error['data']=$uploadInfo;
- echo json_encode($error);
- exit();
- } else {
- $ucloudZipUrl = $uploadInfo['url'];
- }
- //上传Pdf
- if ($pdfUrl) {
- $ucloudPdfUrl=$pdfUrl;
- // $card_pdf = "upload/ThirdSheet/" . $examGroupId . '.pdf';
- // $content = file_get_contents($pdfUrl);
- //
- // file_put_contents($card_pdf, $content);
- //
- // $uploadPdfName = 'zsyas2/cardonline/' . $this->schoolId . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/' . time() . '.pdf';
- // $uploadInfo = $ucloud->putFile($uploadPdfName, $card_pdf);
- //
- // if ($uploadInfo['status'] == 0) {
- // @unlink($card_pdf);
- // $error['success'] = 0;
- // $error['message'] = '答题卡PDF文件上传失败!';
- // echo json_encode($error);
- // exit();
- // } else {
- // @unlink($card_pdf);
- // $uploadInfo['url'] = str_replace("%2F", "/", $uploadInfo['url']);
- // $ucloudPdfUrl = $uploadInfo['url'];
- // }
- }
- //单独上传position.txt
- if($positionJson){
- $positionTxt="upload/ThirdSheet/" .$examGroupId.'_'.time().'.txt' ;
- file_put_contents($positionTxt, $positionJson);
- $uploadTxtName = 'zsyas2/cardonline/'.$this->schoolId.'/'. date('Y') . '/' . date('m') . '/' . date('d').'/' .time().'.txt' ;
- $uploadInfo = $ucloud->putFile($uploadTxtName,$positionTxt);
- if ($uploadInfo['status'] == 0) {
- @unlink($positionTxt);
- $error['success']=0;
- $error['message'] = 'Position文件上传失败!';
- echo json_encode($error);exit();
- }else{
- @unlink($positionTxt);
- $uploadInfo['url'] = str_replace("%2F","/",$uploadInfo['url']);
- $ucloudTxtUrl=$uploadInfo['url'];
- }
- }
- }
- return array(
- 'ucloudZipUrl'=>$ucloudZipUrl,
- 'ucloudPdfUrl'=>$ucloudPdfUrl,
- 'positionUrl'=>$ucloudTxtUrl
- );
- }
- //加载考试未上传学生
- public function actionAjaxLoadNoUploadStudent(){
- $examGroupId = Req::post('exam_group_id');
- $page=intval(Req::post('page'));
- $isDel=intval(Req::post('is_del'));
- $classId=Req::post('class_id');
- if(!$page) $page=1;
- $result=array();
- $result['status']=0;
- if(!$examGroupId){
- $result['msg']='考试id不能为空';
- exit(json_encode($result));
- }
- $data=$this->schoolManager->getNoUploadStudentByGroupId($examGroupId,$page,$isDel,$classId);
- if($data){
- $result['status']=1;
- $result['data']=$data;
- }
- exit(json_encode($result));
- }
- //删除考试学生,全部班级
- public function actionDelExamStudent(){
- $examGroupId = Req::post('examGroupId');
- $studentIds=Req::post('studentsIds');
- $examId=Req::post('examId');
- $result['status']=0;
- if(!$examId){
- $examIds = $this->schoolManager->getExamsIdsByExamGroupId($examGroupId);
- if($examIds){
- $rs=$this->schoolManager->delStudentPaperByStudentAndExamIds($studentIds,$examIds);
- }
- $sendJsonArr = array(
- 'school_id' => $this->schoolId,
- 'send_type' => 'zsyas',
- 'update_type' => 2,
- 'exam_group_id' => $examGroupId,
- 'exam_id_arr' => $examIds,
- 'student_id_arr' => $studentIds
- );
- }else{
- $rs=$this->schoolManager->delStudentPaperByStudentAndExamIds($studentIds,$examId);
- $sendJsonArr = array(
- 'school_id' => $this->schoolId,
- 'send_type' => 'zsyas',
- 'update_type' => 2,
- 'exam_group_id' => $examGroupId,
- 'exam_id_arr' => array($examId),
- 'student_id_arr' => $studentIds
- );
- }
- if($rs){
- if(Yii::app()->params['handle_log_on_off'])
- {
- writeFileLog(jsonEncode(array(
- "examGroupId" => $examGroupId,
- "operate_project" => 'zsyas2',
- "school_id" => $this->schoolId,
- "title" => '删除考试学生,全部班级',
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $this->getRoute(),
- "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
- "date"=>date('Y-m-d H:i:s')
- )));
- }
- $result['status']=1;
- sendStudentCacheQueue($sendJsonArr);
- }
- exit(json_encode($result));
- }
- //下载学生导出excel
- public function actionDownloadSelectStudent(){
- $examGroupId = Req::get('examGroupId');
- $studentIds=Req::get('studentsIds');
- $studentIds=explode(',',$studentIds);
- if(!$studentIds || !$examGroupId){
- $result['status']=0;
- exit(json_encode($result));
- }
- $exam_data = $this->schoolManager->getExamsByExamGroupId($examGroupId);
- $rs=$this->schoolManager->getExcelStudent($studentIds,$examGroupId);
- $excel = new Excel();
- $fileName = $exam_data[0]['name']."未上传学生";
- $excel->export($rs, $fileName);
- }
- //批量删除所有未上传考生
- public function actionDelAllNotUploadStudent(){
- $examGroupId = Req::post('examGroupId');
- $result['status']=0;
- $examIds = $this->schoolManager->getExamsIdsByExamGroupId($examGroupId);
- $studentIds=array();
- if($examIds){
- $rs=$this->schoolManager->delStudentPaperByExamGroupId($examIds);
- $studentIds=$this->schoolManager->getStudentPaperByExamGroupId($examIds);
- }
- $sendJsonArr = array(
- 'school_id' => $this->schoolId,
- 'send_type' => 'zsyas',
- 'update_type' => 2,
- 'exam_group_id' => $examGroupId,
- 'exam_id_arr' => $examIds,
- 'student_id_arr' => $studentIds
- );
- if($rs){
- if(Yii::app()->params['handle_log_on_off'])
- {
- writeFileLog(jsonEncode(array(
- "examGroupId" => $examGroupId,
- "operate_project" => 'zsyas2',
- "school_id" => $this->schoolId,
- "title" => '删除所有未上传考生',
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $this->getRoute(),
- "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
- "date"=>date('Y-m-d H:i:j')
- )));
- }
- $result['status']=1;
- sendStudentCacheQueue($sendJsonArr);
- }
- exit(json_encode($result));
- }
- //获取在线答题卡接口token
- public function actionGetOnlineToken(){
- $token=getOnlineToolToken($this->schoolId);
- if($token){
- $result['status']=1;
- $result['data']=$token;
- }else{
- $result['status']=0;
- $result['msg']='token读取失败';
- }
- exit(json_encode($result));
- }
- //更新考试准考证类型
- public function actionChangeStudentCardType(){
- $examGroupId = Req::post('examGroupId');
- $schoolCard = Req::post("schoolCard");
- $schoolCardLength = intval(Req::post("schoolCardLength"));
- if(!$examGroupId)
- $this->output(0, "参数错误[1]");
- if($schoolCard==1 && !$schoolCardLength){
- $this->output(0, "准考证位数不能为空");
- }
- $exam_group_array = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId));
- if(!$exam_group_array )
- {
- $this->output(0, "非法数据");
- }
- if($exam_group_array['upload_status']>0){
- $this->output(0, "已上传成绩不能修改考号类型");
- }
- if(!in_array($schoolCard,array(0,1))) $this->output(0, "考号类型不正确");
- $examDetail=Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId));
- if(Yii::app()->params['handle_log_on_off'])
- {
- writeFileLog(jsonEncode(array(
- "exam_group_id" => (string)$examGroupId,
- "operate_project" => 'zsyas2',
- "school_id" => $this->schoolId,
- "title" => '更改考号类型',
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $this->getRoute(),
- "operate_sql" => json_encode(array('update'=>array(
- 'exam'=>array('school_card_status'=>$schoolCard),
- ))),
- "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
- "date"=>date('Y-m-d H:i:s')
- )));
- }
- $transaction = $this->sConn->beginTransaction();
- try{
- Exam::model()->updateAll(array('school_card_status'=>$schoolCard,'school_card_length'=>$schoolCardLength),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId));
- $transaction->commit();
- }catch(Exception $e)
- {
- $transaction->rollBack();
- $this->output(0, "更改失败");
- }
- $this->output(1, "更改成功");
- }
- //学生成绩转移读取学生列表
- public function actionGetUploadedStudent(){
- $examGroupId = Req::post('examGroupId');
- if(!$examGroupId)
- $this->output(0, "参数错误[1]");
- $examIds=array();
- $exam_data = $this->schoolManager->getExamsByExamGroupId($examGroupId);
- if(!$exam_data) $this->output(0, "考试不存在");
- foreach ($exam_data as $val){
- $examIds[]=$val['exam_id'];
- }
- if($exam_data[0]['school_card_status']==1){
- $fieldName='school_student_card';
- }else{
- $fieldName='student_card';
- }
- $uploaded=array();
- $noUploaded=array();
- $students=$this->schoolManager->getAllStudentPaperByExamIds($examIds);
- if($students){
- foreach ($students as $val){
- if($val['is_feedback']==1){
- $uploaded[]=array(
- 'student_id'=>$val['student_id'],
- 'student_card'=>$val[$fieldName],
- 'student_name'=>$val['realname']
- );
- }else{
- $noUploaded[]=array(
- 'student_id'=>$val['student_id'],
- 'student_card'=>$val[$fieldName],
- 'student_name'=>$val['realname']
- );
- }
- }
- }
- if(!$uploaded){
- $this->output(0, "考试还未上传成绩");
- }
- if(!$noUploaded){
- $this->output(0, "考试没有未上传的学生");
- }
- $this->output(1, "success",array('data'=>array('uploaded'=>$uploaded,'noUploaded'=>$noUploaded)));
- }
- //交换学生成绩之移形换影大法!
- public function actionAjaxTransferStudentRs(){
- $examGroupId = Req::post('examGroupId');
- $uploadStudentId = Req::post('uploadStudentId');
- $noUploadStudentId = Req::post('noUploadStudentId');
- if(!$examGroupId)
- $this->output(0, "参数错误[1]");
- if(!$uploadStudentId || !$noUploadStudentId) $this->output(0, "请先选择参与转移的学生");
- $examGroupArray = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId));
- $examIds=array();
- $exam_data = $this->schoolManager->getExamsByExamGroupId($examGroupId);
- if(!$exam_data) $this->output(0, "考试不存在");
- $examStatus=array();
- foreach ($exam_data as $val){
- $examIds[]=$val['exam_id'];
- $examStatus[(string)$val['exam_id']]=$val['status'];
- }
- if($examGroupArray->mark_type==3 && $examGroupArray->mark_status==2){
- $this->output(0, "本场考试已完成阅卷,需要先恢复阅卷状态,再转移学生成绩");
- }
- $isAllSelect=1; //全部客观题判断
- //获取paper 表数据
- $paperData = SPaper::model()->find('exam_id=:exam_id',array(':exam_id'=>$examIds[0]));
- $paperTopic=SPaperTopicRelation::model()->findAll('paper_id=:paper_id',array(':paper_id'=>$paperData->paper_id));
- if(!$paperTopic){
- Yii::app()->jump->error('未找到考试信息!');
- }
- //选择题类型判断
- $allSubjectType=array();
- if($examGroupArray['qxk_paper_id']>0){
- $allSubjectType=array(1,2,3,4,12);
- }else{
- $allSubjectType=array(1,2,11);
- }
- foreach ($paperTopic as $item){
- if(!in_array($item->type,$allSubjectType)){
- $isAllSelect=0;
- break;
- }
- }
- $studentPaper=$this->schoolManager->getAllStudentPaperByExamIds($examIds,array($uploadStudentId,$noUploadStudentId));
- $uploadStudentData=array();
- $noUploadStudentData=array();
- if($studentPaper){
- foreach ($studentPaper as $item){
- if(strcmp($item['student_id'],$uploadStudentId)==0){
- $uploadStudentData=$item;
- }elseif(strcmp($item['student_id'],$noUploadStudentId)==0){
- $noUploadStudentData=$item;
- }
- }
- }
- if($examGroupArray->mark_type==4 && $examStatus[$uploadStudentData['exam_id']]==1){
- $this->output(0, $uploadStudentData['realname']."所在班级已完成阅卷,需要先恢复阅卷状态,再转移学生成绩");
- }
- //开始转移
- $transcation = $this->sConn->beginTransaction();
- try {
- //读取原学生成绩数据
- $uploadStudentRs=$this->sConn->createCommand("select * from student_paper_relation where student_id='{$uploadStudentId}' and exam_id='{$uploadStudentData['exam_id']}'")->queryRow();
- $setValue=array(
- "complete_count='{$uploadStudentRs['complete_count']}'",
- "right_count='{$uploadStudentRs['right_count']}'",
- "partial_right_count='{$uploadStudentRs['partial_right_count']}'",
- "wrong_count='{$uploadStudentRs['wrong_count']}'",
- "scoring='{$uploadStudentRs['scoring']}'",
- "lost_score='{$uploadStudentRs['lost_score']}'",
- "is_feedback=1",
- "feedback_time='{$uploadStudentRs['feedback_time']}'",
- "student_img_paper='{$uploadStudentRs['student_img_paper']}'",
- "is_complete='{$uploadStudentRs['is_complete']}'",
- "complete_time='{$uploadStudentRs['complete_time']}'",
- );
- $sourceSetValue=array(
- "complete_count='0'",
- "right_count='0'",
- "partial_right_count='0'",
- "wrong_count='0'",
- "scoring='0'",
- "lost_score='0'",
- "is_feedback=0",
- "feedback_time='0'",
- "student_img_paper='0'",
- "is_complete='0'",
- "complete_time='0'",
- );
- $this->sConn->createCommand("update student_paper_topic_rs set student_id='{$noUploadStudentId}',paper_id='{$noUploadStudentData['paper_id']}' where student_id='{$uploadStudentId}' and paper_id='{$uploadStudentData['paper_id']}'")->execute();
- $this->sConn->createCommand("update student_paper_relation set ".implode(',',$sourceSetValue)." where student_id='{$uploadStudentId}' and paper_id='{$uploadStudentData['paper_id']}'")->execute();
- $updateSql="update student_paper_relation set ".implode(',',$setValue)." where student_id='{$noUploadStudentId}' and paper_id='{$noUploadStudentData['paper_id']}'";
- $this->sConn->createCommand($updateSql)->execute();
- //判断未上传学生班级状态
- $noUploadExam=$this->sConn->createCommand("select upload_status,subject_id from exam where exam_id='".$noUploadStudentData['exam_id']."'")->queryRow();
- if($noUploadExam['upload_status']==0){
- if($examGroupArray->mark_type>0){
- $this->sConn->createCommand("update exam set upload_status=1,status=4 where exam_id='".$noUploadStudentData['exam_id']."'")->execute();
- }else{
- $this->sConn->createCommand("update exam set upload_status=1,status=1,complete_time='".time()."' where exam_id='".$noUploadStudentData['exam_id']."'")->execute();
- }
- }
- //同步阅卷数据
- if($examGroupArray->mark_type>0 && !$isAllSelect){
- $params=array(
- 'examGroupId'=>$examGroupId,
- 'sourceStudentId'=>$uploadStudentId,
- 'targetStudentId'=>$noUploadStudentId,
- 'schoolId'=>$this->schoolId,
- 'targetClazzId'=>$noUploadStudentData['class_id']
- );
- if($examGroupArray->qxk_paper_id>0){
- //查询班级
- $classInfo=$this->sConn->createCommand("select class_name from class where class_id='".$noUploadStudentData['class_id']."'")->queryRow();
- //班级执教教师
- $teacherClassData=$this->sConn->createCommand("select teacher_id from teacher_class_relation where class_id='".$noUploadStudentData['class_id']."'")->queryAll();
- if ($teacherClassData) {
- foreach ($teacherClassData as $v) {
- $teacherIds[$v['teacher_id']] = $v['teacher_id'];
- }
- }
- if ($noUploadExam['subject_id']) {
- if (in_array($noUploadExam['subject_id'], array(3, 6, 51))) {
- $subjectId = 3;
- } else {
- $subjectId = $noUploadExam['subject_id'];
- }
- }
- $teacherSubjectData=$this->sConn->createCommand("select teacher_id,subjects,teacher_name from teacher where teacher_id in(".implode(',',$teacherIds).") and subjects='{$subjectId}'")->queryRow();
- if (!$teacherSubjectData) {
- $teacherSubjectData=$this->sConn->createCommand("select teacher_id,subjects,teacher_name from teacher where teacher_id='{$examGroupArray['teacher_id']}'")->queryRow();
- }
- $params['targetStudentName']=$noUploadStudentData['realname'];
- $params['targetClazzId']=$noUploadStudentData['class_id'];
- $params['targetClazzName']=$classInfo['class_name'];
- $params['targetTeacherId']=$teacherSubjectData['teacher_id'];
- $params['targetTeacherName']=$teacherSubjectData['teacher_name'];
- $rs=http('/qxk/marking/exam/replace-marking','PUT',$this->schoolId,$params,'cgi');
- }else{
- $rs=http('/teacher/marking/v2/replace-marking','PUT',$this->schoolId,$params,'cgi');
- }
- $rs=json_decode($rs);
- if(Yii::app()->params['handle_log_on_off'])
- {
- writeFileLog(jsonEncode(array(
- "exam_group_id" => (string)$examGroupId,
- "operate_project" => 'zsyas2',
- "school_id" => $this->schoolId,
- "title" => '转移成绩',
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $this->getRoute(),
- "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
- "zsyapi_return"=>$rs,
- "date"=>date('Y-m-d H:i:s')
- )));
- }
- if(!isset($rs->errCode) || $rs->errCode !='00')
- {
- throw new Exception($rs->errMsg);
- }else{
- $transcation->commit();
- }
- }else{
- $transcation->commit();
- }
- if($examGroupArray->mark_type==0){
- $kafkaData=array(
- 'schoolId'=>$this->schoolId,
- 'examGroupId'=>$examGroupId,
- 'generateTime'=>time()*1000
- );
- sendDataToKafka("xbkc-academic-offline-generate-report",$kafkaData);
- }
- $this->output(1, "转移成功");
- } catch (Exception $e) {
- $transcation->rollback();
- $this->output(0, "转移失败");
- }
- }
- /**
- * 生成产品消息
- * @return mixed
- */
- public function actionSendProductHtml()
- {
- $examGroupId = Req::post('examGroupId');
- $examId = Req::post('examId');
- $sendMsg=array(
- 'school_id'=>$this->schoolId,
- 'msg_type'=>3,
- 'subject_id'=>Yii::app()->session['session_subject_id'],
- 'send_type'=>'exam',
- 'exam_group_id'=>$examGroupId,
- 'exam_ids'=>array($examId)
- );
- sendDataToKafka('xbkc-php-product-html',$sendMsg);
- return true;
- }
-
- //获取多种指定产品权限
- protected function getManyProductOrder($params,$classify=array(),$studentIds=array())
- {
- $intarr = array();
- $orderIds = array();
- if ($classify) {
- foreach ($classify as $item) {
- $params['students'] = $studentIds;
- $params['classify'] = $item;
- $intarr[] = $params;
- }
- }
- $basic = imsBasicAuth($this->schoolId . '_' . Yii::app()->session['coachInfo']['coach_name'], Yii::app()->params["zsy_api_key"]);
- $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_product_limit_url"], json_encode($intarr), $basic), true);
- if (isset($rs['errCode']) && $rs['errCode'] == "00" && isset($rs['data']) && $rs['data']) {
- foreach ($rs['data'] as $r) {
- $orderIds = array_merge($orderIds, $r);
- }
- }
- return $orderIds;
- }
- //下载全学科试卷解析
- public function actionDownloadPaper(){
- $examGroupId = Req::post('examGroupId');
- $paperSheet =Req::post('paperSheet');
- $downloadType =Req::post('downloadType');
- $wordType = Req::post('wordType');
- $isPrint = Req::post('isPrint');
- $examGroup=SExamGroup::model()->find('exam_group_id=:eg_id',array('eg_id'=>$examGroupId));
- if(!$examGroup) returnMsg(0,'考试id不存在');
- $exam = Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId));
- $paper=SPaper::model()->find('exam_id=:e_id',array(':e_id'=>$exam['exam_id']));
- $paperTopic=$this->sConn->createCommand("select topic_id,`type`,`order`,score,stem_id,`no` from paper_topic_relation where paper_id='".$paper['paper_id']."' order by `type` asc,`order` asc")->queryAll();
- $alias=array();
- $tplData=json_decode($exam['tpl_data'],true);
- $selectTopicGroup=array();
- if(isset($tplData['new_items'])){
- foreach ($tplData['new_items'] as $item){
- if(isset($item['fullAlias'])){
- if(is_numeric($item['fullAlias'])){
- $alias[$item['id']]=$item['fullAlias'];
- }else{
- $alias[$item['id']]=$item['stemAlias'];
- }
- }else{
- $alias[$item['id']]=$item['alias'];
- if($item['stemId']==$item['topicId']){
- $stemAlias[$item['id']]=$item['alias'];
- }else{
- $stemAlias[$item['id']]=$item['stemAlias'].$item['alias'];
- }
- }
- if(isset($item['sameAliasNo']) && $item['sameAliasNo']){
- $selectTopicGroup[$item['id']]=$item['sameAliasNo'];
- }
- }
- }
- $topicIds=array();
- if($paperTopic)
- {
- foreach($paperTopic as $k=>$v)
- {
- if(isset($v['stem_id']) && $v['stem_id']){
- $topicId=$v['stem_id'];
- }else{
- $topicId=$v['topic_id'];
- }
- $topicIds[]=$topicId;
- $topicNumber[(string)$v['topic_id']]=array(
- 'topic_id'=>$v['topic_id'],
- 'type'=>$v['type'],
- 'order'=>$v['order'],
- 'score'=>$v['score'],
- );
- }
- }else{
- returnMsg(0,'请先创建答题卡');
- }
- //$topicDetail=$this->schoolManager->getTopics($topicIds,false,$exam->subject_id);
- $topicDetail=$this->schoolManager->getQxkPaperTopics(array_values($topicIds));
- foreach ($topicDetail as $item){
- if(!isset($topicType[$item['typeId']])){
- $topicType[$item['typeId']]=array(
- 'typeName'=>$item['typeName'],
- 'description'=>'',
- 'topics'=>array()
- );
- }
- $topic=array();
- $id=(string)number_format($item['topicId'],0,'','');
- $topic['topicId']=$id;
- if(isset($topicNumber[$id])){
- $topic['score']=$topicNumber[$id]['score'];
- $order=$topicNumber[$id]['order'];
- $topicType[$item['typeId']]['order']=$order;
- if(isset($alias[$order])){
- $topic['topicNo']=$alias[$order];
- }else{
- $topic['topicNo']=$order;
- }
- //判断选做题
- if(isset($selectTopicGroup[$topicNumber[$id]['order']])){
- $topic['groupId']=$selectTopicGroup[$topicNumber[$id]['order']];
- }
- }
- if(isset($item['slaveList']) && $item['slaveList']){
- foreach ($item['slaveList'] as $val){
- $slave=array();
- if(isset($val['slaveList']) && $val['slaveList']){
- foreach ($val['slaveList'] as $third){
- $thirdSlave=array();
- $thirdSlave['topicId']=(string)number_format($third['topicSlaveId'],0,'','');
- if(isset($topicNumber[(string)$thirdSlave['topicId']])){
- $thirdSlave['score']=$topicNumber[(string)$thirdSlave['topicId']]['score'];
- $thirdOrder=$topicNumber[(string)$thirdSlave['topicId']]['order'];
- if(isset($alias[$thirdOrder])){
- $thirdSlave['topicNo']=$alias[$thirdOrder];
- }else{
- $thirdSlave['topicNo']=$thirdOrder;
- }
- if(!isset($topicType[$item['typeId']]['order'])){
- $topicType[$item['typeId']]['order']=$topicNumber[(string)$thirdSlave['topicId']]['order'];
- }
- if(isset($topicNumber[(string)$thirdSlave['topicId']]['scores'])){
- $thirdSlave['scores']=$topicNumber[(string)$thirdSlave['id']]['scores'];
- }
- if(!isset($topic['topicNo'])){
- $topic['topicNo']= $thirdSlave['topicNo'];
- }
- //判断选做题
- if(isset($selectTopicGroup[$topicNumber[(string)$thirdSlave['topicId']]['order']])){
- $thirdSlave['groupId']=$selectTopicGroup[$topicNumber[(string)$thirdSlave['topicId']]['order']];
- }
- }
- $slave['slave'][]=$thirdSlave;
- }
- }else{
- if(isset($topicNumber[(string)$val['topicSlaveId']])){
- $slave['topicId']=$val['topicSlaveId'];
- $slave['score']=$topicNumber[(string)$val['topicSlaveId']]['score'];
- $slaveOrder=$topicNumber[(string)$val['topicSlaveId']]['order'];
- if(isset($alias[$slaveOrder])){
- $slave['topicNo']=$alias[$slaveOrder];
- }else{
- $slave['topicNo']=$slaveOrder;
- }
- if(!isset($topicType[$item['typeId']]['order'])){
- $topicType[$item['typeId']]['order']=$slaveOrder;
- }
- if(!isset($topic['topicNo'])){
- $topic['topicNo']= $slave['topicNo'];
- }
- //判断选做题
- if(isset($selectTopicGroup[$topicNumber[(string)$val['topicSlaveId']]['order']])){
- $slave['groupId']=$selectTopicGroup[$topicNumber[(string)$val['topicSlaveId']]['order']];
- }
- }
- }
- $topic['slave'][]=$slave;
- }
- }
- $topicType[$item['typeId']]['topics'][]=$topic;
- }
- $lastOrder = $this->_array_column($topicType,'order');
- array_multisort($lastOrder,SORT_ASC,$topicType);
- //拆分选做题
- if($selectTopicGroup){
- $selectTopicType=array();
- $selectTopicType['typeName']='选做题';
- $selectTopicType['topics']=array();
- foreach ($topicType as $key => $item){
- foreach ($item['topics'] as $vk => $val){
- if(isset($val['groupId'])){
- unset($val['groupId']);
- $selectTopicType['topics'][]=$val;
- unset($topicType[$key]['topics'][$vk]);
- $selectTopicType['order']=$val['topicNo'];
- }
- }
- if(count($topicType[$key]['topics'])==0){
- unset($topicType[$key]);
- }
- }
- $topicType[17]=$selectTopicType;
- }
- //计算小题数量
- foreach ($topicType as $key => $item){
- $topicNumber=0;
- $scores=0;
- foreach ($item['topics'] as $k => $val){
- if(isset($val['slave'])){
- foreach ($val['slave'] as $v){
- if(isset($v['slave'])){
- foreach ($v['slave'] as $value){
- if(isset($value['score'])){
- $scores+=$value['score'];
- }
- $topicNumber++;
- }
- }else{
- if(isset($v['score'])){
- $scores+=$v['score'];
- }
- $topicNumber++;
- }
- }
- unset($topicType[$key]['topics'][$k]['slave']);
- }else{
- if($key==17){
- $scores=$val['score'];
- }else{
- $scores+=$val['score'];
- }
- $topicNumber++;
- }
- }
- //选做题(每小题2分,共2分,本题包括A、B两小题,请选定其中一小题,并在相应的答题区域作答。若多做,则按作答的第一小题评分。解答应写出文字说明、证明过程或演算步骤)
- if($key==17){
- $topicType[$key]['description']='每小题'.$scores.'分,共'.$scores.'分,本题包括A、B两小题,请选定其中一小题,并在相应的答题区域作答。若多做,则按作答的第一小题评分。解答应写出文字说明、证明过程或演算步骤';
- }else{
- $topicType[$key]['description']='本大题共'.$topicNumber.'小题,共'.$scores.'分';
- }
- }
- $topicType=array_values($topicType);
- if($paperSheet==0){
- $paperOrientation=1;
- }elseif($paperSheet==2){
- //A4横版
- $paperSheet=0;
- $paperOrientation=0;
- }elseif($paperSheet==1){
- $paperOrientation=null;
- }
- $postParam=array(
- 'subjectId'=>$exam['subject_id'],
- 'downloadType'=>$downloadType,
- 'paperSheet'=>$paperSheet,
- 'wordType'=>$wordType,
- 'paperOrientation'=>$paperOrientation,
- 'subPaperName'=>'',
- 'hasBindLine'=>0,
- 'hasSealFlag'=>0,
- 'attentionInfo'=>'',
- 'paperName'=>$exam['name'],
- 'examTime'=>$tplData['times'],
- 'totalScore'=>$tplData['scores'],
- 'createBy'=>$tplData['author'],
- 'applyBy'=>'',
- 'teacherId'=>$examGroup['teacher_id'],
- 'semesterId'=>$this->semesterId,
- 'types'=>$topicType,
- 'isZxhx'=>3
- );
- $header=array('X-Basic-V:2');
- $cgi=Yii::app()->params['cgi'];
- $username=$cgi['username'];
- $password=$cgi['password'];
- if($isPrint){
- $url = $cgi['domain'].'dmw/qxk/download/mathtype-pdf';
- }else{
- $url = $cgi['domain'].'dmw/qxk/download/mathtype-word';
- }
- $rs = $this->CrmApiPost($url,$postParam,$username,$password,'POST',$header);
- if(isset($rs->errCode) && $rs->errCode=='00'){
- $this->schoolManager->saveExamProcess($examGroupId,14,time());
- if($isPrint){
- //组装打印参数
- $printData=array();
- $printData['typeId']=18;
- $printData['productType']=60001;
- $printData['params']=array(
- 'classIds'=>array(),
- 'url'=>$rs->data,
- 'name'=>$exam['name'],
- 'subjectId'=>$exam['subject_id'],
- 'examGroupId'=>$exam['exam_group_id'],
- );
- returnMsg(1,'success',$printData);
- }else{
- returnMsg(1,'success',$rs->data);
- }
- }else{
- returnMsg(0,$rs->errMsg);
- }
- }
- function _array_column(array $array, $column_key, $index_key=null){
- $result = array();
- foreach($array as $arr) {
- if(!is_array($arr)) continue;
- if(is_null($column_key)){
- $value = $arr;
- }else{
- $value = $arr[$column_key];
- }
- if(!is_numeric($value)){
- $value=intval($value);
- }
- if(!is_null($index_key)){
- $key = $arr[$index_key];
- $result[$key] = $value;
- }else{
- $result[] = $value;
- }
- }
- return $result;
- }
- //读取考试班级产品设置相同题
- public function findExamClassSameTrain($examGroupId,$subject=3){
- if(in_array($subject,$this->mathSubjectId)){
- $subject=3;
- }
- $classes=$this->sConn->createCommand("select class_id from exam where exam_group_id='{$examGroupId}'")->queryAll();
- if($classes){
- //读取产品设置版本
- $productSetEdition=$this->sConn->createCommand("select switch from producut_set_edition limit 1")->queryRow();
- $isBeta=0;
- if($productSetEdition && $productSetEdition['switch']==4){
- $isBeta=1;
- }
- //查询默认模板
- $classIds=array();
- foreach ($classes as $key => $value) {
- $classIds[]=$value['class_id'];
- }
- if($subject==3){
- $classSet=$this->sConn->createCommand("select class_id,template_id,isp,wb_isp from product_class_set where class_id in(".implode(',',$classIds).") and subject_id='{$subject}' and is_beta='{$isBeta}'")->queryAll();
- }else{
- $classSet=$this->sConn->createCommand("select class_id,template_id,isp,wb_isp from product_class_set where class_id in(".implode(',',$classIds).") and subject_id='{$subject}' ")->queryAll();
- }
- $needCheckDefault=false;
- if($classSet){
- //有配置
- $tids=array();
- $tidClass=array();
- foreach ($classSet as $val) {
- if($val['template_id']){
- $tidClass[$val['class_id']][$val['template_id']]=$val['template_id'];
- $tids[$val['template_id']]=$val['template_id'];
- }
- if($val['isp']){
- $tidClass[$val['class_id']][$val['isp']]=$val['isp'];
- $tids[$val['isp']]=$val['isp'];
- }
- if($val['wb_isp']){
- $tidClass[$val['class_id']][$val['wb_isp']]=$val['wb_isp'];
- $tids[$val['wb_isp']]=$val['wb_isp'];
- }
- }
- if(count($classIds)!=count($tidClass)){
- //有班级是取默认设置
- $needCheckDefault=true;
- }
- if($tids){
- $template=$this->sConn->createCommand("select config_text from product_template where template_id in(".implode(',',$tids).")")->queryAll();
-
- if($template){
- foreach ($template as $key => $v) {
- $jsonData=json_decode($v['config_text'],true);
- if(isset($jsonData['studentLevelDivide']['isPushSameTrain']) && $jsonData['studentLevelDivide']['isPushSameTrain']){
- return true;
- }
- }
- }
- }
-
- }
- if($needCheckDefault || !$classSet){
- //没有配置,读取默认模板
- if($subject==3){
- $template=$this->sConn->createCommand("select config_text from product_template where subject_id='{$subject}' and is_default=1 and is_beta='{$isBeta}'")->queryAll();
- }else{
- $template=$this->sConn->createCommand("select config_text from product_template where subject_id='{$subject}' and is_default=1 ")->queryAll();
- }
- if($template){
- foreach ($template as $key => $v) {
- $jsonData=json_decode($v['config_text'],true);
- if(isset($jsonData['studentLevelDivide']['isPushSameTrain']) && $jsonData['studentLevelDivide']['isPushSameTrain']){
- return true;
- }
- }
- }
- }
- }
- return false;
- }
- /*学管发送还原考试申请*/
- public function actionRestoreApply(){
- $examGroupId = Req::post('examId');
- $result['status']=0;
- if(!$examGroupId){
- $result['msg']="参数异常";
- exit(jsonEncode($result));
- }
- $exam=Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId));
- if(!$exam){
- $result['msg']="未查询到考试信息";
- exit(jsonEncode($result));
- }
- $tplData=json_decode($exam->tpl_data,true);
- //查询申请记录
- $examRestore=SExamRestore::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId));
- if($examRestore){
- $result['msg']="考试已经申请,不要重复操作";
- exit(jsonEncode($result));
- }
- $model=new SExamRestore();
- $model->exam_group_id=$examGroupId;
- $model->exam_name=$exam->name;
- $model->subject_name=Yii::app()->params['subjectId'][$exam->subject_id];
- $model->exam_date=$tplData['examDate'];
- $model->create_time=time();
- if($model->save()){
- if(Yii::app()->params['handle_log_on_off'])
- {
- writeFileLog(jsonEncode(array(
- "exam_group_id" => (string)$examGroupId,
- "operate_project" => 'zsyas2',
- "school_id" => $this->schoolId,
- "title" => '还原申请',
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $this->getRoute(),
- "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
- "date"=>date('Y-m-d H:i:s')
- )));
- }
- $result['status']=1;
- exit(jsonEncode($result));
- }else{
- $result['msg']="申请失败";
- exit(jsonEncode($result));
- }
- }
- /*退回还原考试申请*/
- public function actionRestoreApplyBack(){
- $examGroupId = Req::post('examId');
- $result['status']=0;
- if(!$examGroupId){
- $result['msg']="参数异常";
- exit(jsonEncode($result));
- }
- $exam=Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId));
- if(!$exam){
- $result['msg']="未查询到考试信息";
- exit(jsonEncode($result));
- }
- //查询申请记录
- $examRestore=SExamRestore::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId));
- if(!$examRestore){
- $result['msg']="申请已退回,不要重复操作";
- exit(jsonEncode($result));
- }
- $rs = SExamRestore::model()->deleteByPk($examGroupId);
- if($rs){
- $result['status']=1;
- if(Yii::app()->params['handle_log_on_off'])
- {
- writeFileLog(jsonEncode(array(
- "exam_group_id" => (string)$examGroupId,
- "operate_project" => 'zsyas2',
- "school_id" => $this->schoolId,
- "title" => '还原申请退回',
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $this->getRoute(),
- "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
- "date"=>date('Y-m-d H:i:s')
- )));
- }
- exit(jsonEncode($result));
- }else{
- $result['msg']="退回失败";
- exit(jsonEncode($result));
- }
- }
-
- //标注预计完成时间计算
- public function ComputeCompleteTime($examGroupId){
- if(!$examGroupId) return false;
- $exam=$this->sConn->createCommand("select exam_id from exam where exam_group_id='{$examGroupId}'")->queryAll();
- if(!$exam) return false;
- $examIds=array();
- foreach ($exam as $val){
- $examIds[]=$val['exam_id'];
- }
- $taskTime=0;
- $studentPaper=$this->sConn->createCommand("select count(*) as count from student_paper_relation where exam_id in(".implode(',',$examIds).")")->queryRow();
- $studentCount=$studentPaper['count'];
- if($studentCount<=500){
- $taskTime=36;
- }elseif($studentCount<=1000){
- $taskTime=24;
- }elseif($studentCount<=1500){
- $taskTime=12;
- }else{
- $taskTime=6;
- }
- $data['studentNumber']=$studentCount;
- $data['estimate']=expectTime($taskTime,time());
- return $data;
- }
- /**
- * 英语外刊阅读初始化获取 版本 模块 单元
- */
- public function actionAjaxReadingTextbookModuleUnit(){
- //版本 模块 单元
- $textbooks=$modules=$units=array();
- // $textbookResult=$this->apiPost('all_textbook/textbook',array('subject_id'=>8));
- $textbookResult=$this->apiPost('all_textbook/getTextbookByImsProduct',array('subjectId'=>8,'imsProductId'=>6));
- if(isset($textbookResult['status']) && $textbookResult['status'] && isset($textbookResult['data']) && $textbookResult['data']){
- $textbookResult=$textbookResult['data'];
- foreach($textbookResult as $textbookKey=>$textbookItem){
- $textbooks[]=array('textbook_id'=>$textbookItem['textbook_id'],'textbook_name'=>$textbookItem['textbook_name']);
- if($textbookKey==0 && isset($textbookItem['child']) && $textbookItem['child']){
- foreach($textbookItem['child'] as $moduleKey=>$moduleItem){
- $modules[]=array('textbook_id'=>$moduleItem['textbook_id'],'textbook_name'=>$moduleItem['textbook_name']);
- if($moduleKey==0 && isset($moduleItem['child']) && $moduleItem['child']){
- foreach($moduleItem['child'] as $unitItem){
- $units[]=array('textbook_id'=>$unitItem['textbook_id'],'textbook_name'=>$unitItem['textbook_name']);
- }
- }
- }
- }
- }
- }
- $date_msg = $this->getWeekOnMonth();
- $year = $date_msg["year"];
- $month = $date_msg["month"];
- $week = $date_msg["week"];
- $weekUpper = numToUpper($week);
- $weekName = $year.'年'.$month.'月'.'第'.$weekUpper.'周';
- $data=array(
- 'textbooks'=>$textbooks,//版本
- 'modules'=>$modules,//模块
- 'units'=>$units,//单元
- 'week_name'=>$weekName,
- );
- exit(json_encode(array('status'=>1,'msg'=>'成功','data'=>$data)));
- }
- /*
- * 英语外刊阅读获取班级数据
- */
- public function actionAjaxReadingClasses(){
- $req=Req::input();
- $grade=isset($req['grade'])?(int)$req['grade']:0;
- $gc=isset($req['category'])?(int)$req['category']:1; //产品种类 1综合(老版) 2 分离(新版)
- $pt=isset($req['pt'])?(int)$req['pt']:1; //产品类型:1-基础宝 2-外刊宝 3-热点宝
- if(!$grade){
- exit(json_encode(array('status'=>0,'msg'=>'请传年级参数')));
- }
- $class=$this->getClassesBySettingReading($grade,$gc,$pt);
- $data=array(
- 'class'=>$class,
- );
- exit(json_encode(array('status'=>1,'msg'=>'成功','data'=>$data)));
- }
- /*
- * 英语外刊阅读获取基础选题
- */
- public function actionAjaxReadingBasicTopics(){
- $req=Req::input();
- $grade=isset($req['grade'])?(int)$req['grade']:0;
- if(!$grade){
- exit(json_encode(array('status'=>0,'msg'=>'请传年级参数')));
- }
- $basicTopics=array();
- $basicTopicsResult=$this->apiPost('all_library/englishProductSet',array('query_type'=>1,'grade'=>$grade));
- if(isset($basicTopicsResult['status']) && $basicTopicsResult['status'] && isset($basicTopicsResult['data']) && $basicTopicsResult['data']){
- $basicTopics=$basicTopicsResult['data'];
- }
- $data=array(
- 'basic_topics'=>$basicTopics,
- );
- exit(json_encode(array('status'=>1,'msg'=>'成功','data'=>$data)));
- }
- /*
- * 英语外刊阅读获取热点选题
- */
- public function actionAjaxReadingHotTopics(){
- $req=Req::input();
- $grade=isset($req['grade'])?(int)$req['grade']:0;
- if(!$grade){
- exit(json_encode(array('status'=>0,'msg'=>'请传年级参数')));
- }
- $hotTopics=array();
- $hotTopicsResult=$this->apiPost('all_library/englishProductSet',array('query_type'=>2,'grade'=>$grade));
- if(isset($hotTopicsResult['status']) && $hotTopicsResult['status'] && isset($hotTopicsResult['data']) && $hotTopicsResult['data']){
- $hotTopics=$hotTopicsResult['data'];
- }
- $data=array(
- 'hot_topics'=>$hotTopics,
- );
- exit(json_encode(array('status'=>1,'msg'=>'成功','data'=>$data)));
- }
- /*
- * 英语外刊阅读获取主题语境
- */
- public function actionAjaxReadingSubjectContext(){
- $subjectContextResult=$this->apiPost('all_textbook/subjectContext',array());
- if(isset($subjectContextResult['status']) && $subjectContextResult['status'] && isset($subjectContextResult['data']) && $subjectContextResult['data']){
- $subjectContext=$subjectContextResult['data'];
- }
- $data=array(
- 'subject_context'=>$subjectContext,
- );
- exit(json_encode(array('status'=>1,'msg'=>'成功','data'=>$data)));
- }
- /**
- * 根据版本获取模块和单元数据
- */
- public function actionAjaxNewGetModuleAndUnit(){
- $req=Req::input();
- $versionId=isset($req['version_id'])?(int)$req['version_id']:0;
- $queryType=isset($req['query_type'])?(int)$req['query_type']:1;
- if(!$versionId){
- $versionId=(int)Req::post('version_id');
- $queryType=(int)Req::post('query_type')?(int)Req::post('query_type'):2;
- }
- $subjectId= Yii::app()->session['session_duoxueke_subject_id'];
- $subjectId=in_array($subjectId,array(3,6,51))?3:$subjectId;
- $moduleResult=$this->apiPost('all_textbook/getModule',array('version_id'=>$versionId,'query_type'=>$queryType,'subject_id'=>$subjectId));
- $modules=$units=$chapters=array();
- if(isset($moduleResult['status']) && $moduleResult['status'] && isset($moduleResult['data']) && $moduleResult['data']){
- $moduleResult=array_values($moduleResult['data']);
- foreach($moduleResult as $moduleKey=>$moduleItem){
- $modules[]=array('textbook_id'=>$moduleItem['textbook_id'],'textbook_name'=>$moduleItem['textbook_name']);
- if($moduleKey==0 && isset($moduleItem['child']) && $moduleItem['child']){
- foreach($moduleItem['child'] as $unitKey=>$unitItem){
- $units[]=array('textbook_id'=>$unitItem['textbook_id'],'textbook_name'=>$unitItem['textbook_name']);
- if( $unitKey==0 && isset($unitItem['child']) && $unitItem['child']){
- foreach($unitItem['child'] as $chapterItem){
- $chapters[]=array('textbook_id'=>$chapterItem['textbook_id'],'textbook_name'=>$chapterItem['textbook_name']);
- }
- }
- }
- }
- }
- }
- $data=array(
- 'modules'=>$modules,//模块
- 'units'=>$units,//单元
- 'chapters'=>$chapters,//章节
- );
- exit(json_encode(array('status'=>1,'msg'=>'成功','data'=>$data)));
- }
- /**
- * 根据版本获取单元数据
- */
- public function actionAjaxNewGetUnitByModuleId(){
- $req=Req::input();
- $versionId=isset($req['version_id'])?(int)$req['version_id']:0;
- $moduleId=isset($req['module_id'])?(int)$req['module_id']:0;
- $queryType=isset($req['query_type'])?(int)$req['query_type']:1;
- if(!$moduleId){
- $versionId=(int)Req::post('version_id');
- $moduleId=(int)Req::post('module_id');
- $queryType=(int)Req::post('query_type')?(int)Req::post('query_type'):2;
- }
- $unitResult=$this->apiPost('all_textbook/getUnit',array('module_id'=>$moduleId,'query_type'=>$queryType,'version_id'=>$versionId));
- $units=array();
- if(isset($unitResult['status']) && $unitResult['status'] && isset($unitResult['data']) && $unitResult['data']){
- $unitResult=$unitResult['data'];
- foreach($unitResult as $unitKey=>$unitItem){
- $units[]=array('textbook_id'=>$unitItem['textbook_id'],'textbook_name'=>$unitItem['textbook_name']);
- }
- }
- $data=array(
- 'units'=>$units,//单元
- );
- exit(json_encode(array('status'=>1,'msg'=>'成功','data'=>$data)));
- }
- /**
- * 根据模块获取单元数据和章节数据
- */
- public function actionAjaxNewGetUnitAndChapters(){
- $versionId=(int)Req::post('version_id');
- $moduleId=(int)Req::post('module_id');
- $queryType=(int)Req::post('query_type')?(int)Req::post('query_type'):2;
- $subjectId= Yii::app()->session['session_duoxueke_subject_id'];
- $subjectId=in_array($subjectId,array(3,6,51))?3:$subjectId;
- $unitResult=$this->apiPost('all_textbook/getModule',array('version_id'=>$versionId,'query_type'=>$queryType,'subject_id'=>$subjectId,'module_id'=>$moduleId));
- $units=$chapters=array();
- if(isset($unitResult['status']) && $unitResult['status'] && isset($unitResult['data']) && $unitResult['data']){
- $unitResult=array_values($unitResult['data']);
- foreach($unitResult as $unitKey=>$unitItem){
- $units[]=array('textbook_id'=>$unitItem['textbook_id'],'textbook_name'=>$unitItem['textbook_name']);
- if( $unitKey==0 && isset($unitItem['child']) && $unitItem['child']){
- foreach($unitItem['child'] as $chapterItem){
- $chapters[]=array('textbook_id'=>$chapterItem['textbook_id'],'textbook_name'=>$chapterItem['textbook_name']);
- }
- }
- }
- }
- $data=array(
- 'units'=>$units,//单元
- 'chapters'=>$chapters,//章节
- );
- exit(json_encode(array('status'=>1,'msg'=>'成功','data'=>$data)));
- }
- /**
- * 根据单元获取章节数据
- */
- public function actionAjaxNewGetChapters(){
- $versionId=(int)Req::post('version_id');
- $moduleId=(int)Req::post('module_id');
- $queryType=(int)Req::post('query_type')?(int)Req::post('query_type'):2;
- $subjectId= Yii::app()->session['session_duoxueke_subject_id'];
- $subjectId=in_array($subjectId,array(3,6,51))?3:$subjectId;
- $chapterResult=$this->apiPost('all_textbook/getModule',array('version_id'=>$versionId,'query_type'=>$queryType,'subject_id'=>$subjectId,'module_id'=>$moduleId));
- $chapters=array();
- if(isset($chapterResult['status']) && $chapterResult['status'] && isset($chapterResult['data']) && $chapterResult['data']){
- $chapterResult=array_values($chapterResult['data']);
- foreach($chapterResult as $chapterItem){
- $chapters[]=array('textbook_id'=>$chapterItem['textbook_id'],'textbook_name'=>$chapterItem['textbook_name']);
- }
- }
- $data=array(
- 'chapters'=>$chapters,//章节
- );
- exit(json_encode(array('status'=>1,'msg'=>'成功','data'=>$data)));
- }
- /**
- * 智能模式下设置的产品类型学生数据
- */
- public function actionAjaxSmartTypeStudents(){
- $req=Req::input();
- $classIds=isset($req['selectClassIds'])?$req['selectClassIds']:array();
- if(!$classIds || !is_array($classIds)){
- exit(json_encode(array('status'=>0,'msg'=>'请检查班级参数')));
- }
- $classIdsStr=implode(',',$classIds);
- $sql = "select class_id,class_name from class where semester_id = '{$this->semesterId}' and class_id in ({$classIdsStr}) and is_hide=0";
- $validClass = $this->sConn->createCommand($sql)->queryAll();
- if(!$validClass){
- exit(json_encode(array('status'=>0,'msg'=>'成功','data'=>array())));
- }
- // $validClass=$this->_array_column($validClass,'class_name','class_id');
- $newValidClass = array();
- foreach($validClass as $k=>$v){
- $newValidClass[(string)$v['class_id']] = $v['class_name'];
- }
- $validClass = $newValidClass;
- $classIdsStr=implode(',',array_keys($validClass));
- $sql = "SELECT si.student_id,si.realname,si.reading_level,scr.class_id FROM `student_class_relation` scr inner join student_info si on scr.student_id=si.student_id where scr.class_id in ({$classIdsStr}) and si.reading_level>0 and scr.status=0";
- $studentInfo = $this->sConn->createCommand($sql)->queryAll();
- $studentType=array();
- foreach($studentInfo as $item){
- $classId=$item['class_id'];
- $studentId=(string)$item['student_id'];
- $readingLevel=$item['reading_level'];
- if(!isset($studentType[$readingLevel][$classId]) || !array_key_exists($studentId,$studentType[$readingLevel][$classId])) {
- $studentType[$readingLevel][$classId][$studentId] = $item['realname'];
- }
- }
- $readingSmartTypes=array(1,2,3);
- $lists=array();
- foreach($readingSmartTypes as $type){
- $classInfo=array();
- foreach($validClass as $classId=>$className){
- $classId=(string)$classId;
- if(isset($studentType[$type][$classId])){
- $studentsArr=$studentType[$type][$classId];
- $students=array();
- foreach($studentsArr as $studentId=>$studentName){
- $students[]=array('student_id'=>(string)$studentId,'realname'=>$studentName);
- }
- $classInfo[]=array(
- 'class_id'=>$classId,
- 'class_name'=>$className,
- 'students'=>$students,
- );
- }else{
- $classInfo[]=array(
- 'class_id'=>$classId,
- 'class_name'=>$className,
- 'students'=>array(),
- );
- }
- }
- $lists[]=array(
- 'product_type'=>$type,
- 'class_info'=>$classInfo,
- );
- unset($classInfo);
- }
- $data=array('lists'=>$lists);
- exit(json_encode(array('status'=>1,'msg'=>'成功','data'=>$data)));
- }
- /**
- * 外刊阅读保存设置
- */
- public function actionAjaxNewSaveEnglishReading(){
- $error = array();
- $req=Req::input();
- if (!Yii::app()->request->isPostRequest){
- $error[] = '错误的来源!';
- }else{
- $grade=isset($req['grade'])?(int)$req['grade']:0;//年级:1-高一 2-高二 3-高三
- $textbookId=isset($req['textbookId'])?(int)$req['textbookId']:0;//教材Id
- $moduleId=isset($req['moduleId'])?(int)$req['moduleId']:0;//模块Id
- $unitId=isset($req['unitId'])?$req['unitId']:array();//单元Id
- $classIds=isset($req['selectClassIds']) && is_array($req['selectClassIds']) ?$req['selectClassIds']:array();//班级
- $itemIds=isset($req['selectedItemIds']) && is_array($req['selectedItemIds'])?$req['selectedItemIds']:array();//主题语境下话题
- $type=isset($req['type'])?(int)$req['type']:0;//外刊类型:1-个性外刊 2-共性外刊
- $level=isset($req['level'])?(int)$req['level']:0;//外刊分级 1-尖子班 2-培优班 3-提高班
- $isAnswerSeparate=isset($req['isAnswerSeparate'])?(int)$req['isAnswerSeparate']:0;;//答案是否分开打印 0否 1是
- $isNewVersion = 1;//是否新版本 1是 0否
- $recommendMode=isset($req['recommend_mode'])?(int)$req['recommend_mode']:0;;//推荐模式:1-经典模式 2-智能推荐模式
- $productType=isset($req['product_type'])?(int)$req['product_type']:0;;//产品类型:1-基础宝 2-外刊宝 3-热点宝
- $basicTopic=isset($req['basic_topic'])?(int)$req['basic_topic']:0;;//基础选题
- $hotTopic=isset($req['hot_topic'])?(int)$req['hot_topic']:0;//热点选题
- $topicNumber=isset($req['topic_number'])?$req['topic_number']:array();//题目数量
- $selectSetType=isset($req['select_set_type'])?$req['select_set_type']:0;//选择的类型 1-按照教材单元设置 2-主题语境设置 3-时文阅读
- $classBetweenContent=isset($req['class_between_content'])?$req['class_between_content']:0;//班级间内容: 0-相同 1-不同
- $category=isset($req['category'])?(int)$req['category']:1;//产品种类 1综合(老版) 2 分离(新版)
- $classify=19;
- $weekNameExt='外刊宝';
- if($category==2){
- if($productType==1){
- $classify=57;
- $weekNameExt='基础宝';
- }elseif($productType==2){
- $classify=61;
- $weekNameExt='外刊宝';
- }elseif($productType==3){
- $classify=58;
- $weekNameExt='热点宝';
- }
- }
- if(!in_array($selectSetType,array(1,2,3))){
- $error[] = '请选择设置类型';
- }
- if($selectSetType==1){
- if(!$textbookId || !$moduleId || !$unitId){
- $error[] = '按照教材单元设置时教材、模块、单元不能为空';
- }
- $itemIds=array();
- }elseif($selectSetType==2){
- if(!$itemIds){
- $error[] = '主题语境设置时主题语境不能为空';
- }
- $unitId=array();$textbookId=$moduleId=0;
- }elseif($selectSetType==3){
- //时文阅读无这几个参数,处理成不传时候的默认值
- $itemIds=$unitId=array();$textbookId=$moduleId=0;
- }
- if($unitId){
- if(!is_array($unitId)){
- $error[] = '单元格式不正确';
- }
- if(is_array($unitId) && count($unitId)>3) {
- $error[] = '单元最多3个';
- }
- }
- if($unitId && is_array($unitId) && $unitId){
- $unitId=empty($unitId)?0:implode(',',$unitId);
- }elseif(!$unitId){
- $unitId=0;
- }
- if(!in_array($grade,array(1,2,3))){
- $error[] = '请选择正确年级';
- }
- if(!$classIds || !is_array($classIds)){
- $error[] = '请选择班级';
- }
- if(!in_array($recommendMode,array(1,2))){
- $error[] = '推荐模式不在范围内';
- }
- if($recommendMode==1 && !in_array($productType,array(1,2,3))){
- $error[] = '产品类型不在范围内';
- }
- if(!in_array($classBetweenContent,array(0,1))){
- $error[] = '请检查班级间内容';
- }
- if(!in_array($category,array(1,2))){
- $error[] = '产品种类不在合理范围内';
- }
- //经典模式
- if($recommendMode==1){
- if($productType==1){//基础宝
- if(!$basicTopic){
- $error[] = '请选择基础选题';
- }
- //不需要的值,设为0或者空
- $type=0;$level=0;$hotTopic=0;$topicNumberJson='';$classBetweenContent=0;
- }elseif($productType==2){//外刊宝
- if(!in_array($type,array(1,2))){
- $error[] = '请选择外刊类型';
- }
- if($type==2 && !in_array($level,array(1,2,3))){
- $error[] = '外刊类型是共性外刊时请选择正确的外刊分级';
- }
- unset($topicNumber['hot']);
- if(!$topicNumber || !isset($topicNumber['periodicals']) || count($topicNumber)!=1){
- $error[] = '检查题目数量';
- }else{
- $error=array_merge($error,$this->validateTopicNumber($topicNumber));
- }
- //不需要的值,设为0或者空
- $basicTopic=0;$hotTopic=0;
- if($type==1){
- $level=0;
- $classBetweenContent=0;//外刊宝中共性外刊时班级间内容才能选值
- }
- $topicNumberJson=json_encode($topicNumber);
- }elseif($productType==3){//热点宝
- if(!in_array($type,array(1,2))){
- $error[] = '请选择外刊类型';
- }
- if($type==2 && !in_array($level,array(1,2,3))){
- $error[] = '外刊类型是共性外刊时请选择正确的外刊分级';
- }
- if(!$hotTopic){
- $error[] = '请选择热点选题';
- }
- unset($topicNumber['periodicals']);
- if(!$topicNumber || !isset($topicNumber['hot']) || count($topicNumber)!=1){
- $error[] = '缺少题目数量';
- }else{
- $error=array_merge($error,$this->validateTopicNumber($topicNumber));
- }
- //不需要的值,设为0或者空
- $basicTopic=0;
- if($type==1){
- $level=0;
- $classBetweenContent=0;//热点宝中共性外刊时班级间内容才能选值
- }
- $topicNumberJson=json_encode($topicNumber);
- }
- }elseif($recommendMode==2){//智能推荐模式
- if(!$basicTopic){
- $error[] = '请选择基础选题';
- }
- if(!$hotTopic){
- $error[] = '请选择热点选题';
- }
- if(!$topicNumber){
- $error[] = '缺少题目数量';
- }else{
- if(!isset($topicNumber['periodicals']) || !isset($topicNumber['hot'])){
- $error[] = '检查题目数量';
- }else{
- $error=array_merge($error,$this->validateTopicNumber($topicNumber));
- }
- }
- $type=1;//默认个性外刊
- $level=0;$productType=0;$classBetweenContent=0;
- $topicNumberJson=json_encode($topicNumber);
- }
- }
- if(!$error){
- $time = time();
- $date_msg = $this->getWeekOnMonth();
- $year = $date_msg["year"];
- $month = $date_msg["month"];
- $week = $date_msg["week"];
- $weekUpper = numToUpper($week);
- $strModel = new SStudentClassRelation();
- $transaction = $this->sConn->beginTransaction();
- try{
- $weekName = $year.'年'.$month.'月'.'第'.$weekUpper.'周"'.$weekNameExt.'"';
- $reading_id = getUniqueId($this->schoolId);
- $this->sConn->createCommand()->insert('english_reading_setting',array(
- 'reading_id'=>$reading_id,
- 'grade' => $grade,
- 'semester_id' => $this->semesterId,
- 'textbook_id' => $textbookId,
- 'module_id' => $moduleId,
- 'unit_id' => $unitId,
- 'special_ids' => implode(',',$itemIds),
- 'create_time' => $time,
- 'type' => $type,
- 'level'=>$level,
- 'is_answer_separate'=>$isAnswerSeparate,
- 'recommend_mode'=>$recommendMode,
- 'product_type'=>$productType,
- 'basic_topic'=>$basicTopic,
- 'hot_topic'=>$hotTopic,
- 'topic_number_json'=>$topicNumberJson,
- 'class_between_content'=>$classBetweenContent,
- 'category'=>$category
- ));
- $weekIdArr=array();
- foreach($classIds as $k=>$v){
- $weekId = getUniqueId($this->schoolId);
- $weekIdArr[]=$weekId;
- $this->sConn->createCommand()->insert('english_reading',array(
- 'week_id' => $weekId,
- 'name' => $weekName,
- 'class_id' => $v,
- 'grade' => $grade,
- 'semester_id' => $this->semesterId,
- 'year_num' => $year,
- 'week_num' => $week,
- 'month_num' => $month,
- 'reading_id'=>$reading_id,
- 'create_time' => $time,
- 'is_new_version'=>$isNewVersion,
- ));
- //获取班级学生
- $stuData = $strModel->getRelationsByClassId_Status_0($v);
- $studentInfo=array();
- if($stuData && (($recommendMode==1 && in_array($productType,array(2,3)) && $type==1) || ($recommendMode==2)) ){
- $sql = "SELECT si.student_id,si.reading_level,scr.class_id FROM `student_class_relation` scr inner join student_info si on scr.student_id=si.student_id where scr.class_id={$v} and si.reading_level>0 and scr.status=0";
- $studentInfo = $this->sConn->createCommand($sql)->queryAll();
- $studentInfo=$this->_array_column($studentInfo,'reading_level','student_id');
- }
- //智能模式
- if($recommendMode==2 && $stuData){
- foreach($stuData as $kk=>$vv){
- $readingLevel=isset($studentInfo[$vv['student_id']])?$studentInfo[$vv['student_id']]:2;
- $this->sConn->createCommand()->insert('english_reading_student',array(
- 'week_id' => $weekId,
- 'student_id' => $vv['student_id'],
- 'product_type'=>$readingLevel,//智能模式下档次和产品类型数值一样
- 'reading_level'=>$readingLevel,
- ));
- }
- }else if($recommendMode==1 && $stuData){//推荐模式
- foreach($stuData as $kk=>$vv){
- $readingLevel=0;
- //2-外刊宝 3-热点宝 下个性外刊
- if(in_array($productType,array(2,3)) && $type==1){
- $readingLevel=isset($studentInfo[$vv['student_id']])?$studentInfo[$vv['student_id']]:2;
- }
- $this->sConn->createCommand()->insert('english_reading_student',array(
- 'week_id' => $weekId,
- 'student_id' => $vv['student_id'],
- 'product_type'=>$productType,
- 'reading_level'=>$readingLevel,
- ));
- }
- }
- }
- $transaction->commit();
- }catch(Exception $e){
- $transaction->rollBack();
- if (YII_ENV == 'production') {
- $error[] = '系统错误[SQL]';
- } else {
- $error[] = $e->getMessage();
- }
- }
- }
- if($error){
- exit(json_encode(array('status'=>0,'msg'=>$error)));
- }else{
- $kafkaData=array(
- 'school_id'=>$this->schoolId,
- 'msg_type'=>1,//90:重置 1:新设置
- 'grade'=>$grade,
- 'subject_id'=>8,
- 'send_type'=>'english_reading',
- 'product_type'=>array($classify),
- 'gp_group_id'=>$reading_id,//reading_id
- 'gp_ids'=>array_unique($weekIdArr),//week_Id
- );
- sendDataToKafka("php-product-english-reading-html",$kafkaData);
- exit(json_encode(array('status'=>1)));
- }
- }
- /**
- * 校验题目数量设置
- * 外刊宝:外刊阅读,题数默认4(数量范围为0-7);外刊完形(新高考),题数默认0(数量范围为0-2);外刊七选五:题数默认1(数量范围为0-2),题数总和题数范围为2-7
- * 热点宝:外刊阅读,题数默认3(数量范围为0-6);外刊完形(新高考),题数默认0(数量范围为0-2);外刊七选五:题数默认1(数量范围为0-2),题数总和题数范围为1-6
- * @param $topicNumberConfig
- * @return array
- */
- private function validateTopicNumber($topicNumberConfig){
- $error=array();
- if(isset($topicNumberConfig['periodicals'])){
- $periodicals=$topicNumberConfig['periodicals'];
- if(!isset($periodicals['reading']) || !isset($periodicals['gestalt']) || !isset($periodicals['seven_selected_five'])){
- $error[]='外刊宝题目数量参数有误';
- }else{
- $reading=intval($periodicals['reading']);
- $gestalt=intval($periodicals['gestalt']);
- $sevenSelectedFive=intval($periodicals['seven_selected_five']);
- if(!($reading>=0 && $reading<=7)){
- $error[]='外刊宝外刊阅读数量设置有误:数量范围为0-7';
- }
- if(!($gestalt>=0 && $gestalt<=7)){
- $error[]='外刊宝外刊完形(新高考)数量设置有误:数量范围为0-2';
- }
- if(!($sevenSelectedFive>=0 && $sevenSelectedFive<=7)){
- $error[]='外刊宝外刊七选五数量设置有误:数量范围为0-2';
- }
- $periodicalsTotal=$reading+$gestalt+$sevenSelectedFive;
- if(!($periodicalsTotal>=2 && $periodicalsTotal<=7)){
- $error[]='外刊宝题数总和题数范围为2-7';
- }
- }
- }
- if(isset($topicNumberConfig['hot'])){
- $hot=$topicNumberConfig['hot'];
- if(!isset($hot['reading']) || !isset($hot['gestalt']) || !isset($hot['seven_selected_five'])){
- $error[]='热点宝题目数量参数有误';
- }else{
- $reading=intval($hot['reading']);
- $gestalt=intval($hot['gestalt']);
- $sevenSelectedFive=intval($hot['seven_selected_five']);
- if(!($reading>=0 && $reading<=7)){
- $error[]='热点宝外刊阅读数量设置有误:数量范围为0-6';
- }
- if(!($gestalt>=0 && $gestalt<=7)){
- $error[]='热点宝外刊完形(新高考)数量设置有误:数量范围为0-2';
- }
- if(!($sevenSelectedFive>=0 && $sevenSelectedFive<=7)){
- $error[]='热点宝外刊七选五数量设置有误:数量范围为0-2';
- }
- $periodicalsTotal=$reading+$gestalt+$sevenSelectedFive;
- if(!($periodicalsTotal>=1 && $periodicalsTotal<=6)){
- $error[]='热点宝题数总和题数范围为1-6';
- }
- }
- }
- return $error;
- }
- /**
- * 外刊阅读学生设置数据初始化
- */
- public function actionAjaxEnglishReadingSetInit(){
- $req=Req::input();
- $grade=isset($req['grade'])?(int)$req['grade']:0;
- if(!$grade){
- exit(json_encode(array('status'=>0,'msg'=>'请传年级参数')));
- }
- $class=$this->getClassesBySettingReading($grade);
- $data=array('class_students'=>array(), 'reading_level_students'=>array());
- if(!$class){
- exit(json_encode(array('status'=>1,'msg'=>'成功','data'=>$data)));
- }
- $class=$this->_array_column($class,'class_name','class_id');
- $classIdsStr=implode(',',array_keys($class));
- $students=$classStudentInfo=$studentType=$classLevelStudent=array();
- if($classIdsStr){
- $sql = "SELECT si.student_id,si.realname,si.reading_level,scr.class_id FROM `student_class_relation` scr inner join student_info si on scr.student_id=si.student_id where scr.class_id in ({$classIdsStr}) and scr.status=0 order by scr.class_id asc";
- $students = $this->sConn->createCommand($sql)->queryAll();
- }
- $readingLevel=array(1,2,3);
- foreach($students as $item){
- $isSet=false;
- $sutdentItem=array('student_id' => $item['student_id'], 'realname' => $item['realname'],'class_id'=>$item['class_id']);
- if($item['reading_level']){
- $isSet=true;
- $studentType[$item['reading_level']][] = $sutdentItem;//层次学生数据比班级学生数据少一个是否已设置分层标记
- $classLevelStudent[$item['class_id']][$item['reading_level']][]=$sutdentItem;
- }
- $sutdentItem['is_set']=$isSet;
- $sutdentItem['reading_level']=$item['reading_level'];
- $classStudentInfo[$item['class_id']][]=$sutdentItem;
- }
- $classLevelStudentResult=array();
- foreach($classLevelStudent as $classId=>&$itemLevelStudent){
- $classLevelStudentItem=array();
- foreach($readingLevel as $level){
- $levelStudent=isset($itemLevelStudent[$level])?$itemLevelStudent[$level]:array();
- $classLevelStudentItem[]=array('reading_level'=>$level,'students'=>$levelStudent);
- }
- $classLevelStudentResult[$classId]=$classLevelStudentItem;
- }
- $classStudent=$readingLevelStudent=$levelStudentDefault=array();
- foreach($readingLevel as $level){
- $levelStudentDefault[]= array('reading_level'=>$level,'students'=>array());//默认结构
- }
- foreach($class as $classId=>$className){
- $singleClassStudents=isset($classStudentInfo[$classId])?$classStudentInfo[$classId]:array();//单个班级学生数据
- $singleClassLevelStudent=isset($classLevelStudentResult[$classId])?$classLevelStudentResult[$classId]:$levelStudentDefault;//单个班级分档次学生数据
- $classStudent[]=array('class_id'=>$classId,'class_name'=>$className,'students'=>$singleClassStudents,'reading_level_students'=>$singleClassLevelStudent);
- }
- unset($students); unset($classStudentInfo);unset($classLevelStudentResult);unset($singleClassStudents);unset($singleClassLevelStudent);
- foreach($readingLevel as $level){
- $readingLevelStudent[]=array(
- 'reading_level'=>$level,
- 'students'=>isset($studentType[$level])?$studentType[$level]:array(),
- );
- }
- $data=array(
- 'class_students'=>$classStudent,//班级学生
- 'reading_level_students'=>$readingLevelStudent,//分层学生
- );
- unset($classStudent);unset($readingLevelStudent);unset($studentType);
- exit(json_encode(array('status'=>1,'msg'=>'成功','data'=>$data)));
- }
- private function getInWhereStr($data=array()){
- $str='';
- foreach($data as $item){
- $str.="'".$item."',";
- }
- $str=trim($str,',');
- return $str;
- }
- /**
- * 英语外刊学生设置保存学生层次
- */
- public function actionAjaxEnglishReadingStudentSettingSave(){
- $req=Req::input();
- $studentsProductType=isset($req['students_product_type'])?$req['students_product_type']:array();
- if(!$studentsProductType || !is_array($studentsProductType)){
- exit(json_encode(array('status'=>0,'msg'=>'请检查参数')));
- }
- $studentsProductTypeData=array();
- foreach($studentsProductType as $kye=>$item){
- if(!isset($item['reading_level']) || !in_array($item['reading_level'],array(0,1,2,3)) || !isset($item['students']) || !is_array($item['students'])){
- exit(json_encode(array('status'=>0,'msg'=>'请检查参数里的数据')));
- }
- if( !$item['students']){
- unset($studentsProductType[$kye]);
- continue;
- }
- $studentsProductTypeData[$item['reading_level']]=$item['students'];
- }
- unset($studentsProductType);
- ksort($studentsProductTypeData);
- $error=array();
- $transaction = $this->sConn->beginTransaction();
- try{
- foreach($studentsProductTypeData as $readingLevel=>$students){
- $readingLevel=(int)$readingLevel;
- if($students) {
- $studentIdsStr = implode(',', $students);
- $sql = "update student_info set reading_level={$readingLevel} where student_id in ({$studentIdsStr})";
- $this->sConn->createCommand($sql)->execute();
- }
- }
- $transaction->commit();
- }catch(Exception $e){
- $transaction->rollBack();
- if (YII_ENV == 'production') {
- $error[] = '系统错误[SQL]';
- } else {
- $error[] = $e->getMessage();
- }
- }
- if($error){
- exit(json_encode(array('status'=>0,'msg'=>$error)));
- }else{
- exit(json_encode(array('status'=>1)));
- }
- }
- /**
- * 英语外刊阅读学生数据导入
- * @throws CException
- */
- public function actionEnglishReadingStudentImport()
- {
- ini_set('memory_limit', '300M');
- if (Yii::app()->request->getIsPostRequest()) {
- $grade=(int)Req::post('grade');
- if(!$grade){
- exit(json_encode(array('status'=>0,'msg'=>'缺少年级参数')));
- }
- $uploader = new Uploader("upload/tmpDir/UploadEnglisthReadingStudentsList/{$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"]))
- exit(json_encode(array('status'=>0,'msg'=>'请选择上传的Excel!')));
- if ($file["error"] != 0) {
- switch ($file["error"]) {
- case 2001:
- exit(json_encode(array('status'=>0,'msg'=>'文件类型不符')));
- break;
- case 2002:
- exit(json_encode(array('status'=>0,'msg'=>'文件大小超出允许范围')));
- break;
- default:
- exit(json_encode(array('status'=>0,'msg'=>'上传失败')));
- break;
- }
- }
- $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')
- )));
- }
- Yii::import('application.extensions.*');
- require_once('phpexcel/PHPExcel/IOFactory.php');
- // 读取Excel文档
- $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
- $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
- @unlink($file["src"]);
- // 去掉导航
- //dump($sheetData);die;
- unset($sheetData[1]);
- krsort($sheetData);
- $excelTotal=count($sheetData);
- $studentScoreInfo = array();
- foreach ($sheetData as $key => $val) {
- if (empty($val['A']) || empty($val['B']) || !isset($val['C']) || !is_numeric($val['C']) || empty($val['D']) || !is_numeric($val['D']) || (int)$val['D']<=0) {
- continue;
- }
- if (count($val) != 4) {
- continue;
- }
- $studentScoreInfo[] = array(
- 'realname' => $val['A'],
- 'class_name' => $val['B'],
- 'score' => (int)$val['C'],
- 'total_score' => (int)$val['D'],
- );
- }
- if(!$studentScoreInfo){
- exit(json_encode(array('status'=>2,'data'=>array(),'msg'=>'未获取到有效学生数据,请检查表格是否有误。')));
- }
- $classNames=_array_column($studentScoreInfo,'class_name','class_name');
- $classNamesStr=$this->getInWhereStr($classNames);
- // $sql="select class_id,class_name from class where semester_id = '{$this->semesterId}' and class_name in ($classNamesStr) and class_type=1 and is_hide=0 and grade={$grade} group by class_name having count(*)=1";
- $sql="select class_id,class_name from class where semester_id = '{$this->semesterId}' and class_name in ($classNamesStr) and is_hide=0 and grade={$grade} group by class_name having count(*)=1";
- $classInfo= $this->sConn->createCommand($sql)->queryAll();
- if(!$classInfo){
- exit(json_encode(array('status'=>3,'data'=>array(),'msg'=>'没有有效年级数据')));
- }
- $classInfo=$this->_array_column($classInfo,'class_id','class_name');;
- $classIds=implode(',',$classInfo);
- $sql="SELECT scr.class_id,si.student_id,si.realname FROM `student_class_relation` scr inner join student_info si on scr.student_id=si.student_id where scr.class_id in ({$classIds}) and scr.status=0 group by scr.class_id,si.realname having count(*)>1";
- $repeatStudents= $this->sConn->createCommand($sql)->queryAll();
- //重复学生
- $repeatStudentsData=$classStudentInfo=array();
- foreach($repeatStudents as $item){
- $repeatStudentsData[$item['class_id'].$item['realname']]='';
- }
- //过滤信息 剔除查询不到班级和 姓名重复的学生
- foreach($studentScoreInfo as $key=>&$item){
- if(isset($classInfo[$item['class_name']])){
- $classId=$classInfo[$item['class_name']];
- //表里姓名重复的学生
- if(isset($repeatStudentsData[$classId][$item['realname']])){
- unset($studentScoreInfo[$key]);
- continue;
- }
- //excel里重复的和不符合条件的学生数据
- if(isset($classStudentInfo[$classId][$item['realname']]) || !intval($item['score']) || intval($item['total_score'])<=0 || intval($item['score'])>intval($item['total_score'])){
- unset($classStudentInfo[$classId][$item['realname']]);
- unset($studentScoreInfo[$key]);
- continue;
- }
- $rate=round(intval($item['score'])/intval($item['total_score']),4)*100;
- $level=2;
- if($rate<=60){
- $level=1;
- }elseif($rate>60 && $rate<=80){
- $level=2;
- }elseif($rate>80){
- $level=3;
- }
- $classStudentInfo[$classId][$item['realname']]=$level;
- }else{
- //不存在班级的学生
- unset($studentScoreInfo[$key]);
- }
- }
- unset($repeatStudentsData);unset($repeatStudents);
- if(!$classStudentInfo){
- exit(json_encode(array('status'=>1,'data'=>array())));
- }
- $sqlWhere='';
- foreach($classStudentInfo as $classId=>$itemStudent){
- $realnames=array_keys($itemStudent);
- if(!$realnames){
- continue;
- }
- $realnameStr=$this->getInWhereStr($realnames);
- $sqlWhere.=" (scr.class_id={$classId} and si.realname in ({$realnameStr}) ) or";
- }
- if(!$sqlWhere){
- exit(json_encode(array('status'=>2,'data'=>array(),'msg'=>'未获取到有效学生数据,请检查表格是否有误!')));
- }
- $sqlWhere=trim($sqlWhere,'or');
- $sql="select si.student_id,si.realname,scr.class_id from student_info si inner join student_class_relation scr on si.student_id=scr.student_id where {$sqlWhere} order by scr.class_id ";
- $students= $this->sConn->createCommand($sql)->queryAll();
- //有效的学生数
- $studentTotal=count($students);
- //有效的班级学生数据
- $classStudentData=array();
- foreach($students as $item){
- $classStudentData[$item['class_id']][$item['realname']]=$item['student_id'];
- }
- $productTypeStudents=$classStudents=$classLevelStudent=array();
- foreach($classStudentInfo as $classId=>$itemStudent){
- foreach($itemStudent as $realname=>$level){
- if(!isset($classStudentData[$classId][$realname])){
- continue;
- }
- $studentId=$classStudentData[$classId][$realname];
- $studentInfo=array('student_id'=>$studentId,'realname'=>$realname,'class_id'=>$classId);
- $productTypeStudents[$level][]=$studentInfo;
- $classLevelStudent[$classId][$level][]=$studentInfo;
- $studentInfo['is_set']=true;
- $studentInfo['reading_level']=$level;
- $classStudents[$classId][]=$studentInfo;//班级学生数据多是否设置和档次字段
- }
- }
- $readingLevel=array(1,2,3);
- $productTypeStudentsResult=$classStudentsResult=$classLevelStudentResult=array();
- //班级学生数据中的档次数据
- foreach($classLevelStudent as $classId=>&$itemLevelStudent){
- $classLevelStudentItem=array();
- foreach($readingLevel as $level){
- $levelStudent=isset($itemLevelStudent[$level])?$itemLevelStudent[$level]:array();
- $classLevelStudentItem[]=array('reading_level'=>$level,'students'=>$levelStudent);
- }
- $classLevelStudentResult[$classId]=$classLevelStudentItem;
- }
- unset($students);unset($classStudentInfo);unset($classStudentData);unset($classLevelStudent);
- //档次学生数据
- foreach($readingLevel as $itemLevel){
- $studentArr=isset($productTypeStudents[$itemLevel])?$productTypeStudents[$itemLevel]:array();
- $productTypeStudentsResult[]=array(
- 'reading_level'=>$itemLevel,
- 'students'=>$studentArr,
- );
- }
- //默认结构
- $levelStudentDefault=array();
- foreach($readingLevel as $level){
- $levelStudentDefault[]= array('reading_level'=>$level,'students'=>array());
- }
- //班级学生信息
- foreach($classInfo as $itemClassName =>$itemClassId){
- $studentArr=isset($classStudents[$itemClassId])?$classStudents[$itemClassId]:array();
- $classLevelStudentArr=isset($classLevelStudentResult[$itemClassId])?$classLevelStudentResult[$itemClassId]:$levelStudentDefault;
- $classStudentsResult[]=array('class_id'=>$itemClassId,'class_name'=>$itemClassName,'students'=>$studentArr,'reading_level_students'=>$classLevelStudentArr);
- }
- $data=array(
- 'class_students'=>$classStudentsResult,
- 'reading_level_students'=>$productTypeStudentsResult,
- 'excel_total'=>$excelTotal,
- 'student_total'=>$studentTotal,
- );
- unset($productTypeStudents);unset($classStudents);unset($classLevelStudentResult);unset($productTypeStudentsResult);unset($classStudentsResult);unset($studentArr);unset($classLevelStudentArr);
- exit(json_encode(array('status'=>1,'msg'=>'成功','data'=>$data)));
- }
- }
-
- /**
- * 新版英语外刊教师版
- */
- public function new_en_reading($weekId='',$week_info=array()){
- $sql = "select product_type,basic_topic,hot_topic from english_reading_setting where reading_id='{$week_info['reading_id']}'";
- $week_setting = $this->sConn->createCommand($sql)->queryRow();
- $data = array();
- $gradeRel = array(1=>"高一",2=>"高二",3=>"高三");
- $class_name = '';
- $grade = isset($gradeRel[$week_info['grade']]) ? $gradeRel[$week_info['grade']] : '';
- $class_id = $week_info['class_id'];
- $sql = "select class_id,class_name from class where class_id = '$class_id'";
- $class_data = $this->sConn->createCommand($sql)->queryRow();
- if($class_data){
- $class_name = $class_data['class_name'];
- }
- if($week_setting){
- if($week_setting['product_type'] == 1){//基础宝
- $p_name="外刊-基础宝";
- $html_name = 'en_jichu';
- $basic_data = array();
- $basic_topic = $week_setting['basic_topic'];//基础宝ID
- if($basic_topic){
- $basic_topic_arr = explode(",",$basic_topic);
- $brain_data = $this->apiBrainPost('/all_library/englishBaseBaby', array('ids' => $basic_topic_arr), 25, true);
- if($brain_data && isset($brain_data['data']) && $brain_data['data']){
- foreach($brain_data['data'] as $k=>$v){
- if(isset($v['jsb']) && $v['jsb']){
- $basic_data = json_decode($v['jsb'],true);
- }
- }
- }else{
- Yii::app()->jump->error('基础宝教师版接口有误');
- }
- }else{
- Yii::app()->jump->error('基础宝ID设置有误');
- }
- if(!$basic_data){
- Yii::app()->jump->error('基础宝教师版没有数据');
- }else{
- $data['basic_data'] = $basic_data;
- }
-
- }else if($week_setting['product_type'] == 2){//外刊宝
- $p_name="外刊-外刊宝";
- $html_name = 'en_waikan';
- $sql = "select topic_id from student_reading_topic where week_id='{$weekId}'";
- $topic_data = $this->sConn->createCommand($sql)->queryAll();
- if($topic_data){
- $topic_ids = _array_column($topic_data, 'topic_id');
- $topic_ids = array_unique($topic_ids);
- $data['topic_ids'] = $topic_ids;
- $topicDetails = $this->apiBrainPost('/topic/batchAll', array('topicIds' => $topic_ids), 25, true);
- if (!$topicDetails) {
- Yii::app()->jump->error('获取接口batchALL无数据!');
- } elseif (isset($topicDetails['status']) && $topicDetails['status'] == 0) {
- Yii::app()->jump->error($topicDetails['error'][0]);
- } else {
- $paper_topic_detail= array();
- foreach($topicDetails as $k=>$v){
- $paper_topic_detail[(string)$v['id']] = $v;
- }
- $new_topic_detail = $this->newTopicDetail($paper_topic_detail);
- $data['topic_detail'] = $new_topic_detail;
- }
- }else{
- Yii::app()->jump->error('学生外刊没生成');
- }
-
-
- }else{//热点宝
- $p_name="外刊-热点宝";
- $html_name = 'en_hot';
- $hot_topic = $week_setting['hot_topic'];//热点宝ID
- $redian_topic_ids = array();
- if($hot_topic){
- $hot_topic_arr = explode(",",$hot_topic);
- $brain_data = $this->apiBrainPost('/all_library/englishHotBaby', array('ids' => $hot_topic_arr), 25, true);
-
- if($brain_data && isset($brain_data['data']) && $brain_data['data']){
- foreach($brain_data['data'] as $k=>$v){
- if(isset($v['xxtlsy']) && $v['xxtlsy']){
- $redian_topic_ids = array_merge($redian_topic_ids,$v['xxtlsy']);
- }
- if(isset($v['ljfxsy']) && $v['ljfxsy']){
- $redian_topic_ids = array_merge($redian_topic_ids,$v['ljfxsy']);
- }
- if(isset($v['sbsy']) && $v['sbsy']){
- $redian_topic_ids = array_merge($redian_topic_ids,$v['sbsy']);
- }
- if(isset($v['yychhy']) && $v['yychhy']){
- $redian_topic_ids = array_merge($redian_topic_ids,$v['yychhy']);
- }
- if(isset($v['yyjjfx']) && $v['yyjjfx']){
- $redian_topic_ids = array_merge($redian_topic_ids,$v['yyjjfx']);
- }
- if(isset($v['zhyysy']) && $v['zhyysy']){
- $redian_topic_ids = array_merge($redian_topic_ids,$v['zhyysy']);
- }
- }
- $data['hot_data'] = $brain_data['data'][0];
- }else{
- Yii::app()->jump->error('热点宝教师版接口有误');
- }
- }else{
- Yii::app()->jump->error('热点宝ID设置有误');
- }
- $sql = "select topic_id from student_reading_topic where week_id='{$weekId}'";
- $topic_data = $this->sConn->createCommand($sql)->queryAll();
- if($topic_data){
- $topic_ids_0 = _array_column($topic_data, 'topic_id');
- $topic_ids_0 = array_unique($topic_ids_0);
- $topic_ids = array_merge($topic_ids_0,$redian_topic_ids);
- $data['topic_ids'] = $topic_ids_0;
- $topicDetails = $this->apiBrainPost('/topic/batchAll', array('topicIds' => $topic_ids), 25, true);
- if (!$topicDetails) {
- Yii::app()->jump->error('获取接口batchALL无数据!');
- } elseif (isset($topicDetails['status']) && $topicDetails['status'] == 0) {
- Yii::app()->jump->error($topicDetails['error'][0]);
- } else {
- $paper_topic_detail= array();
- foreach($topicDetails as $k=>$v){
- $paper_topic_detail[(string)$v['id']] = $v;
- }
- $new_topic_detail = $this->newTopicDetail($paper_topic_detail);
- $data['topic_detail'] = $new_topic_detail;
- }
-
- }else{
- Yii::app()->jump->error('学生外刊没生成');
- }
-
-
-
-
- }
- //开始生成html
- $data['type_config'] =array('gestalt'=>713,'reading'=>714,'seven_selected_five'=>array(715,432));
- $html = $this->renderPartial("{$html_name}", $data,true);
- unset($data);
- $htmlpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/reading/'; //存放生成的HTML路径
- $pdfpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/reading/' . $this->schoolId . "/"; //存放生成的PDF路径
- $pdfurl = '/upload/tmpDir/reading/' . $this->schoolId . "/";
- if (!is_dir($htmlpath)) {
- if (!mkdir($htmlpath, 0777, true)) {
- Yii::app()->jump->error('Create directory fail: ' . $htmlpath);
- }
- }
- if (!is_dir($pdfpath)) {
- if (!mkdir($pdfpath, 0777, true)) {
- Yii::app()->jump->error('Create directory fail: ' . $pdfpath);
- }
- }
- $htmlpath .= $weekId . ".html";
- $f = fopen($htmlpath, "w");
- fwrite($f, $html);
- fclose($f);
- $htmlurl = '/upload/tmpDir/reading/' . $weekId . ".html"; //访问HTML的路径
- //防止exec 执行命令行导致中文乱码
- $locale='en_US.UTF-8';
- setlocale(LC_ALL,$locale);
- putenv('LC_ALL='.$locale);
- if (Yii::app()->basePath == "E:\wamp64\www\zsyas2\protected") {//本地的basePath
- $htmlurl = " http://local.zsyas2teaching.com" . '/' . $weekId . '.html';
- $pdffname = $weekId . ".pdf";
- $pdfpath = $pdfpath . $pdffname;
- $pdfurl = $pdfurl . $pdffname;
- $commond = Yii::app()->params['phantomjs'] . " "
- . Yii::app()->params['html2pdf'] . " "
- . " {$htmlurl}"
- . " {$pdfpath}"
- . " 176mm*250mm '".$grade." || ".date('Y-m-d',time())."'";
- } else {
- $htmlurl = "http://" . $_SERVER['SERVER_NAME'] . $htmlurl;
- $pdffname = $weekId . ".pdf";
- $pdfpath = $pdfpath . $pdffname;
- $pdfurl = $pdfurl . $pdffname;
- $commond = Yii::app()->params['phantomjs_server_en'] . " "
- . Yii::app()->basePath . '/../js/html2pdf_en.js' . " "
- . " {$htmlurl}"
- . " {$pdfpath}"
- . ' 176mm*250mm "'.$class_name.'|||'.'时间:'.date('Y-m-d',time()).' '.$p_name.'"';
- }
- exec($commond, $res, $code);
- if(isset($res[0])){
- $isBool = false;
- foreach ($res as $msg) {
- if (strpos($msg, 'succeed') !== false) {
- $isBool = true;
- }
- }
- if ($isBool) {//命令返回成功
- if (file_exists($pdfpath)) {
- // $pdfurl=iconv("GBK", "UTF-8",$pdfurl);
- $repdf = $weekId . ".pdf";
- $rename = 'zsyas2/reading/' . $this->schoolId . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/' . uniqid() . '.' . $repdf;
- $ucloud = new HuaweiCloud();
- $uploadInfo = $ucloud->putFile($rename, $pdfpath);
-
- //上传html
- $rehtml = $weekId.".html";
- $rename = 'zsyas2/reading/' . $this->schoolId . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/' . uniqid() . '.' . $rehtml;
- $uploadHtmlInfo = $ucloud->putFile($rename, $htmlpath);
- if($uploadHtmlInfo['status'] == 0){
- $html_url = "http://" . $_SERVER['SERVER_NAME'].$htmlurl;
- }else{
- $html_url = $uploadHtmlInfo['url'];
- }
-
- if ($uploadInfo['status'] == 0) {
- $pdfurl = "http://" . $_SERVER['SERVER_NAME'] . $pdfurl;
- $this->sConn->createCommand()->update("english_reading", array("teacher_general_pdf_path" => $pdfurl,"teacher_general_html_path"=>$html_url), "week_id = '{$weekId}'");
- $week_info['teacher_general_pdf_path'] = $pdfurl;
- }else{
- $pdfurl = $uploadInfo['url'];
- $this->sConn->createCommand()->update("english_reading", array("teacher_general_pdf_path" => $pdfurl,"teacher_general_html_path"=>$html_url), "week_id = '{$weekId}'");
- $week_info['teacher_general_pdf_path'] = $pdfurl;
- @unlink($pdfpath);
- }
- @unlink($htmlpath);
- } else {
- @unlink($htmlpath);
- Yii::app()->jump->error('PDF文件未找到!');
- }
- } else {
- @unlink($htmlpath);
- Yii::app()->jump->error('PDF创建失败!');
- }
- } else {
- Yii::app()->jump->error('PDF创建失败11!');
- }
- }else{
- Yii::app()->jump->error('外刊宝设置信息有误');
- }
- if($week_info['teacher_general_pdf_path']){
- $url = $week_info['teacher_general_pdf_path'];
- header('Content-Description: File Transfer');
- header('Content-Type: application/vnd.android.package-archive');
- header('Content-Disposition: attachment; filename=' . $this->filter_file_name('外刊宝教师版') . ".pdf");
- header('Content-Transfer-Encoding: binary');
- header('Expires: 0');
- header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
- header('Pragma: public');
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
- curl_setopt($ch, CURLOPT_WRITEFUNCTION, function ($ch, $buffer) {
- echo $buffer;
- return strlen($buffer);
- });
- curl_exec($ch);
- curl_close($ch);
- }else{
- Yii::app()->jump->error('尚未生成PDF');
- }
- }
-
- /**
- * 整理试题详情数据
- */
- public function newTopicDetail($paper_topic_detail){
- $result = array();
- $answer = array('A','B','C','D','E','F','G','H','I','J','K');
- foreach($paper_topic_detail as $k=>$v){
- $result[$k]['title'] = $v['title'];
- $result[$k]['type_id'] = $v['type_id'];
- $result[$k]['parse_content'] = $v['parse_content'];
- $result[$k]['answer'] = array();
- $slave_answer = array();
- if(isset($v['slave']) && $v['slave']){
- $slave_arr = array();
- foreach($v['slave'] as $sla_k=>$sla_v){
- $slave_arr[$sla_k]['title'] = $sla_v['title'];//小题题干
- if(isset($sla_v['items']) && $sla_v['items']){
- if(isset($sla_v['items']['options']) && $sla_v['items']['options']){
- foreach($sla_v['items']['options'] as $op_k=>$op_v){
- $slave_arr[$sla_k]['options'][$op_k] = $op_v['option_content'];
- if($op_v['option_correct']){
- $slave_answer[] = $answer[$op_k];
- }
-
- }
- }
- }
- }
- $result[$k]['slave'] = $slave_arr;
- $result[$k]['answer'] = $slave_answer;
- }else{
- if(isset($v['items']) && $v['items'] && isset($v['items'][0]) && $v['items'][0]){
- if(isset($v['items'][0]['options']) && $v['items'][0]['options']){
- foreach($v['items'][0]['options'] as $op_k=>$op_v){
- if($op_v['option_correct'] == 1){
- $slave_answer[] = $op_v['option_content'];
- }
- }
- }
- }
- $result[$k]['answer'] = $slave_answer;
- }
- if(isset($v['affiliate']) && $v['affiliate']){
- foreach($v['affiliate'] as $aff_k=>$aff_v){
- if($aff_v['field_name'] == '体裁类型'){
- $result[$k]['tc'] = $this->getTags($aff_v['field_key'],$aff_v['field_value']);
- }
- if($aff_v['field_name'] == '主题语境'){
- //主题语境只显示一个
- $ztyj_str = $this->getTags($aff_v['field_key'],$aff_v['field_value']);
- $ztyj_arr = explode(",",$ztyj_str);
- if($ztyj_arr){
- $result[$k]['ztyj'] = $ztyj_arr[0];
- }else{
- $result[$k]['ztyj'] ='';
- }
- }
- if($aff_v['field_name'] == '语篇等级'){
- $result[$k]['ypdj'] = $aff_v['field_value'];
- }
- if($aff_v['field_name'] == '句子剖析'){
- $result[$k]['jzpx'] = $aff_v['field_value'];
- }
- if($aff_v['field_name'] == '词汇积累'){
- $result[$k]['chjl'] = $aff_v['field_value'];
- }
- if($aff_v['field_name'] == '关键词拓展'){
- $result[$k]['gjctz'] = $aff_v['field_value'];
- }
- if($aff_v['field_name'] == '长难句解析'){
- $result[$k]['cnjjx'] = $aff_v['field_value'];
- }
- }
- }
-
-
- }
- return $result;
- }
-
- /*
- * 获取试题标签
- *
- */
- public function getTags($field_key='',$field_value=''){
- $result = '';
- $data = array(
- 'subjectId'=>8,
- 'isSearch'=>1,
- 'tagFieldName'=>array($field_key)
- );
- $brain_data = $this->apiBrainPost('/all_subject/topic_tag', $data, 25, true);
- if($brain_data && isset($brain_data['data']) && $brain_data['data']){
- $brain_arr = $brain_data['data'];
- if(isset($brain_arr[0]) && isset($brain_arr[0]['extend']) && $brain_arr[0]['extend']){
- $field_value_arr = explode("|",$field_value);
- $field_arr = array();
- foreach($brain_arr[0]['extend'] as $extend_v){
- if(in_array($extend_v['tag_extend_id'],$field_value_arr)){
- $field_arr[]=$extend_v['tag_extend_name'];
- }
- }
- if($field_arr){
- $result = implode(",",$field_arr);
- }
- }
- }
-
- return $result;
-
- }
- /*读取考试试题推送配置*/
- public function actionLoadExamPushTopic(){
- $examGroupId = Req::post('examGroupId');
- $examIds = Req::post('examIds');
- $result=array();
- $result['status']=0;
- if(!$examGroupId || !is_numeric($examGroupId)){
- $result['msg']="参数异常";
- exit(jsonEncode($result));
- }
- if(!is_array($examIds)){
- $examIds=explode(',',$examIds);
- }
- //加载试题结构
- $classes=array();
- $examGroup=SExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId));
- if($examIds){
- $criteria = new CDbCriteria();
- $criteria->select = 'exam_id,class_id,tpl_data';
- $criteria->addInCondition('exam_id',$examIds);
- $exam = Exam::model()->findAll($criteria);
- $tplData=array();
- $alias=array();
- foreach ($exam as $item){
- $class=ClassModel::model()->find('class_id=:cid',array(':cid'=>$item['class_id']));
- $classes[]=$class['class_name'];
- if(!$tplData){
- $tplData=json_decode($item['tpl_data'],true);
- if(isset($tplData['new_items'])){
- foreach ($tplData['new_items'] as $value){
- if(isset($value['fullAlias'])){
- $alias[$value['id']]=$value['fullAlias'];
- }else{
- $alias[$value['id']]=$value['alias'];
- }
- }
- }
- }
- }
- $paper=SPaper::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam[0]['exam_id']));
- }
- if(!$paper){
- $result['msg']="考试数据异常";
- exit(jsonEncode($result));
- }
- $paperTopic=SPaperTopicRelation::model()->findAll('paper_id=:pid',array(':pid'=>$paper['paper_id']));
- $paperTopicRelation=array();
- if($examGroup['qxk_paper_id']>0){
- foreach ($paperTopic as $item){
- $paperTopicRelation[$item['order']]=$item['topic_id'];
- }
- }else{
- foreach ($paperTopic as $item){
- if(isset($alias[$item['order']])){
- $paperTopicRelation[$item['type']][]=array('topic_id'=>$item['topic_id'],'order'=>$alias[$item['order']]);
- }else{
- $paperTopicRelation[$item['type']][]=array('topic_id'=>$item['topic_id'],'order'=>$item['order']);
- }
- }
- }
- $data['qxk_paper_id']=$examGroup['qxk_paper_id'];
- $data['paper_topic']=$paperTopicRelation;
- $data['classes']=$classes;
- //加载设置数据
- $topicSetting=array();
- if(count($examIds)==1){ //只有一个班
- $examPushTopic=SExamPushTopicsSetting::model()->find('exam_id=:exam_id',array(':exam_id'=>$examIds[0]));
- if($examPushTopic){
- $topicSetting=json_decode($examPushTopic['topic_ids'],true);
- }
- }
- $data['topic_setting']=$topicSetting;
- $result['status']=1;
- $result['data']=$data;
- exit(jsonEncode($result));
- }
- /*保存考试试题推送配置*/
- public function actionSaveExamPushTopicSetting(){
- $examGroupId = Req::post('examGroupId');
- $examIds = Req::post('examIds');
- $topics=Req::post('topics');
- $result=array();
- $result['status']=0;
- if(!$examIds || !is_numeric($examGroupId) ){
- $result['msg']="参数异常";
- exit(jsonEncode($result));
- }
- if(!$topics) $topics=array();
- if(!is_array($examIds)){
- $examIds=explode(',',$examIds);
- }
- $examPushTopicModel=new SExamPushTopicsSetting();
- $examPushTopicModel->updateSettingBatch($examIds,$examGroupId,$topics);
- $result['status']=1;
- exit(jsonEncode($result));
- }
- /*加载考试班级*/
- public function actionLoadExamClass(){
- $examGroupId = Req::post('examGroupId');
- $result['status']=0;
- if(!$examGroupId){
- $result['msg']="参数异常";
- exit(jsonEncode($result));
- }
- $exam=$this->schoolManager->getExportClassByExamGroupId($examGroupId);
- if(!$exam){
- $result['msg']="未查询到考试信息";
- exit(jsonEncode($result));
- }
- $uploaded=array();
- $noUploaded=array();
- foreach ($exam as $value){
- if($value['upload_status']==0){
- $noUploaded[]=array(
- 'exam_id'=>$value['exam_id'],
- 'class_id'=>$value['class_id'],
- 'class_name'=>$value['class_name']
- );
- }else{
- $uploaded[]=array(
- 'exam_id'=>$value['exam_id'],
- 'class_id'=>$value['class_id'],
- 'class_name'=>$value['class_name']
- );
- }
- }
- $result['status']=1;
- $result['uploaded']=$uploaded;
- $result['no_uploaded']=$noUploaded;
- exit(jsonEncode($result));
- }
- /*删除指定班级未上传考生*/
- public function actionDelStudentPaperRelation(){
- $examIds = Req::post('examIds');
- $result['status']=0;
- if(!$examIds){
- $result['msg']="参数异常";
- exit(jsonEncode($result));
- }
- if($this->schoolManager->delStudentPaperByExamId($examIds)){
- $result['status']=1;
- $result['msg']="删除成功";
- exit(jsonEncode($result));
- }else{
- $result['msg']="删除失败";
- exit(jsonEncode($result));
- }
- }
- //客户端打印订单学生在线答题卡
- public function actionPrintPdfOnlineByOrder(){
- $examId=Req::post('exam_id');
- $result['success']=0;
- if(!$examId || !is_numeric($examId)){
- $result['msg']='参数不正确';
- exit(json_encode($result));
- }
- $examInfo = Exam::model()->findByPk($examId);
- if(!$examInfo){
- $result['msg']='未找到考试信息';
- exit(json_encode($result));
- }
- $onlineCard=$this->schoolManager->getAnswerSheetOnline($examInfo->exam_group_id);
- if(!$onlineCard){
- $result['msg']='考试还没有使用在线答题卡';
- exit(json_encode($result));
- }
- //检查订单
- $orderClass=0;
- $allClassStudents=$this->sConn->createCommand("select student_id,class_id from student_paper_relation where exam_id='{$examId}' and is_del=0 ")->queryAll();
- if($allClassStudents){
- foreach ($allClassStudents as $student){
- $students[]=$student['student_id'];
- if(!$orderClass) $orderClass=$student['class_id'];
- }
- }
- $semester=new SSemester();
- $nowsem=$semester->getCurrentSemester();
- $classinfo= ClassModel::model()->find("class_id=:id",array(":id"=>$orderClass));
- $subjectId=Yii::app()->session['session_subject_id'];
- if(in_array($subjectId,$this->mathSubjectId)){
- $subjectId=3;
- }
- $intarr=array(
- "schoolId"=>$this->schoolId,
- "clazzId"=>$orderClass,
- "semester"=>$nowsem['refer_code'],
- "grade"=>$classinfo['grade'],
- "students"=>array(),
- "examTime"=>time(),
- "classify"=>1,
- "subject"=>$subjectId,
- );
- $students=$this->getManyProductOrder($intarr,array(1,2,3,31),$students);
- if(count($allClassStudents)>count($students)){
- $result['all_order']=0;
- }else{
- $result['all_order']=1;
- }
- if(!$students){
- $result['msg']='当前班级没查询到订单';
- exit(json_encode($result));
- }
- //查询生成状态
- $studentPdf=$this->sConn->createCommand("select student_id,answer_card_online_url from student_answer_card_online where answer_card_online_created=1 and exam_id='".$examId."' and student_id in(".implode(',',$students).") ")->queryAll();
- if(!$studentPdf){
- $result['msg']='答题卡还未生成';
- exit(json_encode($result));
- }
- if(count($studentPdf)!=count($students)){
- $result['all_created']=0;
- }else{
- $result['all_created']=1;
- }
- $result['success']=1;
- $result['students']=$students;
- exit(json_encode($result));
- }
- /*导出考试数据*/
- public function actionExportExamData(){
- $examGroupId = Req::post('examGroupId');
- $params=array(
- 'examGroupId'=>$examGroupId,
- 'schoolId'=>$this->schoolId,
- 'reGenerate'=>1
- );
- $result['status']=0;
- $rs = http('/teacher/academic/report/download/exam-info','POST',$this->schoolId,$params,'cgi');
- $rs=json_decode($rs,true);
- if(isset($rs['errCode']) && $rs['errCode']=='00' ){
- if($rs['data']){
- $result['status']=1;
- $result['data']=$rs['data'];
- }else{
- $result['status']=2;
- }
- }else{
- $result['msg']="接口处理异常:".$rs['errMsg'];
- }
- exit(jsonEncode($result));
- }
- }
|