1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646 |
- <?php
- class RecordController extends Controller{
- public function actionAddAct(){
- $recordData = Filter::act($_POST);
- $uploader = new Uploader("upload/xls/");
- $uploader->allowTypes = array("xls");
- $rs = $uploader->act();
- $xls = current($rs);
- $xls = $xls ? $xls[0] : array();
- if(!$xls){
- Yii::app()->jump->error('请选择上传的Excel文件');
- }
- if(!in_array($xls["ext"], array("xls", "xlsx")))
- Yii::app()->jump->error('上传的文件必须是Excel文件');
- $rs = $this->schoolManager->insertExamRecord($recordData, $xls);
- $url = "record/index";
- if(isset($recordData["class_id"]) && $recordData["class_id"])
- $url .= "?classId={$recordData["class_id"]}";
- $url = $this->createUrl($url);
- $result = array();
- $result["url"] = $url;
- $result["title"] = "导入结果";
- if(is_array($rs)){
- $result["result"] = $rs["global"]["result"];
- $errorsCount = count($rs["errors"]);
- $result["content"] = "
- {$rs["global"]["msg"]}<br/>
- ";
- $errorsCount = 0;
- $result["content"] = "";
- foreach($rs["errors"] as $key => $val){
- if($val["count"]){
- $errorsCount++;
- $result["content"] .= "
- 错误{$errorsCount}:<br/>
- 错误原因:{$val["type"]}<br/>
- 错误信息:{$val["msg"]}<br/>
- ";
- }
- }
- $result["content"] = "
- {$rs["global"]["msg"]}<br/>
- 共遇到{$errorsCount}个错误<br/>
- {$result["content"]}
- ";
- }
- else{
- $result["result"] = "失败";
- $result["content"] = "
- 共遇到1个错误<br/>
- 错误原因:数据库操作出错<br/>
- 错误信息:数据写入失败<br/>
- ";
- }
- Yii::app()->cache->set("coach_".Yii::app()->session->sessionID."_tips", $result, 120);
- $this->redirect($this->createUrl("index/showtips"));
- }
- public function actionDelAct(){
- $examId = Req::post("examId");
- $rs = $this->schoolManager->delExam($examId, 2);
- $code = $rs ? "0" : "1";
- $msg = array(
- "0" => "删除成功",
- "1" => "删除失败",
- );
- $rs = array(
- "code" => $code,
- "msg" => isset($msg[$code]) ? $msg[$code] : "",
- );
- echo json_encode($rs);exit;
- }
- public function actionEdit(){
- $examId = Req::get("examId");
- $classes = $this->schoolManager->getClasses();
- $exam = $this->schoolManager->getExam($examId);
- $examClassesIds = $this->schoolManager->getExamClassesIds($examId);
- $this->render("edit", array(
- "classes" => $classes,
- "examClassesIds" => $examClassesIds,
- "exam" => $exam,
- ));
- }
- public function actionIndex(){
- $classId = Req::get("classId");
- $grade = Req::get("grade");
- if(!$grade && !$classId){
- $grade = "1";
- }
- else if($classId){
- $class = $this->schoolManager->getClass($classId);
- if(!$class) $grade = "1";
- else $grade = $class["grade"];
- }
- $classes = $this->schoolManager->getClasses($grade);
- if(!$classId){
- $class = current($classes);
- if($class)
- $classId = $class["class_id"];
- }
- $rs = $this->schoolManager->getClassExamsList($classId);
- $this->render("index", array(
- "exams" => $rs["rs"],
- "pager" => $rs["pager"],
- "class" => $class,
- "classes" => $classes,
- "grade" => $grade,
- ));
- }
- public function actionGetGradeClassesJson(){
- $grade = Req::get("grade");
- echo json_encode($this->schoolManager->getClasses($grade));exit;
- }
- public function actionView(){
- $examId = Req::get("examId");
- $records = $this->schoolManager->getExamRecordsList($examId);
- $this->render("view", array(
- "records" => $records,
- ));
- }
- public function actionTo_zhixue_grade()
- {
- $data = array();
- $exam_group_ids = array();
- $exam_data = array();
- $exam_groups = array();
- // $condition[] = "eg.create_type in (0,1,2,3) ";
- $criteria = new CDbCriteria();
- $criteria->addCondition('semester_id = '.$this->semesterId);
- $criteria->addInCondition('subject_id',$this->mathSubjectId);
- $criteria->addCondition('status = 3');
- $criteria->addCondition('upload_status = 0');
- $criteria->order = 'create_time desc';
- $exam_all_data = Exam::model()->findAll($criteria);
- unset($criteria);
- if($exam_all_data)
- {
- foreach ($exam_all_data as $v)
- {
- $exam_group_ids[$v->exam_group_id] = $v->exam_group_id;
- $exam_data[$v->exam_group_id] = $v;
- }
- if($exam_group_ids)
- {
- $criteria = new CDbCriteria();
- $criteria->addInCondition('exam_group_id',$exam_group_ids);
- $criteria->addInCondition('create_type ',array(0,1,2,3));
- $exam_group_data = ExamGroup::model()->findAll($criteria);
- }
- if($exam_group_data)
- {
- foreach ($exam_group_data as $v)
- {
- if(isset($exam_data[$v->exam_group_id]))
- {
- $exam_groups[] = $exam_data[$v->exam_group_id];
- }
- }
- }
- $data['exam_info'] = $exam_groups;
- }
- unset($exam_all_data);
- $data["use_zhixue"] = $this->schoolInfo->use_zhixue;
- $this->render("to_zhixue_grade",$data);
- }
- public function actionZhixue_import()
- {
- ini_set ('memory_limit', '300M');
- if(!$_FILES){
- Yii::app()->jump->error('文件大小超过范围');
- }else{
- if(!isset($_FILES['exname']) || !isset($_FILES['exname']['size']) || $_FILES['exname']['size'] > 5242880){
- Yii::app()->jump->error('文件大小超过范围');
- }
- }
- if (Yii::app()->request->getIsPostRequest()) {
- $bstudents = new BusinessStudent();
- $exam_group_id = Req::post("exam_group_id");
- if(!$exam_group_id)
- {
- Yii::app()->jump->error('请选择考试信息');
- }
- $uploader = new Uploader("upload/tmpDir/zhixue_chengji/{$this->schoolId}/");
- $uploader->allowTypes = array("xls","xlsx");
- $uploader->fieldsMappings = array("exname" => array(0 => $this->schoolId . date('Ymdhis', time())));
- $file = $uploader->act();
- $file = Arr::current(Arr::current($file));
- if (!$file || !isset($file["error"]))
- Yii::app()->jump->error('请上传Excel!');
- if ($file["error"] != 0) {
- switch ($file["error"]) {
- case 2001:
- Yii::app()->jump->error('文件类型不符');
- break;
- case 2002:
- Yii::app()->jump->error('文件大小超出允许范围');
- break;
- default:
- Yii::app()->jump->error('上传失败');
- break;
- }
- }
- $inputFileName = $file["src"];
- // 导入PHPExcel类
- Yii::import('application.extensions.*');
- require_once('phpexcel/PHPExcel/IOFactory.php');
- // 读取Excel文档
- $exam_id = '';
- $exam_ids = array();
- $topic_count = 0;
- $zhixue_student_card = array();
- $class_name_data = array();
- $student_ids = array();
- $student_topic = array();
- $student_name_data = array();
- $_student_name_data = array();
- $tops = array();
- $scores = array();
- $_err = array();
- $_paper_ids = array();
- $_student_paper_ids = array();
- $_exam_ids = array();
- $total_score = 0;
- $student_score = array();
- $student_paper_all = array();
- $student_paper = array();
- $sql_arr = array();
- $student_paper_info = array();
- $paper_ids = array();
- $paper_student_ids = array();
- $zhixue_student_cards =array();
- $id_sum = 0;
- try{
- $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
- $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
- // FIXME 20191202
- @unlink($file["src"]);
- }catch (Exception $e){
- // FIXME 20191202
- @unlink($file["src"]);
- Yii::app()->jump->error('Excel格式不正确:'.$e->getMessage());
- }
- if(!$sheetData)
- {
- Yii::app()->jump->error('请正确的Excel!');
- }
- unset($objPHPExcel);
- unset($sheetData[1]);
- krsort($sheetData);
- $sheetData = array_reverse($sheetData);
- $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- if($exam_group_data)
- {
- foreach($exam_group_data as $v)
- {
- $exam_ids[$v->exam_id] = $v->exam_id;
- $exam_id = $v->exam_id;
- $tpl_data = json_decode($v->tpl_data,1);
- if(isset($tpl_data['scores']))
- {
- $total_score = $tpl_data['scores'];
- }
- }
- unset($exam_group_data);
- $paper_data = SPaper::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id));
- if($paper_data)
- {
- $paper_topic_data = SPaperTopicRelation::model()->findAll(array('order'=>'`type` asc,`order` asc','condition'=>'paper_id=:paper_id','params'=>array(':paper_id'=>$paper_data->paper_id)));
- if($paper_topic_data)
- {
- foreach($paper_topic_data as $k=>$v)
- {
- $tops[$k] = $v->topic_id;
- $types[$v->topic_id] = $v->type;
- $scores[$v->topic_id] = $v->score;
- }
- unset($paper_data);
- $criteria = new CDbCriteria();
- //$criteria->select = 'student_id,paper_id,class_id,exam_id,semester_id,student_card,school_student_card,partial_right_count,compare,right_count,wrong_count,lost_score';
- $criteria->addInCondition('exam_id',$exam_ids);
- $criteria->addCondition('is_del=0');
- $student_paper_all_data = SStudentPaperRelation::model()->findAll($criteria);
- if($student_paper_all_data)
- {
- foreach($student_paper_all_data as $v)
- {
- $student_paper_all[$v->student_id] = $v->exam_id;
- $student_paper[$v->student_id] = $v->paper_id;
- $paper_ids[$v->paper_id] = $v->paper_id;
- $_paper_ids[$v->exam_id] = $v->paper_id;
- $student_paper_info[$v->student_id] = $v;
- }
- }
- unset($criteria);
- unset($student_paper_all_data);
- foreach($sheetData as $xv)
- {
- if(isset($xv['A']) && !empty($xv['A']) && isset($xv['B']) && !empty($xv['B']) && isset($xv['C'])&& !empty($xv['C']) && isset($xv['D']))
- {
- if(!is_numeric($xv['B'])){
- continue;
- }
- $id_sum++;
- if(isset($xv['E']))
- {
- $z_card = (string)$xv['B'];
- if(in_array($z_card, $zhixue_student_cards)){
- continue;
- }
- $zhixue_student_cards[$z_card] = $z_card;
- $student_name_data[(string)$z_card] = $xv['A'];
- $_student_name_data[(string)$z_card] = $xv['A'];
- $class_name_data[(string)$z_card] = $xv['C'];
- $student_topic[(string)$z_card] = array_merge(array(),array_slice($xv,4));
- $zhixue_student_card[(string)$z_card] = $z_card;
- $student_score[(string)$z_card] = (float)$xv['D'];
-
- //验证导入的成绩
- if($student_score[(string)$z_card] && $student_topic[(string)$z_card]){
- if($student_score[(string)$z_card] != array_sum($student_topic[(string)$z_card])){
- $_err['total_score']['student'][] = $xv['A'];
- }
- }
- if($student_topic[(string)$z_card] && $scores){
- if(count($scores) != count($student_topic[(string)$z_card])){
- $_err['score_count']['student'][] = $xv['A'];
- }else{
- $n = 0;
- $m = 0;
- foreach($scores as $v){
- $scoreArr = array_slice($student_topic[(string)$z_card],$n,1);
- if((int)$v < (int)current($scoreArr)){
- $_err['wrong_score']['student'][$z_card] = $xv['A'];
- }
- $n++;
- }
- }
-
- }
- }else
- {
- $_err['no_score']['student'][] = $xv['A'];
- }
- }else
- {
- //$_err['no_topic']['student'][] = $xv['A'];
- continue;
- }
- }
-
- if(!$zhixue_student_card){
- Yii::app()->jump->error('没有需要导入的正常数据');
- }
- $_uuid_arr = $this->createId(count($types)*$id_sum);
- $_uuid_arr_num = count($_uuid_arr);
- if(!$_uuid_arr)
- {
- Yii::app()->jump->error('预定义UUID不足,请联系技术人员');
- }
- // $criteria = new CDbCriteria();
- // $criteria->select = 'student_id,zhixue_student_card';
- // $criteria->addCondition('school_id=:school_id');
- // $criteria->addInCondition('zhixue_student_card',$zhixue_student_card);
- // $criteria->params[':school_id'] = $this->schoolId;
- // $b_student_data = BusinessStudent::model()->findAll($criteria);
- // unset($criteria);
- //处理准考证号量太大的问题
- $ArrCount=count($zhixue_student_card);
- $Student_data_temp=array();
- $b_student_data=array();
- if($ArrCount<500){
- $Student_data_temp = $bstudents->getStudentsBySchoolIdAndZhixuecard($this->schoolId,$zhixue_student_card);
- }elseif($ArrCount<1000){
- $TempArr=array_chunk($zhixue_student_card, 2);
- }else{
- $TempArr=array_chunk($zhixue_student_card, 5);
- }
- if($Student_data_temp){
- $b_student_data=$Student_data_temp;
- }elseif($TempArr){
- foreach ($TempArr as $item){
- $Student_data_temp=$bstudents->getStudentsBySchoolIdAndZhixuecard($this->schoolId,$item);
- if($Student_data_temp){
- $b_student_data=array_merge($b_student_data,$Student_data_temp);
- }
- }
- }
- // $b_student_data = $bstudents->getStudentsBySchoolIdAndZhixuecard($this->schoolId,$zhixue_student_card);
- if($b_student_data)
- {
- // foreach($b_student_data as $v)
- // {
- // if(isset($student_paper_all[$v->student_id]) && !empty($student_paper_all[$v->student_id]))
- // {
- // $student_ids[(string)$v->zhixue_student_card] = $v->student_id;
- // $paper_student_ids[$v->student_id] = $v->student_id;
- // unset($_student_name_data[(string)$v->zhixue_student_card]);
- //
- // }else
- // {
- // continue;
- // }
- //
- //
- //
- // }
- foreach($b_student_data as $v)
- {
- if(isset($student_paper_all[$v['student_id']]) && !empty($student_paper_all[$v['student_id']]))
- {
- $student_ids[(string)$v['zhixue_student_card']] = $v['student_id'];
- $paper_student_ids[$v['student_id']] = $v['student_id'];
- unset($_student_name_data[(string)$v['zhixue_student_card']]);
- }else
- {
- continue;
- }
- }
- unset($b_student_data);
- //写入
- $sql = '';
- $sql_sum = 0;
- $_sql_sum = 0;
- $_sql = '';
- $_sql_arr = array();
- /* */
- foreach($zhixue_student_card as $v)
- {
- $v = (string)$v;
- $complete_count = 0;
- $r_count = 0;
- $f_count = 0;
- $_student_id = 0;
- $_scoring = isset($student_score[$v])?$student_score[$v]:0;
- if(isset($student_topic[$v]))
- {
- if( count($student_topic[$v]) != count($paper_topic_data))
- {
- Yii::app()->jump->error('导入的题数不正确!');exit;
- }
- }
- if(isset($student_ids[$v]) && !empty($student_ids[$v]) && isset($student_paper[$student_ids[$v]]) && !empty($student_paper[$student_ids[$v]]) && isset($student_paper_info[$student_ids[$v]]))
- {
- $_paper_id = $student_paper[$student_ids[$v]];
- $_student_id = $student_ids[$v];
- if(isset($student_topic[$v]) && !empty($student_topic[$v]))
- {
- $i = 0;
- foreach($student_topic[$v] as $key => $val)
- {
- $val = (int)$val;
- $complete_count += 1;
- $topic_id = '';
- $_score = 0;
- $type = '';
- $is_right = 0;
- if(isset($tops[$i]) && !empty($tops[$i]))
- {
- $topic_id = $tops[$i];
- if(isset($scores[$tops[$i]]) && !empty($scores[$tops[$i]]))
- {
- $_score = $scores[$tops[$i]];
- }
- if(isset($types[$tops[$i]]) && !empty($types[$tops[$i]]))
- {
- $type = $types[$tops[$i]];
- }
- }
- if($type==1)
- {
- if($val==$_score)
- {
- $is_right = 1;
- $r_count += 1;
- }elseif($val>0 && $val<$_score)
- {
- $val = 0;
- $f_count +=1;
- }else
- {
- $f_count +=1;
- }
- }
- if($type==5)
- {
- if($val==$_score)
- {
- $is_right = 1;
- $r_count += 1;
- }else
- {
- $f_count +=1;
- }
- }
- if($type>5)
- {
- if($val==$_score)
- {
- $is_right = 1;
- $r_count += 1;
- }elseif($val>0 && $val<$_score)
- {
- if($_score*0.8<$val)
- {
- $is_right = 1;
- $r_count += 1;
- }else{
- $is_right = 2;
- $f_count +=1;
- }
- }
- }
- if(empty($val))
- {
- $val=0;
- }
- $_uuid = current($_uuid_arr);
- unset($_uuid_arr[$_uuid]);
- $sql.="(".$_uuid.",".$_student_id.",".$_paper_id.",".$topic_id.",".$type.','.$is_right.','.$val.",''),";
- if($sql_sum==300 )
- {
- $sql = substr($sql,0,-1).';';
- $sql_arr[] = $sql;
- $sql_sum = 0;
- $sql = '';
- }
- $i++;
- $sql_sum++;
- }
- }
- unset($student_topic[$v]);
- $paper_obj = $student_paper_info[$_student_id];
- $_sql.= "(".$paper_obj->student_id.",".$paper_obj->paper_id.",".$paper_obj->class_id.",".$paper_obj->exam_id.",".$paper_obj->semester_id.",".$paper_obj->student_card.",'".$paper_obj->school_student_card."',".$complete_count.",".$r_count.",".$paper_obj->partial_right_count.",".$f_count.",".$_scoring.",".($total_score-$_scoring).",".$paper_obj->compare.",0,1,1,".time().",".time().",''),";
- if($_sql_sum ==300)
- {
- $_sql = substr($_sql,0,-1).';';
- $_sql_arr[] = $_sql;
- $_sql_sum = 0;
- $_sql = '';
- }
- $_sql_sum++;
- }else
- {
- $_err['no_student']['student'][] = isset($student_name_data[(string)$v])?$student_name_data[(string)$v]:'';
- continue;
- }
- }
- unset($zhixue_student_card);
- $result = '';
- if($_student_name_data)
- {
- $_err['no_student']['no_exam_student'] = $_student_name_data;
- }
- if($_err)
- {
- $y = 0;
- foreach($_err as $k=>$v)
- {
- if($k=='no_score')
- {
- $result['msg'][$y]['title'] = '错误无分数';
- $result['msg'][$y]['result'] = implode(',',$v['student']);
- }
- if($k=='no_topic')
- {
- $result['msg'][$y]['title'] = '无做题';
- $result['msg'][$y]['result'] = implode(',',$v['student']);
- }
- if($k=='no_exam_student')
- {
- $result['msg'][$y]['title'] = '无考试';
- $result['msg'][$y]['result'] = implode(',',$v['student']);
- }
- if($k=='no_student')
- {
- $result['msg'][$y]['title'] = '不存在学生';
- $result['msg'][$y]['result'] = implode(',',$v['student']);
- }
- if($k=='wrong_score')
- {
- $result['msg'][$y]['title'] = '上传成绩超出试卷小题成绩';
- $result['msg'][$y]['result'] = implode(',',$v['student']);
- }
- if($k=='total_score')
- {
- $result['msg'][$y]['title'] = '上传成绩总分与各小题不符';
- $result['msg'][$y]['result'] = implode(',',$v['student']);
- }
- $y++;
- }
- $result['url'] = Yii::app()->createUrl('record/to_zhixue_grade');
- $this->render('show',$result);exit;
- }
- if($sql){
- $sql = substr($sql,0,-1).';';
- $sql_arr[] = $sql;
- }
- if(!$sql_arr )
- {
- Yii::app()->jump->error('数据有误,无法导入!');exit;
- }
- if($_sql){
- $_sql = substr($_sql,0,-1).';';
- $_sql_arr[] = $_sql;
- }
- if(!$_sql_arr )
- {
- Yii::app()->jump->error('数据有误,无法导入!');exit;
- }
- $transaction = $this->sConn->beginTransaction();
- try{
- $criteria = new CDbCriteria();
- $criteria->addInCondition('paper_id',$paper_ids);
- $criteria->addInCondition('student_id',$paper_student_ids);
- SStudentPaperTopicRs::model()->deleteAll($criteria);
- unset($criteria);
- $criteria = new CDbCriteria();
- $criteria->addInCondition('paper_id',$paper_ids);
- $criteria->addInCondition('student_id',$paper_student_ids);
- SStudentPaperRelation::model()->deleteAll($criteria);
- unset($criteria);
- $sql2 = 'INSERT INTO `student_paper_relation`
- (`student_id`,`paper_id`,`class_id`,`exam_id`,`semester_id`,`student_card`,`school_student_card`,`complete_count`,`right_count`,`partial_right_count`,`wrong_count`,`scoring`,`lost_score`,`compare`,`report_created`,`is_feedback`,`is_complete`,`feedback_time`,`complete_time`,`studytrend_exam_name`)VALUES';
- $sql1='INSERT INTO `student_paper_topic_rs`
- (`id`,`student_id`,`paper_id`,`topic_id`,`type`,`is_right`,`scoring`,`simplify_answer_url`)VALUES';
- if($sql_arr)
- {
- foreach($sql_arr as $k=>$v)
- {
- if($v==';')
- {
- throw new Exception('数据有误,无法导入!');
- }
- $this->sConn->createCommand($sql1.$v)->execute();
- ob_flush();
- }
- }
- unset($sql_arr);
- if($_sql_arr)
- {
- foreach($_sql_arr as $v)
- {
- if($v==';')
- {
- throw new Exception('数据有误,无法导入!');
- }
- $this->sConn->createCommand($sql2.$v)->execute();
- }
- }
- unset($_sql_arr);
- Exam::model()->updateAll(array('upload_status'=>2,'status'=>1,'is_topwb_html'=>0,'is_topwb_pdf'=>0,'is_academicr_html'=>0,'is_academicr_pdf'=>0,'update_time'=>time(),'complete_time'=>time()),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- ExamGroup::model()->updateAll(array('mark_status'=>2,'upload_status'=>2,'status'=>2,'import_score_type'=>1),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- $transaction->commit();
- }catch(Exception $e)
- {
- $transaction->rollBack();
- Yii::app()->jump->error('Excel导入失败!');
- }
- //$this->UUID_log($exam_group_id,$_uuid_arr_num);
- Yii::app()->jump->error('Excel导入成功!');
- }else
- {
- $result['msg'][0]['title'] = '学生不存在';
- $result['msg'][0]['result'] = '此文档中所有学生不存在';
- $result['url'] = Yii::app()->createUrl('record/to_zhixue_grade');
- $this->render('show',$result);exit;
- }
- }
- }
- }
- Yii::app()->jump->error('Excel导入失败!');
- }
- }
- //预生成ID
- private function addSetUUID($_uuid_arr)
- {
- if($_uuid_arr)
- {
- Yii::app()->business_uuid_cache->hmset('redis_business_uuid:'.$this->schoolId,$_uuid_arr);
- }
- }
- private function UUID_log($exam_group_id,$sum)
- {
- Yii::app()->business_uuid_cache->setValue('redis_business_uuid_log'.$this->schoolId,'导入智学网成绩,使用了'.$sum.'个UUID,导入时间为'.date('Y-n-d H:i:s',time()).',导入考试的ID:'.$exam_group_id);
- Yii::app()->redis_business_student->expire('redis_business_uuid_log:'.$this->schoolId,86400);
- }
- //新版导入成绩
- public function actionImportScore(){
- $examGroupId=Req::get('exam_group_id');
- $checkField=Req::get('check_field');
- $renew=Req::get('renew');
- $data = array();
- $sql="select * from import_score_temp where exam_type=0 limit 1";
- $data=$this->sConn->createCommand($sql)->queryRow();
- if($data){
- $this->redirect(Yii::app()->createUrl('record/check_excel'));
- }else{
- $sql="select * from import_score_temp where exam_type=2 limit 1";
- $data=$this->sConn->createCommand($sql)->queryRow();
- if($data) {
- $this->redirect(Yii::app()->createUrl('record/checkImgExcel'));
- }
- }
- $exam=Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId));
- $data['exam_name']=$exam['name'];
- $data['exam_group_id']=$examGroupId;
- $data['check_field']=$checkField;
- $data['renew']=$renew;
- //扩展字段设置
- $studentExtend=$this->schoolManager->getStudentExtend();
- $data['studentExtend']=$studentExtend;
- $this->render('import', $data);
- }
- //加载考试
- public function actionAjaxSearchExam(){
- $exam_type=Req::post('exam_type');
- $subject=Req::post('subject');
- $grade=Req::post('grade');
- $class=Req::post('class');
- $keyword=Req::post('keyword');
- $condition=array();
- //$condition[]=" (eg.qxk_paper_id=0 or eg.qxk_paper_id is null)";
- $condition[]="e.semester_id='{$this->semesterId}'";
- $condition[] = "e.is_display = 0";
- if($exam_type==1){
- $condition[]='eg.is_third=0';
- }elseif($exam_type==2){
- $condition[]='eg.is_third=1';
- }
- $condition[] = "eg.homework = 0";
- $condition[] = "eg.import_score_type <> 2";
- 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."'";
- }
- if($keyword){
- $condition[]="e.name like '%".$keyword."%'";
- }
- $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 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 ";
- if($condition){
- $sql.=" where ".implode(' and ',$condition);
- }
- $sql.=" order by e.create_time desc ";
- $Exam = $this->sConn->createCommand($sql)->queryAll();
- $list=array();
- if($Exam){
- $paperIds=array();
- $examGroupIds=array();
- foreach($Exam as $key=>$val){
- $paperIds[$val['exam_group_id']][]=$val['paper_id'];
- $examGroupIds[]=$val['exam_group_id'];
- $list[$val['exam_group_id']]=$val;
- }
- if($class && $examGroupIds){
- $paperIds=array();
- $sqlClassCount="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 FROM `exam_group` eg ";
- $sqlClassCount.="join exam e on eg.exam_group_id=e.exam_group_id ";
- $sqlClassCount.="join class c on c.class_id=e.class_id ";
- $sqlClassCount.="join paper p on p.exam_id=e.exam_id ";
- $sqlClassCount.=" where e.exam_group_id in(".implode(',',$examGroupIds).")";
- $ExamCount = $this->sConn->createCommand($sqlClassCount)->queryAll();
- foreach ($ExamCount as $val){
- $paperIds[$val['exam_group_id']][]=$val['paper_id'];
- $list[$val['exam_group_id']]=$val;
- }
- }
- //debug($examGroupIds);
- if($list){
- foreach ($list as $key=>$val){
- $list[$key]['student_score_count']=0;
- $list[$key]['class_count']=0;
- $list[$key]['exam_date']='';
- if(isset($paperIds[$val['exam_group_id']])){
- $list[$key]['class_count']=count($paperIds[$val['exam_group_id']]);
- $sql_student_paper="select count(*) as count from student_paper_relation where paper_id in(".implode(',',$paperIds[$val['exam_group_id']]).") and is_feedback=1";
- $studentCount = $this->sConn->createCommand($sql_student_paper)->queryRow();
- if($studentCount){
- if($val['import_score_type']==0 && $studentCount['count']>0){
- //扫描成绩,跳过
- unset($list[$key]);
- continue;
- }else{
- $list[$key]['student_score_count']=$studentCount['count'];
- }
- }
- }
- if($val['tpl_data']){
- $tpl_data=json_decode($val['tpl_data'],true);
- if(isset($tpl_data['examDate'])){
- $list[$key]['exam_date']=$tpl_data['examDate'];
- }
- }
- if(isset(Yii::app()->params['grade_list'][$val['grade']])){
- $list[$key]['grade']=Yii::app()->params['grade_list'][$val['grade']]['grade_name'];
- }else{
- $list[$key]['grade']='';
- }
- }
- }
- }
- $result['status']=1;
- $result['list']=$list;
- exit(json_encode($result));
- }
- //新版全学科导入成绩,导入表格
- public function actionImportStore(){
- ini_set ('memory_limit', '300M');
- if(!$_FILES){
- Yii::app()->jump->error('文件大小超过范围');
- }else{
- if(!isset($_FILES['exname']) || !isset($_FILES['exname']['size']) || $_FILES['exname']['size'] > 5242880){
- Yii::app()->jump->error('文件大小超过范围');
- }
- }
- if (Yii::app()->request->getIsPostRequest()) {
- $exam_group_id=Req::post('exam_group_id');
- $check_field=Req::post('check_field');
- $exam_renew=Req::post('exam_renew');
- if(!$exam_group_id)
- {
- Yii::app()->jump->error('请选择考试信息');
- }
- $uploader = new Uploader("upload/tmpDir/zhixue_chengji/{$this->schoolId}/");
- $uploader->allowTypes = array("xls","xlsx");
- $uploader->fieldsMappings = array("exname" => array(0 => $this->schoolId . date('Ymdhis', time())));
- $file = $uploader->act();
- $file = Arr::current(Arr::current($file));
- if (!$file || !isset($file["error"]))
- Yii::app()->jump->error('请上传的Excel!');
- if ($file["error"] != 0) {
- switch ($file["error"]) {
- case 2001:
- Yii::app()->jump->error('文件类型不符');
- break;
- case 2002:
- Yii::app()->jump->error('文件大小超出允许范围');
- break;
- default:
- Yii::app()->jump->error('上传失败');
- break;
- }
- }
- $inputFileName = $file["src"];
- // 导入PHPExcel类
- Yii::import('application.extensions.*');
- require_once('phpexcel/PHPExcel/IOFactory.php');
- try{
- $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
- $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
- // FIXME 20191202
- @unlink($file["src"]);
- }catch (Exception $e){
- // FIXME 20191202
- @unlink($file["src"]);
- Yii::app()->jump->error('Excel格式不正确:'.$e->getMessage());
- }
- if(!$sheetData)
- {
- Yii::app()->jump->error('请正确的Excel!');
- }
- unset($objPHPExcel);
- if(($check_field=='student_name' && $sheetData[1]['C']!='科目总分') || ($check_field!='student_name' && $sheetData[1]['C']=='科目总分')){
- Yii::app()->jump->error('Excel格式不正确!');
- }
- unset($sheetData[1]);
- if(!$sheetData)
- {
- Yii::app()->jump->error('请输入学生成绩数据');
- }
- $insertSql="insert into import_score_temp(`student_name`,`class_name`,`check_field_value`,`score_data`,`exam_group_id`,`check_field`,`renew`) values";
- $valuesArray=array();
- foreach ($sheetData as $val){
- if(!isset($val['A']) || !isset($val['B']) || !isset($val['C']) || !isset($val['D'])){
- continue;
- }
- $student_topic= array_merge(array(),array_slice($val,2));
- $regex = '/^[a-zA-Z0-9]+$/u';
- if($check_field=='student_name'){
- $topic_score=array_slice($student_topic,1);
- $check_field_value=$val['A'];
- }else{
- $topic_score=array_slice($student_topic,2);
- $check_field_value=$val['C'];
- if(!preg_match($regex, $check_field_value)){
- Yii::app()->jump->error('识别考号内容只能是数字和字母');
- }
- }
- foreach ($topic_score as $k=>$v){
- if(!empty($v) && (!is_numeric($v) || floatval($v)<0)){
- Yii::app()->jump->error('分数必须是数值类型且》=0');
- }
- }
-
- if($check_field=='student_name'){
- $valuesArray[]="('".$val['A']."','".$val['B']."','','".json_encode($student_topic)."','".$exam_group_id."','".$check_field."','".$exam_renew."')";
- }else{
- $valuesArray[]="('".$val['A']."','".$val['B']."','".$val['C']."','".json_encode($student_topic)."','".$exam_group_id."','".$check_field."','".$exam_renew."')";
- }
- }
- if($valuesArray){
- // $delSql="truncate table import_score_temp;";
- $delSql="delete from import_score_temp;";
- $this->sConn->createCommand($delSql)->execute();
- $insertSql.=implode(',',$valuesArray);
- $this->sConn->createCommand($insertSql)->execute();
- $this->redirect(Yii::app()->createUrl('record/check_excel'));
- }else{
- Yii::app()->jump->error('没有发现学生成绩数据');
- }
- Yii::app()->jump->error('导入失败');
- }
- }
- //导入数据检测页
- public function actionCheck_Excel(){
- $sql="select * from import_score_temp where exam_type=0 limit 1";
- $data=$this->sConn->createCommand($sql)->queryRow();
- $fileName=array(
- 'student_name'=>'学生姓名',
- 'userno'=>'学号',
- 'student_card'=>'准考证号',
- 'school_student_card'=>'学校准考证号',
- 'zhixue_student_card'=>'智学网考证号',
- 'id_number'=>'身份证号',
- 'student_phone'=>'手机号'
- );
- //扩展字段
- $studentExtend=$this->schoolManager->getStudentExtend();
- if($studentExtend){
- foreach ($studentExtend as $key=> $value){
- $fileName[$key]=$value['field_mean'];
- }
- }
- if(isset($fileName[$data['check_field']])){
- $data['check_field_name']=$fileName[$data['check_field']];
- }else{
- $data['check_field_name']='学生姓名';
- }
- $data['need_check_name']=0;
- if($data['check_field_name']=='学生姓名'){
- $data['need_check_name']=1;
- }
- $this->render('check',$data);
- }
- //处理导入数据页面
- public function actionHandle_Excel(){
- $this->render('handle');
- }
- //检测格式
- public function actionCheck_field_first(){
- $result['status']=0;
- $sql="select * from import_score_temp where exam_type=0";
- $All_Data=$this->sConn->createCommand($sql)->queryAll();
- if(!$All_Data){
- exit(json_encode($result));
- }
- $data=$All_Data[0];
- $check_field=$data['check_field'];
- $score_data=json_decode($data['score_data'],true);
- $exam_group_id=$data['exam_group_id'];
- if(!$score_data){
- $result['msg']='数据不完整';
- exit(json_encode($result));
- }
- $examGroup=SExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- //检测题量
- $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- $total_score=0;
- if($exam_group_data) {
- foreach ($exam_group_data as $v) {
- $exam_id = $v->exam_id;
- $tpl_data = json_decode($v->tpl_data, 1);
- if (isset($tpl_data['scores'])) {
- $total_score = $tpl_data['scores'];
- }
- break;
- }
- unset($exam_group_data);
- $paper_data = SPaper::model()->find('exam_id=:exam_id', array(':exam_id' => $exam_id));
- $paper_topic_data = SPaperTopicRelation::model()->findAll(array('order'=>'`no` asc','condition'=>'paper_id=:paper_id','params'=>array(':paper_id'=>$paper_data->paper_id)));
- if(!$paper_topic_data){
- $result['msg']='请先关联答题卡再上传成绩';
- exit(json_encode($result));
- }
- $alias=array();
- $sortPaperTopic=array();
- //检测试题别名
- if(isset($tpl_data['new_items']) && !$examGroup['qxk_paper_id']){
- foreach ($tpl_data['new_items'] as $item){
- $alias[$item['id']]=$item['alias'];
- }
- //重新排序
- foreach ($paper_topic_data as $key =>$datum){
- $sortPaperTopic[$alias[$datum['order']]]=$datum;
- }
- ksort($sortPaperTopic);
- $sortPaperTopic=array_values($sortPaperTopic);
- }else{
- $sortPaperTopic=$paper_topic_data;
- }
- //检测试题数据
- foreach($All_Data as $key=> $val){
- $score_data=json_decode($val['score_data'],true);
- if($check_field!='student_name'){
- $topic_score=array_slice($score_data,2);
- $total_score_import=$score_data['D'];
- }else{
- $topic_score=array_slice($score_data,1);
- $total_score_import=$score_data['C'];
- }
- if($total_score_import!=array_sum($topic_score)){
- $result['msg']='科目总分和试题总分不一致:'.$val['student_name'];
- exit(json_encode($result));
- }
- if(count($topic_score)!=count($sortPaperTopic)){
- $result['msg']='上传题量和试卷题量不一致:'.$val['student_name'];
- exit(json_encode($result));
- }
- $topic_score=array_values($topic_score);
- foreach($topic_score as $order => $v){
- if(!empty($v) && (!is_numeric($v) || floatval($v)<0)){
- $result['msg']='试题分数必须是数值类型:'.$val['student_name'];
- exit(json_encode($result));
- }
- if(isset($sortPaperTopic[$order])){
- if($v>$sortPaperTopic[$order]['score']){
- $result['msg']=$val['student_name'].':第'.($order+1).'题试题分数和考试设置分数不一致,提交分数:'.$v."试卷设置分数:".$sortPaperTopic[$order]['score'];
- exit(json_encode($result));
- }
- }else{
- $result['msg']='上传题量和试卷题量不一致';
- exit(json_encode($result));
- }
- }
- }
- $result['msg']='检测完成';
- $result['status']=1;
- }else{
- $result['msg']='未发现对应考试';
- exit(json_encode($result));
- }
- exit(json_encode($result));
- }
- //检测姓名
- public function actionCheck_student_name(){
- ini_set('memory_limit','512M');
- set_time_limit(0);
- $result['status']=0;
- $result['data']=0;
- $student_all_data = $this->sConn->createCommand("SELECT id,student_name FROM `import_score_temp` `t` where exam_type=0")->queryAll();
- if($student_all_data){
- //去除非中文字符
- $updateArr=array();
- $preg="/[^\x{4E00}-\x{9FFF}^·0-9]+/u";
- $count=0;
- foreach($student_all_data as $val){
- if(preg_match($preg,$val['student_name'])){
- $ModifyName = preg_replace($preg, "", $val['student_name']);
- if($ModifyName){
- $updateArr[$val['id']]=$ModifyName;
- $count++;
- }
- }else{
- $updateArr[$val['id']]=$val['student_name'];
- }
- }
- //组织更新语句
- if($updateArr){
- $arrNumber=ceil(count($updateArr)/500);
- $Arr=array_chunk($updateArr,$arrNumber,true);
- $transcation = $this->sConn->beginTransaction();
- try {
- foreach ($Arr as $item){
- $sql='update import_score_temp set `check_field_value`= case id ';
- foreach ($item as $key=> $val){
- $sql.=" WHEN ".$key." THEN '".$val."' ";
- }
- $sql.=" End ";
- $sql.=" where check_field_value='' or check_field_value is null and exam_type=0";
- $this->sConn->createCommand($sql)->execute();
- }
- $transcation->commit();
- $result['status']=1;
- }catch (Exception $e){
- $transcation->rollback();
- }
- }
- $result['count']=$count;
- }
- exit(json_encode($result));
- }
- //匹配信息
- public function actionMatching(){
- $noExistent=0; //不存在
- $repeat=0; //重复(组)
- $success=0; //匹配成功
- $scoreWrong=0; //成绩不正确
- $result['status']=0;
- $sql="select * from import_score_temp where exam_type=0 limit 1";
- $data=$this->sConn->createCommand($sql)->queryRow();
- if(!$data){
- exit(json_encode($result));
- }
- $check_field=$data['check_field'];
- $exam_group_id=$data['exam_group_id'];
- $classArr=array();
- $classIds=array();
- $check_data_group=array(); //检查字段对应临时表id
- $update_temp_data=array(); //更新临时表数据
- $student_card=array(); //学生id,准考证号对应数据
- $tpl_data=array();
- $updateSql=array();
- $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- $exam_group_data = $this->sConn->createCommand("SELECT e.exam_id,e.tpl_data,p.paper_id,e.class_id FROM `exam` e join paper p on e.exam_id=p.exam_id where e.exam_group_id='".$exam_group_id."'")->queryAll();
- $paperIds=array();
- if($exam_group_data){
- foreach ($exam_group_data as $v){
- if(!$tpl_data && isset($v['tpl_data'])){
- $tpl_data=json_decode($v['tpl_data'],true);
- }
- $classIds[]=$v['class_id'];
- $paperIds[]=$v['paper_id'];
- }
- }
- //统计已经匹配成功的数据
- $success_student_data = $this->sConn->createCommand("SELECT id,student_name,check_field,exam_group_id,score_data,check_field_value FROM `import_score_temp` `t` where student_id is not null and student_id<>0 and exam_type=0 ")->queryAll();
- if($success_student_data){
- $success=count($success_student_data);
- }
- $check_field_val_arr=array();
- $student_all_data = $this->sConn->createCommand("SELECT id,student_name,check_field,exam_group_id,score_data,check_field_value FROM `import_score_temp` `t` where student_id is null or student_id=0 and exam_type=0 ")->queryAll();
- if(!$student_all_data){
- $result['repeat']=0;
- $result['success']=$success;
- $result['noExistent']=0;
- $result['status']=1;
- exit(json_encode($result));
- }
- foreach ($student_all_data as $val){
- //验证学生分数
- $check_field_val_arr[]="'".$val['check_field_value']."'";
- $check_data_group[$val['check_field_value']]=$val['id'];
- }
- //处理重复数据
- $repeat_group_data=array();
- $search_value_arr=array();
- foreach ($check_field_val_arr as $value){
- $repeat_group_data[$value][]=$value;
- }
- foreach ($repeat_group_data as $key=>$val){
- if(count($val)>1){
- $repeat++;
- $modify_name=str_replace("'",'',$key);
- $updateSql[]="update import_score_temp set is_repeat=1 where check_field_value='".$modify_name."' and (student_id is null or student_id=0) and exam_type=0";
- }else{
- $search_value_arr[]=$val[0];
- }
- }
- if($search_value_arr){
- $student_info=array();
- $b_student=array();
- switch ($check_field){
- case 'student_name':
- $sql="select si.student_id,si.realname from student_info si join student_paper_relation spr on si.student_id = spr.student_id where realname in(".implode(',',$search_value_arr).") and paper_id in(".implode(',',$paperIds).")";
- $student_info=$this->sConn->createCommand($sql)->queryAll();
- break;
- case 'userno':
- $sql="select userno,spr.student_id from student_info si ";
- $sql.="join student_class_relation scr on scr.student_id=si.student_id ";
- $sql.="join student_paper_relation spr on si.student_id = spr.student_id ";
- $sql.=" where scr.userno in(".implode(',',$search_value_arr).") and scr.status=0 and scr.class_id in(".implode(',',$classIds).") and spr.paper_id in(".implode(',',$paperIds).")";
- $student_info=$this->sConn->createCommand($sql)->queryAll();
- break;
- case 'student_card':
- $sql="select student_id,student_card from student where student_card in(".implode(',',$search_value_arr).") and status=0";
- $b_student=$this->conn->createCommand($sql)->queryAll();
- break;
- case 'school_student_card':
- $sql="select student_id,school_student_card from student where school_student_card in(".implode(',',$search_value_arr).") and status=0";
- $b_student=$this->conn->createCommand($sql)->queryAll();
- break;
- case 'zhixue_student_card':
- $sql="select student_id,zhixue_student_card from student where zhixue_student_card in(".implode(',',$search_value_arr).") and status=0";
- $b_student=$this->conn->createCommand($sql)->queryAll();
- break;
- default:
- $sql="select * from student_info si join student_paper_relation spr on si.student_id = spr.student_id where `".$check_field."` in(".implode(',',$search_value_arr).") and paper_id in(".implode(',',$paperIds).") and is_del=0 ";
- $student_info=$this->sConn->createCommand($sql)->queryAll();
- }
- if($b_student){
- $studentIds=array();
- foreach ($b_student as $item){
- $studentIds[]=$item['student_id'];
- $student_card[$item['student_id']]=$item[$check_field];
- }
- $sql="select si.student_id from student_info si join student_paper_relation spr on si.student_id = spr.student_id where si.student_id in(".implode(',',$studentIds).") and paper_id in(".implode(',',$paperIds).") and is_del=0 ";
- $student_info=$this->sConn->createCommand($sql)->queryAll();
- if($student_info){
- foreach($student_info as $key=>$val){
- $student_info[$key][$check_field]=$student_card[$val['student_id']];
- }
- }
- }
- if(!$student_info){
- $noExistent=count($search_value_arr);
- $result['repeat']=$repeat;
- $result['success']=$success;
- $result['noExistent']=$noExistent;
- $result['status']=1;
- }else{
- $result['status']=1;
- //过滤掉已被删除的学生
- foreach ($student_info as $key=>$value){
- $sql_class_relation="select * from student_class_relation where student_id='".$value['student_id']."' and status=0 ";
- $student_class_realtion=$this->sConn->createCommand($sql_class_relation)->queryRow();
- if(!$student_class_realtion){
- unset($student_info[$key]);
- }
- }
- if($check_field=='student_name'){
- $nameArr=array();
- foreach ($student_info as $item){
- $preg="/[^\x{4E00}-\x{9FFF}^·0-9]+/u";
- $ModifyName = preg_replace($preg, "", $item['realname']);
- $nameArr[$ModifyName][]=$item;
- }
- $noExistent=count($search_value_arr)-count($nameArr);
- if($noExistent<0) $noExistent=0;
- $result['noExistent']=$noExistent;
- foreach ($nameArr as $key=>$value){
- if(count($value)>1){
- $repeat++;
- $updateSql[]="update import_score_temp set is_repeat=1 where check_field_value='".$key."' and (student_id is null or student_id=0) and exam_type=0";
- }else{
- $success++;
- if(isset($check_data_group[$key])){
- $update_temp_data[$check_data_group[$key]]=$value[0]['student_id'];
- }
- }
- }
-
- $result['repeat']=$repeat;
- $result['success']=$success;
- }else{
- $studentGroup=array();
- foreach ($student_info as $item){
- $studentGroup[$item[$check_field]][]=$item;
- }
- foreach ($studentGroup as $key=>$val){
- if(count($val)>1){
- $repeat++;
- $updateSql[]="update import_score_temp set is_repeat=1 where check_field_value='".$key."'and (student_id is null or student_id=0) and exam_type=0";
- }else{
- $success++;
- if(isset($check_data_group[$key])){
- $update_temp_data[$check_data_group[$key]]=$val[0]['student_id'];
- }
- }
- }
- $noExistent=count($search_value_arr)-count($studentGroup);
- if($noExistent<0) $noExistent=0;
- $result['noExistent']=$noExistent;
- $result['repeat']=$repeat;
- $result['success']=$success;
-
- }
- }
- }else{
- $result['repeat']=$repeat;
- $result['success']=$success;
- $result['noExistent']=0;
- $result['status']=1;
- }
- //更新检测成功的数据
- if($update_temp_data || $updateSql){
- $transcation = $this->sConn->beginTransaction();
- try {
- if($update_temp_data) {
- if ($check_field == 'student_name') {
- $sql = 'update import_score_temp set `student_id`= case id ';
- } else {
- $sql = 'update import_score_temp set `student_id`= case id ';
- }
- foreach ($update_temp_data as $key => $val) {
- $sql .= " WHEN " . $key . " THEN '" . $val . "' ";
- }
- $sql .= " End ";
- $sql .= " where (student_id='' or student_id is null) and exam_type=0";
- $this->sConn->createCommand($sql)->execute();
- }
- if($updateSql){
- foreach ($updateSql as $query){
- $this->sConn->createCommand($query)->execute();
- }
- }
- $transcation->commit();
- $result['status']=1;
- }catch (Exception $e){
- $result['status']=0;
- $transcation->rollback();
- }
- }
- exit(json_encode($result));
- }
- //重新上传
- public function actionGiveup(){
- // $delSql="truncate table import_score_temp;";
- $result['data']=$this->sConn->createCommand("select exam_group_id,check_field,renew from import_score_temp limit 1")->queryRow();
- $delSql="delete from import_score_temp where exam_type=0 or exam_type=2;";
- $this->sConn->createCommand($delSql)->execute();
- $result['status']=1;
- exit(json_encode($result));
- }
- //处理完毕,执行成绩导入
- public function actionUpdate_score(){
- ini_set('memory_limit','512M');
- $result['status']=0;
- $sql="select * from import_score_temp where student_id is not null and is_repeat=0 and exam_type=0";
- $all_data=$this->sConn->createCommand($sql)->queryAll();
- if(!$all_data){
- $result['msg']='没有发现可导入学生成绩数据';
- exit(json_encode($result));
- }
- $exam_group_id=$all_data[0]['exam_group_id'];
- $examGroup=$this->sConn->createCommand("SELECT qxk_paper_id FROM `exam_group` where exam_group_id='".$exam_group_id."'")->queryRow();
- $exam = $this->sConn->createCommand("SELECT e.exam_id,e.tpl_data,p.paper_id FROM `exam` e join paper p on e.exam_id=p.exam_id where e.exam_group_id='".$exam_group_id."'")->queryAll();
- if(!$exam){
- $result['msg']='考试ID不正确,请从考试列表点击上传成绩';
- exit(json_encode($result));
- }
- $paperIds=array();
- $examIds=array();
- foreach ($exam as $value){
- $paperIds[]=$value['paper_id'];
- $examIds[]=$value['exam_id'];
- }
- $tpl_data=json_decode($exam[0]['tpl_data'],true);
- $paper_topic_relation=$this->sConn->createCommand("select `paper_id`,`topic_id`,`order`,`score`,`type` from `paper_topic_relation` where paper_id='".$paperIds[0]."'")->queryAll();
- if(!$paper_topic_relation){
- $result['msg']='请关联答题卡';
- exit(json_encode($result));
- }
- $sortPaperTopic=array();
- //检测试题别名
- if(isset($tpl_data['new_items'])){
- foreach ($tpl_data['new_items'] as $item){
- if($examGroup['qxk_paper_id']>0){
- $alias[$item['id']]=$item['id'];
- }else{
- $alias[$item['id']]=$item['alias'];
- }
- }
- //重新排序
- foreach ($paper_topic_relation as $key =>$datum){
- $sortPaperTopic[$alias[$datum['order']]]=$datum;
- }
- ksort($sortPaperTopic);
- $sortPaperTopic=array_values($sortPaperTopic);
- }else{
- $sortPaperTopic=$paper_topic_relation;
- }
- $paper_topic_rs=array();
- $scores=array();
- $paperType=array();
- foreach ($sortPaperTopic as $key=>$value){
- $paper_topic_rs[$key]=$value['topic_id'];
- $scores[$key]=$value['score'];
- $paperType[$key]=$value['type'];
- }
- $sql='Replace INTO `student_paper_topic_rs` (`id`,`student_id`,`paper_id`,`topic_id`,`type`,`scoring`,`is_right`)VALUE ';
- $deleteSql=array();
- $updateSql=array();
- $error=array();
- $studentIds=array(); //用于检测重复
- $time=time();
- $uuidArr=array(); //批量uuid
- $needUuidCount=count($all_data)*count($paper_topic_relation);
- while ($needUuidCount>0){
- $getIds=array();
- if($needUuidCount>100000){
- $getIds=getBatchUuid($this->schoolId,100000);
- $needUuidCount-=100000;
- }else{
- $getIds=getBatchUuid($this->schoolId,$needUuidCount);
- $needUuidCount=0;
- }
- $uuidArr=array_merge($uuidArr,$getIds);
- }
- //debug($uuidArr);
- // $uuidArr=getBatchUuid($this->schoolId,$needUuidCount);
- foreach($all_data as $val){
- $StudentPaperRelation=$this->sConn->createCommand("select student_id,paper_id from `student_paper_relation` where student_id='".$val['student_id']."' and paper_id in(".implode(',',$paperIds).") and is_del=0")->queryRow();
- if(!$StudentPaperRelation){
- $error[]='学生没有参加本次考试 :'.$val['student_name'];
- continue;
- }
- $paper_id=$StudentPaperRelation['paper_id'];
- if($val['renew']==0){
- $isFound=$this->sConn->createCommand("select * from student_paper_topic_rs where student_id='".$val['student_id']."' and paper_id='".$paper_id."'")->queryRow();
- if($isFound){
- continue; //已有成绩,跳过
- }
- }
- $deleteSql[]="delete from `student_paper_topic_rs` where student_id='".$val['student_id']."' and paper_id='".$paper_id."' ";
- $topicScoreData=json_decode($val['score_data'],true);
- if($val['check_field']=='student_name'){
- $topicScoreData=array_slice($topicScoreData,1);
- }else{
- $topicScoreData=array_slice($topicScoreData,2);
- }
- $score_get=0;
- $lost_score=0;
- $topicScoreData=array_values($topicScoreData);
- $isHandle=0;
- foreach($topicScoreData as $key=> $ts){
- $ts=(float)$ts;
- if(!$ts){
- $ts=0;
- }
- $is_right=1;
- $bcR=bccomp($ts,$scores[$key],1);
- if($bcR==1 || $bcR==0){
- if(!$isHandle || $paperType[$key]!=17){
- $score=$scores[$key];
- }
- if($paperType[$key]==17){
- $isHandle=1;
- }
- }else{
- $score=$ts;
- $l=bcsub($scores[$key],$ts,1);
- if(!$isHandle || $paperType[$key]!=17){
- $lost_score=bcadd($lost_score,$l,1);
- }
- if($paperType[$key]==17 && $score){
- $isHandle=1;
- }
- $is_right=0;
- }
- $score_get=bcadd($score_get,$score,1);
- $topic_id= $paper_topic_rs[$key];
- $uuid=array_pop($uuidArr);
- $valueSql[]=' ('.$uuid.','.$val['student_id'].','.$paper_id.','.$topic_id.','.$paperType[$key].','.$score.','.$is_right.') ';
- }
- $updateSql_t=" update `student_paper_relation` set complete_count='".$tpl_data['totals']."',`scoring`='".$score_get."',`lost_score`='".$lost_score."',is_feedback=1,feedback_time='".$time."',is_complete=1,complete_time='".$time."'";
- $updateSql_t.=" where student_id='".$val['student_id']."' and paper_id='".$paper_id."' ";
- $updateSql[]=$updateSql_t;
- }
-
- if($deleteSql && $updateSql && $valueSql){
- $transaction = $this->sConn->beginTransaction();
- try{
- if($deleteSql){
- foreach ($deleteSql as $dquery){
- $this->sConn->createCommand($dquery)->execute();
- }
- if($updateSql){
- foreach ($updateSql as $uquery){
- $this->sConn->createCommand($uquery)->execute();
- }
- }
- if($valueSql){
- if(count($valueSql)>100){
- $valueSql = array_chunk($valueSql, 10);
- foreach($valueSql as $value){
- $chunkSql=$sql;
- $chunkSql.=implode(',',$value);
- $this->sConn->createCommand($chunkSql)->execute();
- }
- }else{
- $sql.=implode(',',$valueSql);
- $this->sConn->createCommand($sql)->execute();
- }
- }
- Exam::model()->updateAll(array('status'=>1,'upload_status'=>2,'complete_time'=>$time),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- ExamGroup::model()->updateAll(array('mark_status'=>2,'status'=>2,'upload_status'=>2,'import_score_type'=>3),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- //清理导入临时数据
- // $delSql="truncate table import_score_temp;";
- $delSql="delete from import_score_temp where exam_type=0;";
- $this->sConn->createCommand($delSql)->execute();
- $transaction->commit();
- $result['status']=1;
- if($error){
- // Yii::app()->jump->error('导入成功,有部分学生成绩没有导入:'.implode(',',$error));
- $result['msg']=implode('<br>',$error);
- }else{
- $result['msg']='导入成功';
- }
- 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" =>'',
- "date"=>date('Y-m-d H:i:s')
- )));
- }
- $conf = new RdKafka\Conf();
- $conf->set('metadata.broker.list', Yii::app()->params['kafka']);
- $producer = new RdKafka\Producer($conf);
- $topic = $producer->newTopic("xbkc-academic-offline-generate-report");
- $kafkaData=array(
- 'examGroupId'=>$exam_group_id,
- 'schoolId'=>$this->schoolId,
- 'generateTime'=>time()*1000
- );
- $topic->produce(RD_KAFKA_PARTITION_UA, 0, json_encode($kafkaData));
- $producer->poll(0);
- $producer->flush(10000);
- //发送学生端消息
- $sendJsonArr=array(
- 'school_id'=>$this->schoolId,
- 'send_type'=>'zsyas',
- 'update_type'=>0,
- 'exam_group_id'=>$exam_group_id,
- );
- sendStudentCacheQueue($sendJsonArr);
- exit(json_encode($result));
- }
- }catch (Exception $e) {
- //如果操作失败, 数据回滚
- $transaction->rollback();
- // Yii::app()->jump->error('成绩导入失败,请检查后重新');
- $result['msg']='成绩导入失败,请检查后重新导入';
- exit(json_encode($result));
- }
- }else{
- //没有需要重新导入的数据,清理导入临时数据
- //$delSql="truncate table import_score_temp;";
- $delSql="delete from import_score_temp where exam_type=0;";
- $this->sConn->createCommand($delSql)->execute();
- $result['status']=1;
- exit(json_encode($result));
- }
- }
- //处理重复学生
- public function actionHandle_repeat(){
- $page=Req::post('page');
- $name_like=Req::post('name');
- if(!$page) $page=1;
- $pageSize=10;
- $offset=($page-1)*$pageSize;
- $sql="select * from import_score_temp where exam_type=0 limit 1";
- $checkData=$this->sConn->createCommand($sql)->queryRow();
- $check_field=$checkData['check_field'];
- $sql="select count(*) as count,check_field_value,check_field from import_score_temp where is_repeat=1 and exam_type=0 group by check_field_value ";
- if($name_like){
- $sql.=" having check_field_value='".$name_like."'";
- }
- $sql.="order by count desc";
- $all_data=$this->sConn->createCommand($sql)->queryAll();
-
- if(!$all_data){
- $this->redirect(Yii::app()->createUrl('record/check_excel'));
- }
- $repeat=array();
- $total=count($all_data);
- $data['total_page']=ceil($total/$pageSize);
- $data['name_group']=array_slice($all_data,$offset,$pageSize);
- $data['page']=$page;
- if(Yii::app()->request->isAjaxRequest){
- $result['status']=1;
- $result['data']=$data['name_group'];
- $result['total_page']=$data['total_page'];
- exit(json_encode($result));
- }else{
- if($check_field=='student_name'){
- $this->render('handle', $data);
- }else{
- $fileName=array(
- 'student_name'=>'学生姓名',
- 'userno'=>'学号',
- 'student_card'=>'准考证号',
- 'school_student_card'=>'学校准考证号',
- 'zhixue_student_card'=>'智学网考证号',
- 'id_number'=>'身份证号',
- 'student_phone'=>'手机号'
- );
- //扩展字段
- $studentExtend=$this->schoolManager->getStudentExtend();
- if($studentExtend){
- foreach ($studentExtend as $key=> $value){
- $fileName[$key]=$value['field_mean'];
- }
- }
- $data['fieldName']=$fileName[$check_field];
- $data['check_field']=$check_field;
- $this->render('handle_card', $data);
- }
- }
- }
- //处理重复考号
- public function actionHandle_card(){
- $fileName=array(
- 'student_name'=>'学生姓名',
- 'userno'=>'学号',
- 'student_card'=>'准考证号',
- 'school_student_card'=>'学校准考证号',
- 'zhixue_student_card'=>'智学网考证号',
- 'id_number'=>'身份证号',
- 'student_phone'=>'手机号'
- );
- //扩展字段
- $studentExtend=$this->schoolManager->getStudentExtend();
- if($studentExtend){
- foreach ($studentExtend as $key=> $value){
- $fileName[$key]=$value['field_mean'];
- }
- }
- //查询不存在的数据
- $sql="select * from import_score_temp where is_repeat=1 and exam_type=0 ";
- $all_data=$this->sConn->createCommand($sql)->queryAll();
- $data['list']=$all_data;
- $data['fieldName']=$fileName;
- $this->render('handle_card',$data);
- }
- //处理不存在学生
- public function actionHandle_existent(){
- $fileName=array(
- 'student_name'=>'学生姓名',
- 'userno'=>'学号',
- 'student_card'=>'准考证号',
- 'school_student_card'=>'学校准考证号',
- 'zhixue_student_card'=>'智学网考证号',
- 'id_number'=>'身份证号',
- 'student_phone'=>'手机号'
- );
- //扩展字段
- $studentExtend=$this->schoolManager->getStudentExtend();
- if($studentExtend){
- foreach ($studentExtend as $key=> $value){
- $fileName[$key]=$value['field_mean'];
- }
- }
- //查询不存在的数据
- $sql="select * from import_score_temp where is_repeat=0 and (student_id is null or student_id =0) and exam_type=0 ";
- $all_data=$this->sConn->createCommand($sql)->queryAll();
- if($all_data){
- $data['check_field']=$all_data[0]['check_field'];
- }else{
- $data['check_field']='';
- }
- $data['list']=$all_data;
- $data['fieldName']=$fileName;
- $this->render('handle_existent',$data);
- }
- //根据名称加载重名学生
- public function actionShowrepeatstudent(){
- $name=Req::post('name');
- $fileName=array(
- 'student_name'=>'学生姓名',
- 'userno'=>'学号',
- 'student_card'=>'准考证号',
- 'school_student_card'=>'学校准考证号',
- 'zhixue_student_card'=>'智学网考证号',
- 'id_number'=>'身份证号',
- 'student_phone'=>'手机号'
- );
- //扩展字段
- $studentExtend=$this->schoolManager->getStudentExtend();
- if($studentExtend){
- foreach ($studentExtend as $key=> $value){
- $fileName[$key]=$value['field_mean'];
- }
- }
- $classIds=array();
- $sql="select * from import_score_temp where check_field_value='".$name."' and ( student_id is null or student_id =0) and exam_type=0";
- $nameArr=array();
- $systemStudent=array();
- $numberToId=array();
- $excel_data = $this->sConn->createCommand($sql)->queryAll();
- if($excel_data){
- $topic_score=json_decode($excel_data[0]['score_data'],true);
- $check_field=$excel_data[0]['check_field'];
- $excel_html='<table class="table table-striped table-bordered table-hover dataTable no-footer DTTT_selectable">';
- $excel_html.='<tr>';
- $excel_html.='<th>序号</th>';
- $excel_html.='<th>姓名</th>';
- $excel_html.='<th>班级</th>';
- if($check_field=='student_name'){
- $scoreArr=array_slice($topic_score,1);
- $excel_html.='<th>科目总分</th>';
- }else{
- $excel_html.='<th>'.$fileName[$check_field].'</th>';
- $excel_html.='<th>科目总分</th>';
- $scoreArr=array_slice($topic_score,2);
- }
- for($i=1;$i<=count($scoreArr);$i++){
- $excel_html.='<th>第'.$i.'题</th>';
- }
- $excel_html.='</tr>';
- $i=1;
- foreach($excel_data as $val){
- $topic_score=json_decode($val['score_data'],true);
- if($check_field=='student_name'){
- $scoreArr=array_slice($topic_score,1);
- $totalScore=$topic_score['C'];
- }else{
- $card_value=$val['check_field_value'];
- $totalScore=$topic_score['D'];
- $scoreArr=array_slice($topic_score,2);
- }
- $numberToId[$i]=$val['id'];
- $excel_html.='<tr>';
- $excel_html.='<td>'.$i.'</td>';
- if(isset($card_value)){
- $excel_html.='<td>'.$val['student_name'].'</td>';
- $excel_html.='<td>'.$val['class_name'].'</td>';
- $excel_html.='<td><input type="text" value="'.$val['check_field_value'].'" data="'.$val['check_field_value'].'" class="change_card" id="'.$val['id'].'"></td>';
- }else{
- $excel_html.='<td>'.$val['check_field_value'].'(原'.$val['student_name'].')</td>';
- $excel_html.='<td>'.$val['class_name'].'</td>';
- }
- $excel_html.='<td>'.$totalScore.'</td>';
- foreach($scoreArr as $v){
- $excel_html.='<td>'.$v.'</td>';
- }
- $excel_html.='</tr>';
- $i++;
- }
- $excel_html.='</table>';
- $exam_group_data = $this->sConn->createCommand("SELECT e.exam_id,e.tpl_data,p.paper_id FROM `exam` e join paper p on e.exam_id=p.exam_id where e.exam_group_id='".$excel_data[0]['exam_group_id']."'")->queryAll();
- $paperIds=array();
- if($exam_group_data){
- foreach ($exam_group_data as $v){
- $paperIds[]=$v['paper_id'];
- }
- }
- $_allStudent=array();
- if($check_field=='student_name'){
- $check_field='realname';
- $sys_sql="SELECT sc.realname,sc.id_number,sc.class_id,sc.student_id,sc.is_outer,sc.id_number,c.class_name,s.semester_id,s.semester_name,s.school_year,s.end_time,sc.field_1,sc.field_2,sc.field_3,sc.field_4,sc.field_5 FROM `student_info` sc ";
- $sys_sql.="LEFT JOIN class c on sc.class_id=c.class_id ";
- $sys_sql.="LEFT JOIN semester s on s.semester_id=c.semester_id ";
- $sys_sql.="LEFT JOIN student_paper_relation spr on sc.student_id = spr.student_id ";
- $sys_sql.=" where `".$check_field."` = '".$name."' and spr.paper_id in(".implode(',',$paperIds).") and s.semester_id <>'' ";
- $sys_sql.="order by end_time desc ;";
- $_allStudent = $this->sConn->createCommand($sys_sql)->queryAll();
- }elseif($check_field=='student_card'){
- $sql="select student_id,student_card from student where student_card ='".$name."' and status=0";
- $b_student=$this->conn->createCommand($sql)->queryRow();
- if($b_student){
- $sys_sql="SELECT sc.realname,sc.id_number,sc.class_id,sc.student_id,sc.is_outer,sc.id_number,c.class_name,s.semester_id,s.semester_name,s.school_year,s.end_time,sc.field_1,sc.field_2,sc.field_3,sc.field_4,sc.field_5 FROM `student_info` sc ";
- $sys_sql.="LEFT JOIN class c on sc.class_id=c.class_id ";
- $sys_sql.="LEFT JOIN semester s on s.semester_id=c.semester_id ";
- $sys_sql.="LEFT JOIN student_paper_relation spr on sc.student_id = spr.student_id ";
- $sys_sql.=" where sc.student_id = '".$b_student['student_id']."' and spr.paper_id in(".implode(',',$paperIds).") and s.semester_id <>'' ";
- $sys_sql.="order by end_time desc ;";
- $_allStudent = $this->sConn->createCommand($sys_sql)->queryAll();
- }
- }elseif($check_field=='school_student_card') {
- $sql = "select student_id,school_student_card from student where school_student_card ='" . $name . "'and status=0";
- $b_student = $this->conn->createCommand($sql)->queryRow();
- if ($b_student) {
- $sys_sql = "SELECT sc.realname,sc.id_number,sc.class_id,sc.student_id,sc.is_outer,sc.id_number,c.class_name,s.semester_id,s.semester_name,s.school_year,s.end_time,sc.field_1,sc.field_2,sc.field_3,sc.field_4,sc.field_5 FROM `student_info` sc ";
- $sys_sql .= "LEFT JOIN class c on sc.class_id=c.class_id ";
- $sys_sql .= "LEFT JOIN semester s on s.semester_id=c.semester_id ";
- $sys_sql .= "LEFT JOIN student_paper_relation spr on sc.student_id = spr.student_id ";
- $sys_sql .= " where sc.student_id = '" . $b_student['student_id'] . "' and spr.paper_id in(" . implode(',', $paperIds) . ") and s.semester_id <>'' ";
- $sys_sql .= "order by end_time desc ;";
- $_allStudent = $this->sConn->createCommand($sys_sql)->queryAll();
- }
- }elseif($check_field=='zhixue_student_card'){
- $sql = "select student_id,zhixue_student_card from student where zhixue_student_card ='" . $name . "'and status=0";
- $b_student = $this->conn->createCommand($sql)->queryRow();
- if ($b_student) {
- $sys_sql = "SELECT sc.realname,sc.id_number,sc.class_id,sc.student_id,sc.is_outer,sc.id_number,c.class_name,s.semester_id,s.semester_name,s.school_year,s.end_time,sc.field_1,sc.field_2,sc.field_3,sc.field_4,sc.field_5 FROM `student_info` sc ";
- $sys_sql .= "LEFT JOIN class c on sc.class_id=c.class_id ";
- $sys_sql .= "LEFT JOIN semester s on s.semester_id=c.semester_id ";
- $sys_sql .= "LEFT JOIN student_paper_relation spr on sc.student_id = spr.student_id ";
- $sys_sql .= " where sc.student_id = '" . $b_student['student_id'] . "' and spr.paper_id in(" . implode(',', $paperIds) . ") and s.semester_id <>'' ";
- $sys_sql .= "order by end_time desc ;";
- $_allStudent = $this->sConn->createCommand($sys_sql)->queryAll();
- }
- }else{
- $sys_sql="SELECT sc.realname,sc.id_number,sc.class_id,sc.student_id,sc.is_outer,sc.id_number,c.class_name,s.semester_id,s.semester_name,s.school_year,s.end_time,sc.field_1,sc.field_2,sc.field_3,sc.field_4,sc.field_5 FROM `student_info` sc ";
- $sys_sql.="LEFT JOIN class c on sc.class_id=c.class_id ";
- $sys_sql.="LEFT JOIN semester s on s.semester_id=c.semester_id ";
- $sys_sql.="LEFT JOIN student_paper_relation spr on sc.student_id = spr.student_id ";
- $sys_sql.=" where `".$check_field."` = '".$name."' and spr.paper_id in(".implode(',',$paperIds).") and s.semester_id <>'' ";
- $sys_sql.="order by end_time desc ;";
- $_allStudent = $this->sConn->createCommand($sys_sql)->queryAll();
- }
- $nameArr=array();
- $studentData=array();
- $businessData=array();
- $semester=array();
- $studentId=array();
- $html='';
- if($_allStudent){
- foreach ($_allStudent as $val){
- $val['serial_number']=0;
- $val['userno']=0;
- //班级信息
- $sql_class_relation="select * from student_class_relation where student_id='".$val['student_id']."' and status=0 ";
- $student_class_realtion=$this->sConn->createCommand($sql_class_relation)->queryRow();
- if($student_class_realtion){
- $val['serial_number']=$student_class_realtion['serial_number'];
- $val['userno']=$student_class_realtion['userno'];
- }else{
- continue;
- }
- //查询副号
- $sql_fuhao="select * from student_relation where find_in_set('".$val['student_id']."',relation_student_id)";
- $student_fuhao=$this->sConn->createCommand($sql_fuhao)->queryRow();
- $val['fuhao']=0;
- if($student_fuhao){
- if($val['student_id']!=$student_fuhao['master_student_id']){
- continue;
- }else{
- $fuhao_arr=explode(',',$student_fuhao['relation_student_id']);
- $val['fuhao']=count($fuhao_arr)-1;
- }
- }
- $studentData[$val['semester_id']][]=$val;
- $semester[$val['semester_id']]=$val['semester_name'];
- $studentId[]=$val['student_id'];
- }
- //查询business
- $criteria = new CDbCriteria();
- $b_student = array();
- $criteria->addInCondition('student_id',$studentId);
- $b_student_data = BusinessStudent::model()->findAll($criteria);
- if($b_student_data){
- foreach($b_student_data as $v)
- {
- $businessData[$v->student_id]=array(
- 'username'=>$v->username,
- 'student_card'=>$v->student_card,
- 'school_student_card'=>$v->school_student_card,
- 'zhixue_student_card'=>$v->zhixue_student_card,
- );
- }
- }
- $i=1;
- $currSemester = $this->schoolManager->getCurrSemester();
- $smid=$currSemester['semester_id'];
- foreach ($semester as $key=> $val){
- $semesterStatus='非当前学期';
- if($smid==$key){
- $semesterStatus='当前学期';
- }
- $html.='<div class="handel-term-list">';
- $html.='<div class="term-name fw"></div>';
- $html.='<div class="relative flex">';
- $html.='<img src="/images/prev-arrow.png" alt="" class="prev-arrow arrow-img pointer">';
- $html.='<div class="term-card-layout flex-one" >';
- $html.='<ul class="term-card-detail">';
- if(isset($studentData[$key])){
- // debug($studentData[$key]);
- foreach ($studentData[$key] as $item){
- $isZj='是';
- if($item['is_outer']==1){
- $isZj='否';
- }
- $html.='<li class="term-card-list" id="'.$item['student_id'].'" draggable="true" >';
- $html.='<div class="padding-layout">';
- $html.='<div class="card-lis-data flex">';
- $html.='<div class="card_select">';
- $html.='<select class="nToId"><option value="0">请选择序号</option>';
- foreach ($numberToId as $number=>$Id){
- $html.='<option value="'.$Id.'">'.$number.'</option>';
- }
- $html.='</select>';
- $html.='</div>';
- $html.='</div>';
- $html.='<div class="card-lis-data flex">';
- $html.='<span class="card-list-menu gray-font">姓名</span>';
- $html.='<span class="card-list-msg flex-one">'.$item['realname'].'</span>';
- $html.='</div>';
- $html.='<div class="card-lis-data flex">';
- $html.='<span class="card-list-menu gray-font">班级</span>';
- $html.='<span class="card-list-msg flex-one">'.$item['class_name'].'</span>';
- $html.='</div>';
- $html.='<div class="hide-list">';
- $html.='<div class="card-lis-data flex">';
- $html.='<span class="card-list-menu gray-font">学期</span>';
- $html.='<span class="card-list-msg flex-one">'.$val.'</span>';
- $html.='</div>';
- $html.='<div class="card-lis-data flex">';
- $html.='<span class="card-list-menu gray-font">学期状态</span>';
- $html.='<span class="card-list-msg flex-one">'.$semesterStatus.'</span>';
- $html.='</div>';
- $html.='<div class="card-lis-data flex">';
- $html.='<span class="card-list-menu gray-font">班级序号</span>';
- $html.='<span class="card-list-msg flex-one">'.$item['serial_number'].'</span>';
- $html.='</div>';
- $html.='<div class="card-lis-data flex">';
- $html.='<span class="card-list-menu gray-font">学号</span>';
- $html.='<span class="card-list-msg flex-one">'.$item['userno'].'</span>';
- $html.='</div>';
- $html.='<div class="card-lis-data flex">';
- $html.='<span class="card-list-menu gray-font">登录账号</span>';
- if(isset($businessData[$item['student_id']])){
- $html.='<span class="card-list-msg flex-one">'.$businessData[$item['student_id']]['username'].'</span>';
- }else{
- $html.='<span class="card-list-msg flex-one"></span>';
- }
- $html.='</div>';
- $html.='<div class="card-lis-data flex">';
- $html.='<span class="card-list-menu gray-font">系统准考证号</span>';
- if(isset($businessData[$item['student_id']])){
- $html.='<span class="card-list-msg flex-one">'.$businessData[$item['student_id']]['student_card'].'</span>';
- }else{
- $html.='<span class="card-list-msg flex-one"></span>';
- }
- $html.='</div>';
- $html.='<div class="card-lis-data flex">';
- $html.='<span class="card-list-menu gray-font">学校准考证号</span>';
- if(isset($businessData[$item['student_id']])){
- $html.='<span class="card-list-msg flex-one">'.$businessData[$item['student_id']]['school_student_card'].'</span>';
- }else{
- $html.='<span class="card-list-msg flex-one"></span>';
- }
- $html.='</div>';
- $html.='<div class="card-lis-data flex">';
- $html.='<span class="card-list-menu gray-font">智学网考号</span>';
- if(isset($businessData[$item['student_id']])){
- $html.='<span class="card-list-msg flex-one">'.$businessData[$item['student_id']]['zhixue_student_card'].'</span>';
- }else{
- $html.='<span class="card-list-msg flex-one"></span>';
- }
- $html.='</div>';
- $html.='<div class="card-lis-data flex">';
- $html.='<span class="card-list-menu gray-font">身份证号</span>';
- $html.='<span class="card-list-msg flex-one">'.$item['id_number'].'</span>';
- $html.='</div>';
- $html.='<div class="card-lis-data flex">';
- $html.='<span class="card-list-menu gray-font">是否为在籍生</span>';
- $html.='<span class="card-list-msg flex-one">'.$isZj.'</span>';
- $html.='</div>';
- $html.='<div class="card-lis-data flex">';
- $html.='<span class="card-list-menu gray-font">历史考试成绩</span>';
- $html.='<span rel="'.$item['student_id'].'" class="card-list-msg flex-one browse-history green-font">查看</span>';
- $html.='</div>';
- $html.='<div class="card-lis-data flex">';
- $html.='<span class="card-list-menu gray-font">副号</span>';
- $html.='<span rel="'.$item['student_id'].'" class="card-list-msg flex-one green-font pointer fuhao-lock">'.$item['fuhao'].'</span>';
- $html.='</div>';
- $html.='</div>';
- $html.='<span class="toggle-opt-btn green-font pointer">展开</span>';
- $html.='</div>';
- $html.='</li>';
- $i++;
- }
- }
- $html.='</ul>';
- $html.='</div>';
- $html.='<img src="/images/next-arrow.png" alt="" class="next-arrow arrow-img pointer">';
- $html.='</div>';
- $html.='</div>';
- }
- }
- }
- $result['html']=$html;
- $result['excel_html']=$excel_html;
- $result['status']=1;
- exit(json_encode($result));
- }
- //绑定学生id
- public function actionBinding(){
- $str=Req::post('str');
- $result['status']=0;
- if(!$str || !is_array($str)){
- exit(json_encode($result));
- }
- $studentIds=array();
- $tempIds=array();
- foreach($str as $val){
- @$nToId=explode('///',$val);
- if(isset($nToId[0])){
- if(in_array((string)$nToId[0],$studentIds,true)){
- $result['msg']='不能学生重复选择';
- exit(json_encode($result));
- }else{
- $studentIds[]=(string)$nToId[0];
- }
- }
- if(isset($nToId[1])){
- if(in_array((string)$nToId[1],$tempIds,true)){
- $result['msg']='不能学生重复选择';
- exit(json_encode($result));
- }else{
- $tempIds[]=(string)$nToId[1];
- }
- }
- }
- $updateSql=array();
- foreach($str as $val){
- @$nToId=explode('///',$val);
- if(isset($nToId[0]) && isset($nToId[1])){
- //判断学生id是否已关联过
- $related=$this->sConn->createCommand("select id from import_score_temp where student_id='".$nToId[0]."' and exam_type=0 limit 1")->queryRow();
- if($related){
- $result['msg']='学生已经被关联,请重新检查';
- exit(json_encode($result));
- }
- $updateSql[]="update import_score_temp set student_id='".$nToId[0]."',is_repeat=0 where id='".$nToId[1]."' and exam_type=0";
- }
- }
- if($updateSql){
- foreach($updateSql as $query){
- $this->sConn->createCommand($query)->execute();
- }
- $result['status']=1;
- }
- exit(json_encode($result));
- }
- //修改不存在的学生数据
- public function actionChange_value(){
- $id=Req::post('id');
- $value=Req::post('value');
- $result['status']=0;
- if(!$id || !$value){
- $result['msg']='参数不正确';
- exit(json_encode($result));
- }
- $sql="select student_name,class_name,check_field_value,score_data,exam_group_id,check_field,renew,student_id,is_repeat from import_score_temp where id='".$id."' limit 1";
- $data=$this->sConn->createCommand($sql)->queryRow();
- if(!$data){
- $result['msg']='id不正确';
- exit(json_encode($result));
- }
- $check_field=$data['check_field'];
- //excel中是否有重复数据
- $excelCheck="select id from import_score_temp where check_field_value='".$value."' and exam_type=0 ";
- $excelCheckData=$this->sConn->createCommand($excelCheck)->queryRow();
- if($excelCheckData){
- $result['msg']='excel中已存在相同记录';
- if($check_field=='student_name'){
- $result['status']=1;
- $updateSql="update import_score_temp set `is_repeat`=1,check_field_value='{$value}' where (id={$id} or check_field_value='{$value}') and exam_type=0";
- $this->sConn->createCommand($updateSql)->execute();
- $result['msg']='excel中已存在相同记录,请返回检测页面,继续处理重名';
- }
- exit(json_encode($result));
- }
- //系统中是否有数据
- $exam_group_id=$data['exam_group_id'];
- $exam_group_data = $this->sConn->createCommand("SELECT e.exam_id,e.tpl_data,p.paper_id,e.class_id FROM `exam` e join paper p on e.exam_id=p.exam_id where e.exam_group_id='".$exam_group_id."'")->queryAll();
- if(!$exam_group_data){
- $result['status']=0; //还有重复数据,需要继续处理
- exit(json_encode($result));
- }
- $paperIds=array();
- $examIds=array();
- $classIds=array();
- foreach ($exam_group_data as $val){
- $paperIds[]=$val['paper_id'];
- $examIds[]=$val['exam_id'];
- $classIds[]=$val['class_id'];
- }
- if($exam_group_data){
- $student_info=array();
- switch ($check_field){
- case 'student_name':
- $sql="select si.student_id,si.realname from student_info si join student_paper_relation spr on si.student_id = spr.student_id where realname ='".$value."' and paper_id in(".implode(',',$paperIds).")";
- $student_info=$this->sConn->createCommand($sql)->queryAll();
- break;
- case 'userno':
- $sql="select userno,spr.student_id from student_info si ";
- $sql.="join student_class_relation scr on scr.student_id=si.student_id ";
- $sql.="join student_paper_relation spr on si.student_id = spr.student_id ";
- $sql.=" where sscr.userno ='".$value."' and scr.status=0 and scr.class_id in(".implode(',',$classIds).") and spr.paper_id in(".implode(',',$paperIds).")";
- $student_info=$this->sConn->createCommand($sql)->queryAll();
- break;
- case 'student_card':
- $sql="select student_id,student_card from student where student_card ='".$value."' and status=0";
- $b_student=$this->conn->createCommand($sql)->queryAll();
- break;
- case 'school_student_card':
- $sql="select student_id,school_student_card from student where school_student_card='".$value."' and status=0";
- $b_student=$this->conn->createCommand($sql)->queryAll();
- break;
- case 'zhixue_student_card':
- $sql="select student_id,zhixue_student_card from student where zhixue_student_card='".$value."' and status=0";
- $b_student=$this->conn->createCommand($sql)->queryAll();
- break;
- default:
- $sql="select * from student_info si join student_paper_relation spr on si.student_id = spr.student_id where `".$check_field."` ='".$value."' and paper_id in(".implode(',',$paperIds).") ";
- $student_info=$this->sConn->createCommand($sql)->queryAll();
- }
- if(isset($b_student) && $b_student){
- $studentIds=array();
- foreach ($b_student as $item){
- $studentIds[]=$item['student_id'];
- }
- $sql="select si.student_id,si.realname from student_info si join student_paper_relation spr on si.student_id = spr.student_id where si.student_id in(".implode(',',$studentIds).") and paper_id in(".implode(',',$paperIds).")";
- $student_info=$this->sConn->createCommand($sql)->queryAll();
- }
- if(!$student_info){
- $result['msg']='系统中不存在,或学生没有参加该次考试';
- exit(json_encode($result));
- }elseif(count($student_info)>1){
- $updateSql="update import_score_temp set `is_repeat`=1,check_field_value='{$value}' where id={$id}";
- $this->sConn->createCommand($updateSql)->execute();
- $result['msg']='系统中存在多个该学生数据,请返回检测页面,继续处理重名';
- exit(json_encode($result));
- }else{
- $result['status']=1;
- $studentId=$student_info[0]['student_id'];
- //查询是否参加考试
- $StudentPaperRelation=$this->sConn->createCommand("select student_id,paper_id from `student_paper_relation` where student_id='".$studentId."' and paper_id in(".implode(',',$paperIds).")")->queryRow();
- if(!$StudentPaperRelation){
- $result['status']=1;
- $result['msg']='学生没有参加本次考试';
- exit(json_encode($result));
- }
- //判断学生id是否已关联过
- $related=$this->sConn->createCommand("select id from import_score_temp where student_id='".$studentId."' and exam_type=0 limit 1")->queryRow();
- if($related){
- $result['msg']='学生已经被关联,请重新检查';
- exit(json_encode($result));
- }
- $updateSql="update import_score_temp set student_id='{$studentId}',check_field_value='{$value}',is_repeat=0 where id={$id}";
- $this->sConn->createCommand($updateSql)->execute();
- exit(json_encode($result));
- }
- }else{
- $result['msg']='考试数据有误';
- exit(json_encode($result));
- }
- }
- //修改后确认
- public function actionChange_check(){
- $check_value=Req::post('check_value');
- $result['status']=0;
- if(!$check_value){
- exit(json_encode($result));
- }
- $sql="select id,student_name,class_name,check_field_value,score_data,exam_group_id,check_field,renew,student_id,is_repeat from import_score_temp where check_field_value='".$check_value."' and is_repeat=1 and exam_type=0";
- $student_info=$this->sConn->createCommand($sql)->queryAll();
- if(!$student_info){
- $result['status']=1; //没有数据,处理完毕
- exit(json_encode($result));
- }elseif(count($student_info)>1){
- $result['status']=0; //还有重复数据,需要继续处理
- exit(json_encode($result));
- }else{
- //只剩一条,查询
- $data=$student_info[0];
- $check_field=$data['check_field'];
- $id=$data['id'];
- //系统中是否有数据
- $exam_group_id=$data['exam_group_id'];
- $exam_group_data = $this->sConn->createCommand("SELECT e.exam_id,e.tpl_data,p.paper_id,e.class_id FROM `exam` e join paper p on e.exam_id=p.exam_id where e.exam_group_id='".$exam_group_id."'")->queryAll();
- if(!$exam_group_data){
- $result['status']=0; //还有重复数据,需要继续处理
- exit(json_encode($result));
- }
- $paperIds=array();
- $examIds=array();
- $classIds=array();
- foreach ($exam_group_data as $value){
- $paperIds[]=$value['paper_id'];
- $examIds[]=$value['exam_id'];
- $classIds[]=$value['class_id'];
- }
- if($exam_group_data){
- $student_info=array();
- switch ($check_field){
- case 'student_name':
- $sql="select student_id,realname from student_info where realname ='".$check_value."' and class_id in(".implode(',',$classIds).")";
- $student_info=$this->sConn->createCommand($sql)->queryAll();
- break;
- case 'userno':
- $sql="select userno,student_id from student_info si ";
- $sql.="join student_class_relation scr on scr.student_id=si.student_id ";
- $sql.=" where scr.userno ='".$check_value."' and scr.status=0 and scr.class_id in(".implode(',',$classIds).")";
- $student_info=$this->sConn->createCommand($sql)->queryAll();
- break;
- case 'student_card':
- $sql="select student_id,student_card from student where student_card ='".$check_value."' and status=0";
- $b_student=$this->conn->createCommand($sql)->queryAll();
- break;
- case 'school_student_card':
- $sql="select student_id,school_student_card from student where school_student_card='".$check_value."' and status=0";
- $b_student=$this->conn->createCommand($sql)->queryAll();
- break;
- case 'zhixue_student_card':
- $sql="select student_id,zhixue_student_card from student where zhixue_student_card ='".$check_value."' and status=0";
- $b_student=$this->conn->createCommand($sql)->queryAll();
- break;
- default:
- $sql="select * from student_info where `".$check_field."` ='".$check_value."' and class_id in(".implode(',',$classIds).")";
- $student_info=$this->sConn->createCommand($sql)->queryAll();
- }
- if(isset($b_student) && $b_student){
- $studentIds=array();
- foreach ($b_student as $item){
- $studentIds[]=$item['student_id'];
- }
- $sql="select student_id from student_info where student_id in(".implode(',',$studentIds).") and class_id in(".implode(',',$classIds).")";
- $student_info=$this->sConn->createCommand($sql)->queryAll();
- }
- if(!$student_info){
- $updateSql="update import_score_temp set is_repeat=0,student_id='' where id={$id}";
- $this->sConn->createCommand($updateSql)->execute();
- $result['msg']='还有系统中不存在,或没有参加本次考试的数据,需要继续处理';
- $result['status']=0;
- exit(json_encode($result));
- }elseif(count($student_info)>1){
- $result['msg']='系统中存在多个该学生数据,请检查后重新填写';
- $result['status']=0;
- exit(json_encode($result));
- }else{
- $result['status']=1;
- $studentId=$student_info[0]['student_id'];
- //查询是否参加考试
- $StudentPaperRelation=$this->sConn->createCommand("select student_id,paper_id from `student_paper_relation` where student_id='".$studentId."' and paper_id in(".implode(',',$paperIds).")")->queryRow();
- if(!$StudentPaperRelation){
- $result['status']=1;
- $result['msg']='学生没有参加本次考试';
- exit(json_encode($result));
- }
- //判断学生id是否已关联过
- $related=$this->sConn->createCommand("select id from import_score_temp where student_id='".$studentId."' limit 1")->queryRow();
- if($related){
- $result['status']=0;
- $result['msg']='需要继续处理';
- exit(json_encode($result));
- }else{
- $updateSql="update import_score_temp set student_id='{$studentId}',is_repeat=0 where id={$id}";
- $this->sConn->createCommand($updateSql)->execute();
- exit(json_encode($result));
- }
- }
- }else{
- $result['msg']='考试数据有误';
- exit(json_encode($result));
- }
- }
- }
- /*导入学生答题图片*/
- //导入图片,导入表格
- public function actionImportStudentExcel(){
- ini_set ('memory_limit', '300M');
- if(!$_FILES){
- Yii::app()->jump->error('文件大小超过范围');
- }else{
- if(!isset($_FILES['exname']) || !isset($_FILES['exname']['size']) || $_FILES['exname']['size'] > 5242880){
- Yii::app()->jump->error('文件大小超过范围');
- }
- }
- if (Yii::app()->request->getIsPostRequest()) {
- $exam_group_id=Req::post('exam_group_id');
- $check_field=Req::post('check_field');
- $exam_renew=Req::post('exam_renew');
- if(!$exam_group_id)
- {
- Yii::app()->jump->error('请选择考试信息');
- }
- $uploader = new Uploader("upload/tmpDir/zhixue_chengji/{$this->schoolId}/");
- $uploader->allowTypes = array("xls","xlsx");
- $uploader->fieldsMappings = array("exnameYwy" => array(0 => $this->schoolId . date('Ymdhis', time())));
- $file = $uploader->act();
- $file = Arr::current(Arr::current($file));
- if (!$file || !isset($file["error"]))
- Yii::app()->jump->error('请上传的Excel!');
- if ($file["error"] != 0) {
- switch ($file["error"]) {
- case 2001:
- Yii::app()->jump->error('文件类型不符');
- break;
- case 2002:
- Yii::app()->jump->error('文件大小超出允许范围');
- break;
- default:
- Yii::app()->jump->error('上传失败');
- break;
- }
- }
- $inputFileName = $file["src"];
- // 导入PHPExcel类
- Yii::import('application.extensions.*');
- require_once('phpexcel/PHPExcel/IOFactory.php');
- try{
- $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
- $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
- // FIXME 20191202
- @unlink($file["src"]);
- }catch (Exception $e){
- // FIXME 20191202
- @unlink($file["src"]);
- Yii::app()->jump->error('Excel格式不正确:'.$e->getMessage());
- }
- if(!$sheetData)
- {
- Yii::app()->jump->error('请正确的Excel!');
- }
- unset($objPHPExcel);
- unset($sheetData[1]);
- if(!$sheetData)
- {
- Yii::app()->jump->error('请输入学生图片数据');
- }
- $insertSql="insert into import_score_temp(`student_name`,`class_name`,`check_field_value`,`score_data`,`exam_group_id`,`check_field`,`renew`,`exam_type`) values";
- $valuesArray=array();
- foreach ($sheetData as $val){
- if(!isset($val['A']) || !isset($val['B']) || !isset($val['C']) ){
- continue;
- }
- $student_topic=array_slice($val,2);
- $regex = '/^[a-zA-Z0-9]+$/u';
- if($check_field=='student_name'){
- //$student_topic=array_slice($val,2);
- }else{
- $check_field_value=$val['C'];
- if(!preg_match($regex, $check_field_value)){
- Yii::app()->jump->error('识别考号内容只能是数字和字母');
- }
- }
- if($check_field=='student_name'){
- $valuesArray[]="('".$val['A']."','".$val['B']."','','".json_encode($student_topic)."','".$exam_group_id."','".$check_field."','".$exam_renew."',2)";
- }else{
- $valuesArray[]="('".$val['A']."','".$val['B']."','".$val['C']."','".json_encode($student_topic)."','".$exam_group_id."','".$check_field."','".$exam_renew."',2)";
- }
- }
- if($valuesArray){
- // $delSql="truncate table import_score_temp;";
- $delSql="delete from import_score_temp;";
- $this->sConn->createCommand($delSql)->execute();
- $insertSql.=implode(',',$valuesArray);
- $this->sConn->createCommand($insertSql)->execute();
- $this->redirect(Yii::app()->createUrl('record/checkImgExcel'));
- }else{
- Yii::app()->jump->error('没有发现学生图片数据');
- }
- Yii::app()->jump->error('导入失败');
- }
- }
- //导入图片检测页
- public function actionCheckImgExcel(){
- $sql="select * from import_score_temp where exam_type=2 limit 1";
- $data=$this->sConn->createCommand($sql)->queryRow();
- $fileName=array(
- 'student_name'=>'学生姓名',
- 'userno'=>'学号',
- 'student_card'=>'准考证号',
- 'school_student_card'=>'学校准考证号',
- 'zhixue_student_card'=>'智学网考证号',
- 'id_number'=>'身份证号',
- 'student_phone'=>'手机号'
- );
- //扩展字段
- $studentExtend=$this->schoolManager->getStudentExtend();
- if($studentExtend){
- foreach ($studentExtend as $key=> $value){
- $fileName[$key]=$value['field_mean'];
- }
- }
- if(isset($fileName[$data['check_field']])){
- $data['check_field_name']=$fileName[$data['check_field']];
- }else{
- $data['check_field_name']='学生姓名';
- }
- $data['need_check_name']=0;
- if($data['check_field_name']=='学生姓名'){
- $data['need_check_name']=1;
- }
- $this->render('check_img',$data);
- }
- //检测导入图片数据格式
- public function actionCheck_img_field_first(){
- $result['status']=0;
- $sql="select * from import_score_temp where exam_type=2";
- $All_Data=$this->sConn->createCommand($sql)->queryAll();
- if(!$All_Data){
- exit(json_encode($result));
- }
- $data=$All_Data[0];
- $check_field=$data['check_field'];
- $score_data=json_decode($data['score_data'],true);
- $exam_group_id=$data['exam_group_id'];
- if(!$score_data){
- $result['msg']='数据不完整';
- exit(json_encode($result));
- }
- //检测题量
- $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- if($exam_group_data) {
- foreach ($exam_group_data as $v) {
- $exam_id = $v->exam_id;
- $tpl_data = json_decode($v->tpl_data, 1);
- }
- unset($exam_group_data);
- $paper_data = SPaper::model()->find('exam_id=:exam_id', array(':exam_id' => $exam_id));
- $paper_topic_data = SPaperTopicRelation::model()->findAll(array('order'=>'`no` asc','condition'=>'paper_id=:paper_id','params'=>array(':paper_id'=>$paper_data->paper_id)));
- if(!$paper_topic_data){
- $result['msg']='请先关联答题卡再上传成绩';
- exit(json_encode($result));
- }
- //判断是否上传成绩
- //检测试题数据
- foreach($All_Data as $key=> $val){
- $score_data=json_decode($val['score_data'],true);
- $score_data=array_slice($score_data,1);
-
- if(count($score_data)!=count($paper_topic_data)){
- $result['msg']='上传题量和试卷题量不一致:'.$val['student_name'];
- exit(json_encode($result));
- }
- $topic_score=array_values($score_data);
- foreach($topic_score as $order => $v){
- if(!isset($paper_topic_data[$order])){
- $result['msg']='上传题量和试卷题量不一致';
- exit(json_encode($result));
- }
- }
- }
- $result['msg']='检测完成';
- $result['status']=1;
- }else{
- $result['msg']='未发现对应考试';
- exit(json_encode($result));
- }
- exit(json_encode($result));
- }
- //检测导入图片姓名
- public function actionCheck_img_student_name(){
- ini_set('memory_limit','512M');
- set_time_limit(0);
- $result['status']=0;
- $result['data']=0;
- $student_all_data = $this->sConn->createCommand("SELECT id,student_name FROM `import_score_temp` `t` where exam_type=2")->queryAll();
- if($student_all_data){
- //去除非中文字符
- $updateArr=array();
- $preg="/[^\x{4E00}-\x{9FFF}^·]+/u";
- $count=0;
- foreach($student_all_data as $val){
- if(preg_match($preg,$val['student_name'])){
- $ModifyName = preg_replace($preg, "", $val['student_name']);
- if($ModifyName){
- $updateArr[$val['id']]=$ModifyName;
- $count++;
- }
- }else{
- $updateArr[$val['id']]=$val['student_name'];
- }
- }
- //组织更新语句
- if($updateArr){
- $arrNumber=ceil(count($updateArr)/500);
- $Arr=array_chunk($updateArr,$arrNumber,true);
- $transcation = $this->sConn->beginTransaction();
- try {
- foreach ($Arr as $item){
- $sql='update import_score_temp set `check_field_value`= case id ';
- foreach ($item as $key=> $val){
- $sql.=" WHEN ".$key." THEN '".$val."' ";
- }
- $sql.=" End ";
- $sql.=" where check_field_value='' or check_field_value is null and exam_type=0";
- $this->sConn->createCommand($sql)->execute();
- }
- $transcation->commit();
- $result['status']=1;
- }catch (Exception $e){
- $transcation->rollback();
- }
- }
- $result['count']=$count;
- }
- exit(json_encode($result));
- }
- //匹配信息
- public function actionMatchingImg(){
- $noExistent=0; //不存在
- $repeat=0; //重复(组)
- $success=0; //匹配成功
- $scoreWrong=0; //成绩不正确
- $result['status']=0;
- $sql="select * from import_score_temp where exam_type=2 limit 1";
- $data=$this->sConn->createCommand($sql)->queryRow();
- if(!$data){
- exit(json_encode($result));
- }
- $check_field=$data['check_field'];
- $exam_group_id=$data['exam_group_id'];
- $classArr=array();
- $classIds=array();
- $check_data_group=array(); //检查字段对应临时表id
- $update_temp_data=array(); //更新临时表数据
- $student_card=array(); //学生id,准考证号对应数据
- $tpl_data=array();
- $updateSql=array();
- $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- $exam_group_data = $this->sConn->createCommand("SELECT e.exam_id,e.tpl_data,p.paper_id,e.class_id FROM `exam` e join paper p on e.exam_id=p.exam_id where e.exam_group_id='".$exam_group_id."'")->queryAll();
- $paperIds=array();
- if($exam_group_data){
- foreach ($exam_group_data as $v){
- if(!$tpl_data && isset($v['tpl_data'])){
- $tpl_data=json_decode($v['tpl_data'],true);
- }
- $classIds[]=$v['class_id'];
- $paperIds[]=$v['paper_id'];
- }
- }
- //统计已经匹配成功的数据
- $success_student_data = $this->sConn->createCommand("SELECT id,student_name,check_field,exam_group_id,score_data,check_field_value FROM `import_score_temp` `t` where student_id is not null and student_id<>0 and exam_type=0 ")->queryAll();
- if($success_student_data){
- $success=count($success_student_data);
- }
- $check_field_val_arr=array();
- $student_all_data = $this->sConn->createCommand("SELECT id,student_name,check_field,exam_group_id,score_data,check_field_value FROM `import_score_temp` `t` where student_id is null or student_id=0 and exam_type=0 ")->queryAll();
- if(!$student_all_data){
- $result['repeat']=0;
- $result['success']=$success;
- $result['noExistent']=0;
- $result['status']=1;
- exit(json_encode($result));
- }
- foreach ($student_all_data as $val){
- //验证学生分数
- $check_field_val_arr[]="'".$val['check_field_value']."'";
- $check_data_group[$val['check_field_value']]=$val['id'];
- }
- //处理重复数据
- $repeat_group_data=array();
- $search_value_arr=array();
- foreach ($check_field_val_arr as $value){
- $repeat_group_data[$value][]=$value;
- }
- foreach ($repeat_group_data as $key=>$val){
- if(count($val)>1){
- $repeat++;
- $modify_name=str_replace("'",'',$key);
- $updateSql[]="update import_score_temp set is_repeat=1 where check_field_value='".$modify_name."' and (student_id is null or student_id=0) and exam_type=2";
- }else{
- $search_value_arr[]=$val[0];
- }
- }
- if($search_value_arr){
- $student_info=array();
- $b_student=array();
- switch ($check_field){
- case 'student_name':
- $sql="select si.student_id,si.realname from student_info si join student_paper_relation spr on si.student_id = spr.student_id where realname in(".implode(',',$search_value_arr).") and paper_id in(".implode(',',$paperIds).")";
- $student_info=$this->sConn->createCommand($sql)->queryAll();
- break;
- case 'userno':
- $sql="select userno,spr.student_id from student_info si ";
- $sql.="join student_class_relation scr on scr.student_id=si.student_id ";
- $sql.="join student_paper_relation spr on si.student_id = spr.student_id ";
- $sql.=" where scr.userno in(".implode(',',$search_value_arr).") and scr.status=0 and scr.class_id in(".implode(',',$classIds).") and spr.paper_id in(".implode(',',$paperIds).")";
- $student_info=$this->sConn->createCommand($sql)->queryAll();
- break;
- case 'student_card':
- $sql="select student_id,student_card from student where student_card in(".implode(',',$search_value_arr).") and status=0";
- $b_student=$this->conn->createCommand($sql)->queryAll();
- break;
- case 'school_student_card':
- $sql="select student_id,school_student_card from student where school_student_card in(".implode(',',$search_value_arr).") and status=0";
- $b_student=$this->conn->createCommand($sql)->queryAll();
- break;
- case 'zhixue_student_card':
- $sql="select student_id,zhixue_student_card from student where zhixue_student_card in(".implode(',',$search_value_arr).") and status=0";
- $b_student=$this->conn->createCommand($sql)->queryAll();
- break;
- default:
- $sql="select * from student_info si join student_paper_relation spr on si.student_id = spr.student_id where `".$check_field."` in(".implode(',',$search_value_arr).") and paper_id in(".implode(',',$paperIds).") ";
- $student_info=$this->sConn->createCommand($sql)->queryAll();
- }
- if($b_student){
- $studentIds=array();
- foreach ($b_student as $item){
- $studentIds[]=$item['student_id'];
- $student_card[$item['student_id']]=$item[$check_field];
- }
- $sql="select si.student_id from student_info si join student_paper_relation spr on si.student_id = spr.student_id where si.student_id in(".implode(',',$studentIds).") and paper_id in(".implode(',',$paperIds).") ";
- $student_info=$this->sConn->createCommand($sql)->queryAll();
- if($student_info){
- foreach($student_info as $key=>$val){
- $student_info[$key][$check_field]=$student_card[$val['student_id']];
- }
- }
- }
- if(!$student_info){
- $noExistent=count($search_value_arr);
- $result['repeat']=$repeat;
- $result['success']=$success;
- $result['noExistent']=$noExistent;
- $result['status']=1;
- }else{
- $result['status']=1;
- //过滤掉已被删除的学生
- foreach ($student_info as $key=>$value){
- $sql_class_relation="select * from student_class_relation where student_id='".$value['student_id']."' and status=0 ";
- $student_class_realtion=$this->sConn->createCommand($sql_class_relation)->queryRow();
- if(!$student_class_realtion){
- unset($student_info[$key]);
- }
- }
- if($check_field=='student_name'){
- $nameArr=array();
- foreach ($student_info as $item){
- $preg="/[^\x{4E00}-\x{9FFF}^·]+/u";
- $ModifyName = preg_replace($preg, "", $item['realname']);
- $nameArr[$ModifyName][]=$item;
- }
- $noExistent=count($search_value_arr)-count($nameArr);
- if($noExistent<0) $noExistent=0;
- $result['noExistent']=$noExistent;
- foreach ($nameArr as $key=>$value){
- if(count($value)>1){
- $repeat++;
- $updateSql[]="update import_score_temp set is_repeat=1 where check_field_value='".$key."' and (student_id is null or student_id=0) and exam_type=2";
- }else{
- $success++;
- if(isset($check_data_group[$key])){
- $update_temp_data[$check_data_group[$key]]=$value[0]['student_id'];
- }
- }
- }
- $result['repeat']=$repeat;
- $result['success']=$success;
- }else{
- $studentGroup=array();
- foreach ($student_info as $item){
- $studentGroup[$item[$check_field]][]=$item;
- }
- foreach ($studentGroup as $key=>$val){
- if(count($val)>1){
- $repeat++;
- $updateSql[]="update import_score_temp set is_repeat=1 where check_field_value='".$key."'and (student_id is null or student_id=0) and exam_type=2";
- }else{
- $success++;
- if(isset($check_data_group[$key])){
- $update_temp_data[$check_data_group[$key]]=$val[0]['student_id'];
- }
- }
- }
- $noExistent=count($search_value_arr)-count($studentGroup);
- if($noExistent<0) $noExistent=0;
- $result['noExistent']=$noExistent;
- $result['repeat']=$repeat;
- $result['success']=$success;
- }
- }
- }else{
- $result['repeat']=$repeat;
- $result['success']=$success;
- $result['noExistent']=0;
- $result['status']=1;
- }
- //更新检测成功的数据
- if($update_temp_data || $updateSql){
- $transcation = $this->sConn->beginTransaction();
- try {
- if($update_temp_data) {
- if ($check_field == 'student_name') {
- $sql = 'update import_score_temp set `student_id`= case id ';
- } else {
- $sql = 'update import_score_temp set `student_id`= case id ';
- }
- foreach ($update_temp_data as $key => $val) {
- $sql .= " WHEN " . $key . " THEN '" . $val . "' ";
- }
- $sql .= " End ";
- $sql .= " where (student_id='' or student_id is null) and exam_type=2";
- $this->sConn->createCommand($sql)->execute();
- }
- if($updateSql){
- foreach ($updateSql as $query){
- $this->sConn->createCommand($query)->execute();
- }
- }
- $transcation->commit();
- $result['status']=1;
- }catch (Exception $e){
- $result['status']=0;
- $transcation->rollback();
- }
- }
- exit(json_encode($result));
- }
- //处理重复学生
- public function actionHandle_repeat_img(){
- $page=Req::post('page');
- $name_like=Req::post('name');
- if(!$page) $page=1;
- $pageSize=10;
- $offset=($page-1)*$pageSize;
- $sql="select * from import_score_temp where exam_type=2 limit 1";
- $checkData=$this->sConn->createCommand($sql)->queryRow();
- $check_field=$checkData['check_field'];
- $sql="select count(*) as count,check_field_value,check_field from import_score_temp where is_repeat=1 and exam_type=2 group by check_field_value ";
- if($name_like){
- $sql.=" having check_field_value='".$name_like."'";
- }
- $sql.="order by count desc";
- $all_data=$this->sConn->createCommand($sql)->queryAll();
- if(!$all_data){
- $this->redirect(Yii::app()->createUrl('record/checkImgExcel'));
- }
- $repeat=array();
- $total=count($all_data);
- $data['total_page']=ceil($total/$pageSize);
- $data['name_group']=array_slice($all_data,$offset,$pageSize);
- $data['page']=$page;
- if(Yii::app()->request->isAjaxRequest){
- $result['status']=1;
- $result['data']=$data['name_group'];
- $result['total_page']=$data['total_page'];
- exit(json_encode($result));
- }else{
- if($check_field=='student_name'){
- $this->render('handle', $data);
- }else{
- $fileName=array(
- 'student_name'=>'学生姓名',
- 'userno'=>'学号',
- 'student_card'=>'准考证号',
- 'school_student_card'=>'学校准考证号',
- 'zhixue_student_card'=>'智学网考证号',
- 'id_number'=>'身份证号',
- 'student_phone'=>'手机号'
- );
- //扩展字段
- $studentExtend=$this->schoolManager->getStudentExtend();
- if($studentExtend){
- foreach ($studentExtend as $key=> $value){
- $fileName[$key]=$value['field_mean'];
- }
- }
- $data['fieldName']=$fileName[$check_field];
- $data['check_field']=$check_field;
- $this->render('handle_card_img', $data);
- }
- }
- }
- //修改后确认
- public function actionChange_check_img(){
- $check_value=Req::post('check_value');
- $result['status']=0;
- if(!$check_value){
- exit(json_encode($result));
- }
- $sql="select id,student_name,class_name,check_field_value,score_data,exam_group_id,check_field,renew,student_id,is_repeat from import_score_temp where check_field_value='".$check_value."' and is_repeat=1 and exam_type=2";
- $student_info=$this->sConn->createCommand($sql)->queryAll();
- if(!$student_info){
- $result['status']=1; //没有数据,处理完毕
- exit(json_encode($result));
- }elseif(count($student_info)>1){
- $result['status']=0; //还有重复数据,需要继续处理
- exit(json_encode($result));
- }else{
- //只剩一条,查询
- $data=$student_info[0];
- $check_field=$data['check_field'];
- $id=$data['id'];
- //系统中是否有数据
- $exam_group_id=$data['exam_group_id'];
- $exam_group_data = $this->sConn->createCommand("SELECT e.exam_id,e.tpl_data,p.paper_id,e.class_id FROM `exam` e join paper p on e.exam_id=p.exam_id where e.exam_group_id='".$exam_group_id."'")->queryAll();
- if(!$exam_group_data){
- $result['status']=0; //还有重复数据,需要继续处理
- exit(json_encode($result));
- }
- $paperIds=array();
- $examIds=array();
- $classIds=array();
- foreach ($exam_group_data as $value){
- $paperIds[]=$value['paper_id'];
- $examIds[]=$value['exam_id'];
- $classIds[]=$value['class_id'];
- }
- if($exam_group_data){
- $student_info=array();
- switch ($check_field){
- case 'student_name':
- $sql="select student_id,realname from student_info where realname ='".$check_value."' and class_id in(".implode(',',$classIds).")";
- $student_info=$this->sConn->createCommand($sql)->queryAll();
- break;
- case 'userno':
- $sql="select userno,student_id from student_info si ";
- $sql.="join student_class_relation scr on scr.student_id=si.student_id ";
- $sql.=" where scr.userno ='".$check_value."' and scr.status=0 and scr.class_id in(".implode(',',$classIds).")";
- $student_info=$this->sConn->createCommand($sql)->queryAll();
- break;
- case 'student_card':
- $sql="select student_id,student_card from student where student_card ='".$check_value."' and status=0";
- $b_student=$this->conn->createCommand($sql)->queryAll();
- break;
- case 'school_student_card':
- $sql="select student_id,school_student_card from student where school_student_card='".$check_value."' and status=0";
- $b_student=$this->conn->createCommand($sql)->queryAll();
- break;
- case 'zhixue_student_card':
- $sql="select student_id,zhixue_student_card from student where zhixue_student_card ='".$check_value."' and status=0";
- $b_student=$this->conn->createCommand($sql)->queryAll();
- break;
- default:
- $sql="select * from student_info where `".$check_field."` ='".$check_value."' and class_id in(".implode(',',$classIds).")";
- $student_info=$this->sConn->createCommand($sql)->queryAll();
- }
- if(isset($b_student) && $b_student){
- $studentIds=array();
- foreach ($b_student as $item){
- $studentIds[]=$item['student_id'];
- }
- $sql="select student_id from student_info where student_id in(".implode(',',$studentIds).") and class_id in(".implode(',',$classIds).")";
- $student_info=$this->sConn->createCommand($sql)->queryAll();
- }
- if(!$student_info){
- $updateSql="update import_score_temp set is_repeat=0,student_id='' where id={$id}";
- $this->sConn->createCommand($updateSql)->execute();
- $result['msg']='还有系统中不存在,或没有参加本次考试的数据,需要继续处理';
- $result['status']=0;
- exit(json_encode($result));
- }elseif(count($student_info)>1){
- $result['msg']='系统中存在多个该学生数据,请检查后重新填写';
- $result['status']=0;
- exit(json_encode($result));
- }else{
- $result['status']=1;
- $studentId=$student_info[0]['student_id'];
- //查询是否参加考试
- $StudentPaperRelation=$this->sConn->createCommand("select student_id,paper_id from `student_paper_relation` where student_id='".$studentId."' and paper_id in(".implode(',',$paperIds).")")->queryRow();
- if(!$StudentPaperRelation){
- $result['status']=1;
- $result['msg']='学生没有参加本次考试';
- exit(json_encode($result));
- }
- //判断学生id是否已关联过
- $related=$this->sConn->createCommand("select id from import_score_temp where student_id='".$studentId."' limit 1")->queryRow();
- if($related){
- $result['status']=0;
- $result['msg']='需要继续处理';
- exit(json_encode($result));
- }else{
- $updateSql="update import_score_temp set student_id='{$studentId}',is_repeat=0 where id={$id}";
- $this->sConn->createCommand($updateSql)->execute();
- exit(json_encode($result));
- }
- }
- }else{
- $result['msg']='考试数据有误';
- exit(json_encode($result));
- }
- }
- }
- //绑定学生id
- public function actionBindingImg(){
- $str=Req::post('str');
- $result['status']=0;
- if(!$str || !is_array($str)){
- exit(json_encode($result));
- }
- $studentIds=array();
- $tempIds=array();
- foreach($str as $val){
- @$nToId=explode('///',$val);
- if(isset($nToId[0])){
- if(in_array((string)$nToId[0],$studentIds,true)){
- $result['msg']='不能学生重复选择';
- exit(json_encode($result));
- }else{
- $studentIds[]=(string)$nToId[0];
- }
- }
- if(isset($nToId[1])){
- if(in_array((string)$nToId[1],$tempIds,true)){
- $result['msg']='不能学生重复选择';
- exit(json_encode($result));
- }else{
- $tempIds[]=(string)$nToId[1];
- }
- }
- }
- $updateSql=array();
- foreach($str as $val){
- @$nToId=explode('///',$val);
- if(isset($nToId[0]) && isset($nToId[1])){
- //判断学生id是否已关联过
- $related=$this->sConn->createCommand("select id from import_score_temp where student_id='".$nToId[0]."' and exam_type=2 limit 1")->queryRow();
- if($related){
- $result['msg']='学生已经被关联,请重新检查';
- exit(json_encode($result));
- }
- $updateSql[]="update import_score_temp set student_id='".$nToId[0]."',is_repeat=0 where id='".$nToId[1]."' and exam_type=2";
- }
- }
- if($updateSql){
- foreach($updateSql as $query){
- $this->sConn->createCommand($query)->execute();
- }
- $result['status']=1;
- }
- exit(json_encode($result));
- }
- //修改不存在的学生数据
- public function actionChange_value_img(){
- $id=Req::post('id');
- $value=Req::post('value');
- $result['status']=0;
- if(!$id || !$value){
- $result['msg']='参数不正确';
- exit(json_encode($result));
- }
- $sql="select student_name,class_name,check_field_value,score_data,exam_group_id,check_field,renew,student_id,is_repeat from import_score_temp where id='".$id."' limit 1";
- $data=$this->sConn->createCommand($sql)->queryRow();
- if(!$data){
- $result['msg']='id不正确';
- exit(json_encode($result));
- }
- $check_field=$data['check_field'];
- //excel中是否有重复数据
- $excelCheck="select id from import_score_temp where check_field_value='".$value."' and exam_type=2 ";
- $excelCheckData=$this->sConn->createCommand($excelCheck)->queryRow();
- if($excelCheckData){
- $result['msg']='excel中已存在相同记录';
- if($check_field=='student_name'){
- $result['status']=1;
- $updateSql="update import_score_temp set `is_repeat`=1,check_field_value='{$value}' where (id={$id} or check_field_value='{$value}') and exam_type=2";
- $this->sConn->createCommand($updateSql)->execute();
- $result['msg']='excel中已存在相同记录,请返回检测页面,继续处理重名';
- }
- exit(json_encode($result));
- }
- //系统中是否有数据
- $exam_group_id=$data['exam_group_id'];
- $exam_group_data = $this->sConn->createCommand("SELECT e.exam_id,e.tpl_data,p.paper_id,e.class_id FROM `exam` e join paper p on e.exam_id=p.exam_id where e.exam_group_id='".$exam_group_id."'")->queryAll();
- if(!$exam_group_data){
- $result['status']=0; //还有重复数据,需要继续处理
- exit(json_encode($result));
- }
- $paperIds=array();
- $examIds=array();
- $classIds=array();
- foreach ($exam_group_data as $val){
- $paperIds[]=$val['paper_id'];
- $examIds[]=$val['exam_id'];
- $classIds[]=$val['class_id'];
- }
- if($exam_group_data){
- $student_info=array();
- switch ($check_field){
- case 'student_name':
- $sql="select si.student_id,si.realname from student_info si join student_paper_relation spr on si.student_id = spr.student_id where realname ='".$value."' and paper_id in(".implode(',',$paperIds).")";
- $student_info=$this->sConn->createCommand($sql)->queryAll();
- break;
- case 'userno':
- $sql="select userno,spr.student_id from student_info si ";
- $sql.="join student_class_relation scr on scr.student_id=si.student_id ";
- $sql.="join student_paper_relation spr on si.student_id = spr.student_id ";
- $sql.=" where sscr.userno ='".$value."' and scr.status=0 and scr.class_id in(".implode(',',$classIds).") and spr.paper_id in(".implode(',',$paperIds).")";
- $student_info=$this->sConn->createCommand($sql)->queryAll();
- break;
- case 'student_card':
- $sql="select student_id,student_card from student where student_card ='".$value."' and status=0";
- $b_student=$this->conn->createCommand($sql)->queryAll();
- break;
- case 'school_student_card':
- $sql="select student_id,school_student_card from student where school_student_card='".$value."' and status=0";
- $b_student=$this->conn->createCommand($sql)->queryAll();
- break;
- case 'zhixue_student_card':
- $sql="select student_id,zhixue_student_card from student where zhixue_student_card='".$value."' and status=0";
- $b_student=$this->conn->createCommand($sql)->queryAll();
- break;
- default:
- $sql="select * from student_info si join student_paper_relation spr on si.student_id = spr.student_id where `".$check_field."` ='".$value."' and paper_id in(".implode(',',$paperIds).") ";
- $student_info=$this->sConn->createCommand($sql)->queryAll();
- }
- if(isset($b_student) && $b_student){
- $studentIds=array();
- foreach ($b_student as $item){
- $studentIds[]=$item['student_id'];
- }
- $sql="select si.student_id,si.realname from student_info si join student_paper_relation spr on si.student_id = spr.student_id where si.student_id in(".implode(',',$studentIds).") and paper_id in(".implode(',',$paperIds).")";
- $student_info=$this->sConn->createCommand($sql)->queryAll();
- }
- if(!$student_info){
- $result['msg']='系统中不存在,或学生没有参加该次考试';
- exit(json_encode($result));
- }elseif(count($student_info)>1){
- $updateSql="update import_score_temp set `is_repeat`=1,check_field_value='{$value}' where id={$id}";
- $this->sConn->createCommand($updateSql)->execute();
- $result['msg']='系统中存在多个该学生数据,请返回检测页面,继续处理重名';
- exit(json_encode($result));
- }else{
- $result['status']=1;
- $studentId=$student_info[0]['student_id'];
- //查询是否参加考试
- $StudentPaperRelation=$this->sConn->createCommand("select student_id,paper_id from `student_paper_relation` where student_id='".$studentId."' and paper_id in(".implode(',',$paperIds).")")->queryRow();
- if(!$StudentPaperRelation){
- $result['status']=1;
- $result['msg']='学生没有参加本次考试';
- exit(json_encode($result));
- }
- //判断学生id是否已关联过
- $related=$this->sConn->createCommand("select id from import_score_temp where student_id='".$studentId."' and exam_type=2 limit 1")->queryRow();
- if($related){
- $result['msg']='学生已经被关联,请重新检查';
- exit(json_encode($result));
- }
- $updateSql="update import_score_temp set student_id='{$studentId}',check_field_value='{$value}',is_repeat=0 where id={$id}";
- $this->sConn->createCommand($updateSql)->execute();
- exit(json_encode($result));
- }
- }else{
- $result['msg']='考试数据有误';
- exit(json_encode($result));
- }
- }
- //处理不存在学生
- public function actionHandle_existent_img(){
- $fileName=array(
- 'student_name'=>'学生姓名',
- 'userno'=>'学号',
- 'student_card'=>'准考证号',
- 'school_student_card'=>'学校准考证号',
- 'zhixue_student_card'=>'智学网考证号',
- 'id_number'=>'身份证号',
- 'student_phone'=>'手机号'
- );
- //扩展字段
- $studentExtend=$this->schoolManager->getStudentExtend();
- if($studentExtend){
- foreach ($studentExtend as $key=> $value){
- $fileName[$key]=$value['field_mean'];
- }
- }
- //查询不存在的数据
- $sql="select * from import_score_temp where is_repeat=0 and (student_id is null or student_id =0) and exam_type=2 ";
- $all_data=$this->sConn->createCommand($sql)->queryAll();
- if($all_data){
- $data['check_field']=$all_data[0]['check_field'];
- }else{
- $data['check_field']='';
- }
- $data['list']=$all_data;
- $data['fieldName']=$fileName;
- $this->render('handle_existent',$data);
- }
- //处理完毕,执行图片导入
- public function actionUpdate_images(){
- ini_set('memory_limit','512M');
- $result['status']=0;
- $sql="select * from import_score_temp where student_id is not null and is_repeat=0 and exam_type=2";
- $all_data=$this->sConn->createCommand($sql)->queryAll();
- if(!$all_data){
- $result['msg']='没有发现可导入学生成绩数据';
- exit(json_encode($result));
- }
- $exam_group_id=$all_data[0]['exam_group_id'];
- $exam = $this->sConn->createCommand("SELECT e.exam_id,e.tpl_data,p.paper_id FROM `exam` e join paper p on e.exam_id=p.exam_id where e.exam_group_id='".$exam_group_id."'")->queryAll();
- if(!$exam){
- $result['msg']='考试ID不正确,请从考试列表点击上传成绩';
- exit(json_encode($result));
- }
- $paperIds=array();
- $examIds=array();
- foreach ($exam as $value){
- $paperIds[]=$value['paper_id'];
- $examIds[]=$value['exam_id'];
- }
- $tpl_data=json_decode($exam[0]['tpl_data'],true);
- $paper_topic_relation=$this->sConn->createCommand("select `paper_id`,`topic_id`,`no`,`score`,`type` from `paper_topic_relation` where paper_id='".$paperIds[0]."'")->queryAll();
- if(!$paper_topic_relation){
- $result['msg']='请关联答题卡';
- exit(json_encode($result));
- }
- $paper_topic_rs=array();
- $paperType=array();
- foreach ($paper_topic_relation as $key=>$value){
- $paper_topic_rs[$key]=$value['topic_id'];
- $paperType[$key]=$value['type'];
- }
- $error=array();
- $updateArr=array();
- $studentInPaper=array();
- foreach($all_data as $val){
- $StudentPaperRelation=$this->sConn->createCommand("select student_id,paper_id from `student_paper_relation` where student_id='".$val['student_id']."' and paper_id in(".implode(',',$paperIds).")")->queryRow();
- if(!$StudentPaperRelation){
- $error[]='学生没有参加本次考试 :'.$val['student_name'];
- continue;
- }
- $studentInPaper[(string)$val['student_id']]=$StudentPaperRelation['paper_id'];
- $topicScoreData=json_decode($val['score_data'],true);
- if($val['check_field']!='student_name'){
- $topicScoreData=array_slice($topicScoreData,1);
- }
- $topicScoreData=array_values($topicScoreData);
- foreach($topicScoreData as $key=> $ts){
- if(!$ts) continue;
- $topic_id= $paper_topic_rs[$key];
- $image_array = @getimagesize($ts);
- if ($image_array && isset($image_array[0]) && isset($image_array[1])) {
- $updateArr[(string)$val['student_id']]['answer_url'][$topic_id]=$ts;
- $updateArr[(string)$val['student_id']]['answer_url_width'][$topic_id]=$image_array[0];
- $updateArr[(string)$val['student_id']]['answer_url_height'][$topic_id]=$image_array[1];
- $updateArr[(string)$val['student_id']]['simplify_answer_url'][$topic_id]=$ts;
- $updateArr[(string)$val['student_id']]['simplify_answer_url_width'][$topic_id]=$image_array[0];
- $updateArr[(string)$val['student_id']]['simplify_answer_url_height'][$topic_id]=$image_array[1];
- }
- }
- }
- if($updateArr){
- $transaction = $this->sConn->beginTransaction();
- try{
- $sqlArr=array();
- foreach ($updateArr as $student_id =>$value){
- $updateSqlTemp=array();
- $sql='update `student_paper_topic_rs` set ';
- foreach ($value as $filed =>$val){
- $updateSqlStr=" `{$filed}` = case topic_id ";
- foreach ($val as $topic_id =>$v){
- $updateSqlStr.=" WHEN '".$topic_id."' THEN '".$v."' ";
- }
- $updateSqlStr.=" ELSE `{$filed}` ";
- $updateSqlStr.=" END ";
- $updateSqlTemp[]=$updateSqlStr;
- }
- $sqlArr[]= $sql.implode(',',$updateSqlTemp)." where student_id='".$student_id."' and paper_id ='".$studentInPaper[$student_id]."'";
- }
- foreach ($sqlArr as $v){
- $this->sConn->createCommand($v)->execute();
- }
- //清理导入临时数据
- $delSql="delete from import_score_temp where exam_type=2;";
- $this->sConn->createCommand($delSql)->execute();
- $transaction->commit();
- $result['status']=1;
- if($error){
- // Yii::app()->jump->error('导入成功,有部分学生成绩没有导入:'.implode(',',$error));
- $result['msg']=implode('<br>',$error);
- }else{
- $result['msg']='导入成功';
- }
- 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" =>'',
- "date"=>date('Y-m-d H:i:s')
- )));
- }
- exit(json_encode($result));
- }catch (Exception $e) {
- //如果操作失败, 数据回滚
- $transaction->rollback();
- // Yii::app()->jump->error('成绩导入失败,请检查后重新');
- $result['msg']='图片导入失败,请检查后重新导入';
- exit(json_encode($result));
- }
- }else{
- //没有需要重新导入的数据,清理导入临时数据
- //$delSql="truncate table import_score_temp;";
- $delSql="delete from import_score_temp where exam_type=2;";
- $this->sConn->createCommand($delSql)->execute();
- $result['status']=1;
- exit(json_encode($result));
- }
- }
- public function actionT(){
- //$image_array = getimagesize('http://zxhx-n-1302712961.cos.ap-beijing.myqcloud.com/PT/CScut/4016/990807494965600256/945581044318568448/6.jpg');
- //$image_array = getimagesize('https://pics7.baidu.com/feed/2cf5e0fe9925bc31e23d52434fdae8bdca13709e.jpeg');
- $image_array = getimagesize('http://ftp.hujiao.com/iu-1.png');
- debug($image_array);
- }
- }
|