1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860 |
- <?php
- /**
- * 导入学生控制器类
- * @author li
- * @date 2018-12-24 9:50:00
- * @company 上海风车教育有限公司.
- */
- class ImportstudentController extends Controller
- {
- public $fileName=array(
- 'userno'=>'学号',
- 'school_student_card'=>'学校准考证号',
- 'zhixue_student_card'=>'智学网准考证号',
- 'id_number'=>'身份证号',
- 'student_phone'=>'手机号',
- 'is_outer'=>'在籍生'
- );
- public function actionIndex(){
- $this->sConn->createCommand("DELETE FROM `import_student_temp` where import_type=2 ")->execute();
- $student_all_data = $this->sConn->createCommand("SELECT id FROM `import_student_temp` limit 1 ")->queryRow();
- if($student_all_data){
- $this->render('check');
- }else{
- $this->render('index');
- }
- }
- public function actionTemplate(){
- $fileName=array(
- 'userno'=>'学号',
- 'school_student_card'=>'学校准考证号',
- 'zhixue_student_card'=>'智学网准考证号',
- 'id_number'=>'身份证号',
- 'student_phone'=>'手机号',
- 'is_outer'=>'在籍生'
- );
- //扩展字段
- $studentExtend=$this->schoolManager->getStudentExtend();
- if($studentExtend){
- foreach ($studentExtend as $key=> $value){
- if($value['is_enable']==1){
- $fileName[$key]=$value['field_mean'];
- }
- }
- }
- $data['fileName']=$fileName;
- $template=$this->sConn->createCommand("select tpl_data from import_student_template limit 1")->queryRow();
- if($template && isset($template['tpl_data'])){
- $data['tpl_data']=json_decode($template['tpl_data'],true);
- }
- $this->render('template',$data);
- }
- public function actionSave_template(){
- $tpl_data=Req::post('data');
- $result['status']=0;
- if(!$tpl_data) exit(json_encode($result));
- $table=$tpl_data[0];
- $tpl_data=array_slice($table,5);
- foreach ($tpl_data as $key=>$val){
- if($val=='-1'){
- unset($tpl_data[$key]);
- }
- }
-
- $template=$this->sConn->createCommand("select id from import_student_template limit 1")->queryRow();
- if($template){
- $this->sConn->createCommand("update import_student_template set tpl_data='".json_encode($tpl_data)."'")->execute();
- }else{
- $this->sConn->createCommand("insert into import_student_template set tpl_data='".json_encode($tpl_data)."'")->execute();
- }
- $result['status']=1;
- exit(json_encode($result));
- }
- public function actionImport(){
- ini_set ('memory_limit', '300M');
- if(!$_FILES){
- Yii::app()->jump->error('文件大小超过范围');
- }else {
- if (!isset($_FILES['student_file']) || !isset($_FILES['student_file']['size']) || $_FILES['student_file']['size'] > 5242880) {
- Yii::app()->jump->error('文件大小超过范围');
- }
- }
- if (Yii::app()->request->getIsPostRequest()) {
- //读取模板
- $template=$this->schoolManager->getImportStudentTemplate();
- if(!$template){
- Yii::app()->jump->error('请先设置导入学生模板');
- }
- @$tpl_data=json_decode($template,true);
- if(!$tpl_data){
- //Yii::app()->jump->error('模板数据异常,请重新设置模板');
- }
- $uploader = new Uploader("upload/tmpDir/UploadClassesStudentsList/{$this->schoolId}/");
- $uploader->allowTypes = array("xls","xlsx");
- $uploader->fieldsMappings = array("exname" => array(0 => $this->schoolId));
- $file = $uploader->act();
- $file = Arr::current(Arr::current($file));
- if (!$file || !isset($file["error"]))
- Yii::app()->jump->error('请上传的Excel!');
- if ($file["error"] != 0) {
- switch ($file["error"]) {
- case 2001:
- Yii::app()->jump->error('文件类型不符');
- break;
- case 2002:
- Yii::app()->jump->error('文件大小超出允许范围');
- break;
- default:
- Yii::app()->jump->error('上传失败');
- break;
- }
- }
- $inputFileName = $file["src"];
- if(Yii::app()->params['handle_log_on_off'])
- {
- writeFileLog(jsonEncode(array(
- "exam_group_id" => 0,
- "operate_project" => 'zsyas2',
- "school_id" => $this->schoolId,
- "title" => '导入学生',
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $this->getRoute(),
- "operate_sql" =>'',
- "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET,'file'=>$inputFileName)),
- "date"=>date('Y-m-d H:i:j')
- )));
- }
- // 导入PHPExcel类
- Yii::import('application.extensions.*');
- require_once('phpexcel/PHPExcel/IOFactory.php');
- try{
- $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
- $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
- //FIXME 2019-12-23
- @unlink($file["src"]);
- }catch (Exception $e){
- //FIXME 2019-12-23
- @unlink($file["src"]);
- Yii::app()->jump->error('Excel格式不正确:'.$e->getMessage());
- }
- if(!$sheetData)
- {
- Yii::app()->jump->error('请正确的Excel!');
- }
- unset($objPHPExcel);
- //扩展字段
- $studentExtend=$this->schoolManager->getStudentExtend();
- if($studentExtend){
- foreach ($studentExtend as $key=> $value){
- if($value['is_enable']==1){
- $this->fileName[$key]=$value['field_mean'];
- }
- }
- }
- //检查模板
- $tempHeader=array(
- '班级','姓名','性别(男/女)','系统准考证号'
- );
- foreach ($tpl_data as $datum){
- $tempHeader[]=$this->fileName[$datum];
- }
- $sheetHead=$sheetData[1];
- if(count($sheetHead)!=count($tempHeader)){
- Yii::app()->jump->error('导入学生Excel格式与模板不匹配! ');
- }
- $sheetHead=array_values($sheetHead);
- foreach ($tempHeader as $key => $value){
- if(!isset($sheetHead[$key]) || trim($sheetHead[$key])!=$value){
- Yii::app()->jump->error('导入学生Excel格式与模板不匹配:'.$value);
- }
- }
- unset($sheetData[1]);
- if(!$sheetData)
- {
- Yii::app()->jump->error('请输入学生数据');
- }
- //获取当前学期的所有班级
- $semesterId = $this->semesterId;
- $class_semester_data = ClassModel::model()->findAll('semester_id=:semester_id',array(':semester_id'=>$semesterId));
- if($class_semester_data)
- {
- foreach($class_semester_data as $v)
- {
- $class_ids[$v->class_id] = $v->class_id;
- $c_class_names[$v->class_id] = (string)$v->class_name;
- }
- }
- unset($class_semester_data);
- if(!$class_ids)
- {
- Yii::app()->jump->error('当前学期无班级信息,导入失败');
- }
- $insertValue="insert into import_student_temp(`student_name`,`class_name`,`sex`,`extend`,`id_number`,`student_card`) values ";
- $values=array();
- $studentCard=array();
- $schoolStudentCard=array();
- foreach ($sheetData as $val){
- if(!$val['A'] || !$val['B'] || !$val['C']){
- //Yii::app()->jump->error('班级,姓名,性别不能为空');
- continue;
- }
- if(count($val)!=count($tpl_data)+4){
- Yii::app()->jump->error('导入学生Excel格式与模板不匹配! ');
- }
- if($val['D']){
- $studentCard[$val['D']][]=$val['D'];
- }
- //扩展信息基本校验
- $extendKeyValue=array();
- if($tpl_data){
- $extend=array_slice($val,4);
- $preg_card='/^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/i';
- $preg_phone='/^1[34578]\d{9}$/ims';
- $extend=array_values($extend);
- foreach ($extend as $key=>$v){
- if(!$v){
- $extendKeyValue[$tpl_data[$key]]='';
- continue;
- }
- switch ($tpl_data[$key]){
- case 'userno':
- if(!is_numeric($v)){
- Yii::app()->jump->error('学号只能是数字! ');
- }
- break;
- case 'school_student_card':
- if(!is_numeric($v)){
- Yii::app()->jump->error('学校准考证号格式错误! ');
- }
- $schoolStudentCard[$v][]=$v;
- break;
- case 'id_number':
-
- if(!preg_match($preg_card,$v)){
- Yii::app()->jump->error('身份证格式不正确! ');
- }
- break;
- case 'student_phone':
- if(!preg_match($preg_phone,$v)){
- Yii::app()->jump->error('手机号格式不正确! ');
- }
- break;
- case 'zhixue_student_card':
- if(!is_numeric($v)){
- Yii::app()->jump->error('智学网准考证号格式错误! ');
- }
- break;
- case 'is_outer':
- $isOuter=0;
- if(!isset($v) || !$v || $v=='是') {
- $v = '是';
- $isOuter = 0;
- }elseif($v=='否'){
- $isOuter = 1;
- }elseif(!in_array($v,array('是','否'))){
- Yii::app()->jump->error('在籍生填写错误! ');
- }
- $v=$isOuter;
- break;
- }
- $extendKeyValue[$tpl_data[$key]]=$v;
- }
- }
- $sex=1;
- if($val['C']=='女'){
- $sex=2;
- }
- $id_number=0;
- if(isset($extendKeyValue['id_number'])){
- $id_number=$extendKeyValue['id_number'];
- }
- if(!$val['D']){
- $val['D']=0;
- }
- $values[]="('".$val['B']."','".$val['A']."','".$sex."','".jsonEncode($extendKeyValue)."','".$id_number."','".$val['D']."')";
- }
- //检测系统准考证号是否重复
- $errorStudentCard=array();
- if($studentCard){
- foreach ($studentCard as $item){
- if(count($item)>1){
- $errorStudentCard[]=$item[0];
- }
- }
- }
- if($errorStudentCard){
- if(count($errorStudentCard)>3){
- Yii::app()->jump->error('系统准考证号重复: '.implode(',',array_slice($errorStudentCard,0,3)).' ...... ');
- }else{
- Yii::app()->jump->error('系统准考证号重复: '.implode(',',$errorStudentCard));
- }
- }
- $errorSchoolStudentCard=array();
- if($schoolStudentCard){
- foreach ($schoolStudentCard as $item){
- if(count($item)>1){
- $errorSchoolStudentCard[]=$item[0];
- }
- }
- }
-
- if($errorSchoolStudentCard){
- if(count($errorSchoolStudentCard)>3){
- Yii::app()->jump->error('学校准考证号重复: '.implode(',',array_slice($errorSchoolStudentCard,0,3)).' ...... ');
- }else{
- Yii::app()->jump->error('学校准考证号重复: '.implode(',',$errorSchoolStudentCard));
- }
- }
- if($values){
- $sql=$insertValue.implode(',',$values);
- $transaction = $this->sConn->beginTransaction();
- try{
- $this->sConn->createCommand($sql)->execute();
- $transaction->commit();
- // Yii::app()->jump->error('Excel导入成功!');
- //跳转检测页
- $this->redirect($this->createUrl('importstudent/check'));
- }catch(Exception $e){
- $transaction->rollBack();
- Yii::app()->jump->error('Excel导入失败!');
- }
- }else{
- Yii::app()->jump->error('Excel导入失败!');
- }
- }
- }
- public function actionCheck(){
- $this->render('check');
- }
- //检测姓名
- public function actionCheck_student_name(){
- ini_set('memory_limit','512M');
- set_time_limit(0);
- $result['status']=0;
- $result['data']=0;
- $id_number=array();
- $clearIdNumber=array(); //需要清除身份证
- $studentCard=array();
- $student_all_data = $this->sConn->createCommand("SELECT id,student_name,id_number FROM `import_student_temp` `t` ")->queryAll();
- if($student_all_data){
- //去除非中文字符
- $updateArr=array();
- $preg="/[^\x{2E80}-\x{FE4F}0-9^·]+/u";
- $count=0;
- foreach($student_all_data as $val){
- if($val['id_number']){
- //判断系统中是否存在
- if($this->schoolManager->checkStudentIdNumber($val['id_number'])){
- $clearIdNumber[]=$val['id'];
- }
- $id_number[$val['id_number']][]=$val['id'];
- }
- 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($id_number){
- foreach ($id_number as $number=>$vid){
- if(count($vid)>1){
- $clearIdNumber=array_merge($clearIdNumber,$vid);
- }
- }
- }
- //组织更新语句
- if($updateArr){
- $arrNumber=ceil(count($updateArr)/500);
- $Arr=array_chunk($updateArr,$arrNumber,true);
- $transcation = $this->sConn->beginTransaction();
- try {
- if($clearIdNumber){
- $this->sConn->createCommand("update import_student_temp set id_number=0 where id in(".implode(',',$clearIdNumber).")")->execute();
- }
- foreach ($Arr as $item){
- $sql='update import_student_temp set `modify_name`= case id ';
- foreach ($item as $key=> $val){
- $sql.=" WHEN ".$key." THEN '".$val."' ";
- }
- $sql.=" End ";
- $sql.=" where modify_name='' or modify_name is null";
- $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(){
- $classNotFound=array(); //班级名称不一致
- $repeat=array(); //重名
- $success=array(); //正常
- $updateClassValue=array(); //需要更新的班级不存在数据
- $updateRepeatValue=array(); //需要更新重复数据
- $studentName=array();
- $studentCardValue=array(); //准考证号不存在
- $updateStudentCard=array();
- $idNumber=array();
- $updateStudentId=array(); //匹配成功需要更新student_id数据
- $updateClassId=array(); //更新班级id
- $result['status']=0;
- $student_all_data = $this->sConn->createCommand("SELECT id,student_name,class_name,modify_name,student_id,is_repeat,class_not_found,is_normal,id_number,student_card FROM `import_student_temp` `t` ")->queryAll();
- if(!$student_all_data){
- $result['msg']='请先导入excel数据';
- exit(json_encode($result));
- }
- $preSemesterId=$this->schoolManager->getPrevSemesterId();
- $nowSemester=$this->semesterId;
- foreach ($student_all_data as $key=>$val){
- if($val['is_repeat']==1){
- $repeat[$val['modify_name']][]=$val;
- unset($student_all_data[$key]);
- }
- if($val['class_not_found']==1){
- $classNotFound[$val['class_name']][]=$val;
- unset($student_all_data[$key]);
- }
- if($val['class_not_found']==2){
- $studentCardValue[]=$val['id'];
- unset($student_all_data[$key]);
- }
- if($val['is_normal']==1){
- $success[]=1;
- unset($student_all_data[$key]);
- }
- }
- if(!$student_all_data){
- $result['studentCard']=count($studentCardValue);
- $result['repeat']=count($repeat);
- $result['success']=count($success);
- $result['noExistent']=count($classNotFound);
- $result['status']=1;
- exit(json_encode($result));
- }
- //判断班级是否存在
- foreach($student_all_data as $val){
- $class_id=$this->schoolManager->classNameExists($val['class_name'],$nowSemester);
- if(!$class_id){
- $classNotFound[$val['class_name']][]=$val;
- $updateClassValue[]="'".$val['class_name']."'"; //班级不存在
- }else{
- //判断准考证号
- if($val['student_card']){
- $sql="select student_id from student where student_card ='".$val['student_card']."' and status=0 and school_id='".$this->schoolId."'";
- $b_student=$this->conn->createCommand($sql)->queryRow();
- if($b_student){
- //判断姓名
- $student_card_name=$this->sConn->createCommand("select realname from student_info where student_id='".$b_student['student_id']."'")->queryRow();
- if(!$student_card_name){
- $studentCardValue[]=$val['id'];
- $updateClassId[$val['class_name']]="update import_student_temp set class_id='".$class_id."' where class_name='".$val['class_name']."'";
- }elseif($student_card_name['realname']!=$val['student_name']){
- $studentCardValue[]=$val['id'];
- $updateClassId[$val['class_name']]="update import_student_temp set class_id='".$class_id."' where class_name='".$val['class_name']."'";
- }else{
- //存在学生
- $updateStudentCard[]="update import_student_temp set class_id='".$class_id."',student_id='".$b_student['student_id']."',is_normal=1 where student_card='".$val['student_card']."'";
- $success[]=$val['id'];
- }
- }else{
- $updateClassId[$val['class_name']]="update import_student_temp set class_id='".$class_id."' where class_name='".$val['class_name']."'";
- $studentCardValue[]=$val['id'];
- }
- }else{
- $updateClassId[$val['class_name']]="update import_student_temp set class_id='".$class_id."' where class_name='".$val['class_name']."'";
- $studentName[$val['modify_name']][]=$val['id'];
- $idNumber[$val['id']]=$val['id_number'];
- }
- }
- }
- //判断姓名是否正常
- if($studentName){
- foreach ($studentName as $k=>$v){
- if(count($v)>1){ //当前excel中学生(去掉姓名中非汉字字符后)存在重名
- $repeat[]=$v;
- $updateRepeatValue=array_merge($updateRepeatValue,$v);
- }else{
- //读取系统中数据
- $student=$this->schoolManager->getStudentByNameClass($k,$nowSemester,$idNumber[$v[0]]);
- if(!$student){
- //不存在,正常数据 需要创建
- $success[]=$v[0];
- // }elseif(count($student)==1){
- //存在且唯一,正常数据 需要转班 !!!没有系统准考证号,都需要重新确认
- // $success[]=$v[0];
- // $updateStudentId[$v[0]]=(string)$student[0]['student_id'];
- }else{
- //系统中重名
- $repeat[]=$v[0];
- $updateRepeatValue[]=$v[0];
- }
- }
- }
- }
- //更新检测成功的数据
- if($updateRepeatValue || $updateStudentId || $updateClassValue || $success || $studentCardValue || $updateClassId || $updateStudentCard){
- $transcation = $this->sConn->beginTransaction();
- try {
- if($studentCardValue){
- //准考证号不存在
- $this->sConn->createCommand("update import_student_temp set class_not_found=2 where id in(".implode(',',$studentCardValue).")")->execute();
- }
- if($updateStudentId) {
- $sql = 'update import_student_temp set `student_id`= case id ';
- foreach ($updateStudentId as $key => $val) {
- $sql .= " WHEN " . $key . " THEN '" . $val . "' ";
- }
- $sql .= " End ";
- $sql .= " where student_id='' or student_id is null";
- $this->sConn->createCommand($sql)->execute();
- }
- if($updateRepeatValue){
- $this->sConn->createCommand("update import_student_temp set is_repeat=1 where id in(".implode(',',$updateRepeatValue).")")->execute();
- }
- if($updateClassValue){
- $updateClassValue=array_values($updateClassValue);
- $this->sConn->createCommand("update import_student_temp set class_not_found=1 where class_name in(".implode(',',$updateClassValue).")")->execute();
- }
- if($updateClassId){
- foreach ($updateClassId as $query){
- $this->sConn->createCommand($query)->execute();
- }
- }
- if($updateStudentCard){
- foreach ($updateStudentCard as $query){
- $this->sConn->createCommand($query)->execute();
- }
- }
- if($success){
- $success=array_values($success);
- $this->sConn->createCommand("update import_student_temp set is_normal=1 where id in(".implode(',',$success).")")->execute();
- }
- $transcation->commit();
- $result['status']=1;
- }catch (Exception $e){
- $result['status']=0;
- $transcation->rollback();
- }
- }
- $result['studentCard']=count($studentCardValue);
- $result['repeat']=count($repeat);
- $result['success']=count($success);
- $result['noExistent']=count($classNotFound);
- $result['status']=1;
- exit(json_encode($result));
- }
- //重新上传
- public function actionGiveup(){
- //$delSql="truncate table import_student_temp;";
- $delSql="delete from import_student_temp;";
- $this->sConn->createCommand($delSql)->execute();
- $result['status']=1;
- exit(json_encode($result));
- }
- //系统准考证不存在
- public function actionHandle_existent_card(){
- $notFound=$this->sConn->createCommand("select id,student_name,modify_name,class_name,student_card from import_student_temp where class_not_found=2")->queryAll();
- if(!$notFound) $this->redirect($this->createUrl('importstudent/check'));
- $data['student']=$notFound;
- $this->render('handle_existent_card',$data);
- }
- //系统不存在
- public function actionHandle_existent(){
- $notFound=$this->sConn->createCommand("select id,class_name from import_student_temp where class_not_found=1")->queryAll();
- if(!$notFound) $this->redirect($this->createUrl('importstudent/check'));
- $className=array();
- foreach ($notFound as $val){
- $className[$val['class_name']][]=$val;
- }
- $data['className']=$className;
- $this->render('handle_existent',$data);
- }
- //修改班级名称
- public function actionChange_value(){
- $old_class_name=Req::post('data');
- $value=Req::post('value');
- $result['status']=0;
- if(!$old_class_name || !$value){
- $result['msg']='参数不正确';
- exit(json_encode($result));
- }
- $valueArr=array();
- $sql="select id,modify_name,student_name,sex,extend,student_id,student_card from import_student_temp where class_name='".$old_class_name."' ";
- $data=$this->sConn->createCommand($sql)->queryAll();
- if(!$data){
- $result['msg']='数据异常';
- exit(json_encode($result));
- }
- $nowSemester=$this->semesterId;
- $class_id=$this->schoolManager->classNameExists($value,$nowSemester);
- $updateClassId=array();
- if(!$class_id){
- $result['status']=0;
- $result['msg']='班级在系统中不存在';
- exit(json_encode($result));
- }else{
- foreach ($data as $key => $val){
- //判断准考证号
- if($val['student_card']){
- $sql="select student_id from student where student_card ='".$val['student_card']."' and status=0 and school_id='".$this->schoolId."'";
- $b_student=$this->conn->createCommand($sql)->queryRow();
- if($b_student){
- //存在学生
- $valueArr[]="('".$val['student_name']."','".$value."','".$val['sex']."','".$val['modify_name']."','".$val['extend']."','".$b_student['student_id']."','".$class_id."','".$val['student_card']."',0,0,1)";
- unset($data[$key]);
- }else{
- $valueArr[]="('".$val['student_name']."','".$value."','".$val['sex']."','".$val['modify_name']."','".$val['extend']."','".$b_student['student_id']."','".$class_id."','".$val['student_card']."',0,2,0)";
- unset($data[$key]);
- }
- }
- }
- if($data){
- //班级存在,判断姓名
- //读取系统中数据
-
- $nameArr=array();
- foreach ($data as $val){
- $nameArr[$val['modify_name']][]=$val;
- }
- foreach ($nameArr as $Name=>$val){
- if(count($val)>1){ //当前excel中学生(去掉姓名中非汉字字符后)存在重名
- foreach ($val as $v){
- if(!$v['student_id']){
- $v['student_id']=0;
- }
- $valueArr[]="('".$v['student_name']."','".$value."','".$v['sex']."','".$v['modify_name']."','".$v['extend']."','".$v['student_id']."','".$class_id."','".$v['student_card']."',1,0,0)";
- }
- }else{
- $student=$this->schoolManager->getStudentByNameClass($Name,$nowSemester);
- if(!$val[0]['student_id']){
- $val[0]['student_id']=0;
- }
- if(!$student){
- //不存在,正常数据 需要创建
- $valueArr[]="('".$val[0]['student_name']."','".$value."','".$val[0]['sex']."','".$val[0]['modify_name']."','".$val[0]['extend']."','".$val[0]['student_id']."','".$class_id."','".$val[0]['student_card']."',0,0,1)";
- // }elseif(count($student)==1){
- //存在且唯一,正常数据 需要转班
- // $valueArr[]="('".$val[0]['student_name']."','".$value."','".$val[0]['sex']."','".$val[0]['modify_name']."','".$val[0]['extend']."','".$student[0]['student_id']."','".$class_id."',0,0,1)";
- }else{
- //系统中重名
- $valueArr[]="('".$val[0]['student_name']."','".$value."','".$val[0]['sex']."','".$val[0]['modify_name']."','".$val[0]['extend']."','".$val[0]['student_id']."','".$class_id."','".$val[0]['student_card']."',1,0,0)";
- }
- }
- }
- }
- $transcation = $this->sConn->beginTransaction();
- try {
- if($valueArr) {
- $insert="insert into import_student_temp(`student_name`,`class_name`,`sex`,`modify_name`,`extend`,`student_id`,`class_id`,`student_card`,`is_repeat`,`class_not_found`,`is_normal`) values ";
- $this->sConn->createCommand("delete from import_student_temp where class_name='".$old_class_name."'")->execute();
- $this->sConn->createCommand($insert.implode(',',$valueArr))->execute();
- }
- $transcation->commit();
- $result['status']=1;
- }catch (Exception $e){
- $result['status']=0;
- $transcation->rollback();
- }
- exit(json_encode($result));
- }
- }
- //修改身份证号码
- public function actionChange_idnumber(){
- $id=Req::post('id');
- $value=Req::post('value');
- $result['status']=0;
- if(!$id || !$value){
- $result['msg']='参数不正确';
- exit(json_encode($result));
- }
- //判断系统中是否存在
- if($this->schoolManager->checkStudentIdNumber($value)){
- $result['status']=0;
- $result['msg']='系统中已存在相同身份证,请检查后重新确认';
- exit(json_encode($result));
- }
- //判断表格中是否存在
- $sql="select id,modify_name from import_student_temp where id_number='".$value."' ";
- $data=$this->sConn->createCommand($sql)->queryRow();
- if($data){
- $result['msg']='导入的数据中中已存在相同身份证,请检查后重新确认';
- exit(json_encode($result));
- }
- if($this->sConn->createCommand("update import_student_temp set id_number='".$value."',is_normal=1,is_repeat=0 where id='".$id."'")->execute()){
- $result['status']=1;
- }
- exit(json_encode($result));
- }
- //修改准考证号码
- public function actionChange_studentcard(){
- $id=Req::post('id');
- $value=Req::post('value');
- $result['status']=0;
- if(!$id || !$value){
- $result['msg']='参数不正确';
- exit(json_encode($result));
- }
- $excel_data=$this->sConn->createCommand("select student_name from import_student_temp where id='".$id."'")->queryRow();
- if(!$excel_data){
- $result['msg']='参数不正确';
- exit(json_encode($result));
- }
- //判断表格中是否存在
- $sql="select id,student_name from import_student_temp where student_card='".$value."' and id!='".$id."' ";
- $data=$this->sConn->createCommand($sql)->queryRow();
- if($data){
- $result['msg']='导入的数据中中已存在相同准考证'.$data['student_name'].',请检查后重新确认';
- exit(json_encode($result));
- }
- //验证系统中是否存在
- $sql="select student_id from student where student_card ='".$value."' and status=0 and school_id='".$this->schoolId."'";
- $b_student=$this->conn->createCommand($sql)->queryRow();
- if(!$b_student){
- $result['msg']='准考证号不存在,请检查后重新确认';
- exit(json_encode($result));
- }else{
- //判断姓名
- $student_card_name=$this->sConn->createCommand("select realname from student_info where student_id='".$b_student['student_id']."'")->queryRow();
- if(!$student_card_name){
- $result['msg']='准考证号不存在,请检查后重新确认';
- exit(json_encode($result));
- }elseif($student_card_name['realname']!=$excel_data['student_name']){
- $result['msg']='新的准考证号与表格姓名不匹配,请检查后重新确认';
- exit(json_encode($result));
- }else{
- if($this->sConn->createCommand("update import_student_temp set student_card='".$value."',is_normal=1,is_repeat=0,class_not_found=0,student_id='".$b_student['student_id']."' where id='".$id."'")->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 count(*) as count, id,student_name,class_name,sex,modify_name,extend from import_student_temp where is_repeat=1 group by modify_name ";
- 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){
- Yii::app()->jump->error('没有重名的数据! ');
- }
- $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{
- $this->render('handle_card', $data);
- }
- }
- //根据名称加载重名学生
- public function actionShowrepeatstudent(){
- $name=Req::post('name');
- $fileName=array(
- 'userno'=>'学号',
- 'school_student_card'=>'学校准考证号',
- 'zhixue_student_card'=>'智学网准考证号',
- 'id_number'=>'身份证号',
- 'student_phone'=>'手机号',
- 'is_outer'=>'在籍生'
- );
- //扩展字段
- $studentExtend=$this->schoolManager->getStudentExtend();
- if($studentExtend){
- foreach ($studentExtend as $key=> $value){
- $fileName[$key]=$value['field_mean'];
- }
- }
- $classIds=array();
- $sql="select * from import_student_temp where modify_name='".$name."' and is_repeat=1";
- $nameArr=array();
- $systemStudent=array();
- $numberToId=array();
- $excel_data = $this->sConn->createCommand($sql)->queryAll();
- if($excel_data){
- $topic_score=json_decode($excel_data[0]['extend'],true);
- $sex[1]='男';
- $sex[2]="女";
- $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>';
- $excel_html.='<th>身份证号</th>';
- $excel_html.='<th>性别</th>';
- $i=1;
- if(isset($topic_score['id_number'])){
- unset($topic_score['id_number']);
- }
- foreach ($topic_score as $key=>$item){
- if(isset($fileName[$key])){
- $excel_html.='<th>'.$fileName[$key].'</th>';
- }else{
- $excel_html.='<th>导入信息'.$i.'</th>';
- }
- $i++;
- }
- $excel_html.='</tr>';
- $i=1;
- foreach($excel_data as $val){
- $extend=json_decode($val['extend'],true);
- $numberToId[$i]=$val['id'];
- $excel_html.='<tr>';
- $excel_html.='<td>'.$i.'</td>';
- $excel_html.='<td>'.$val['class_name'].'</td>';
- $excel_html.='<td>'.$val['modify_name'].'(原'.$val['student_name'].')</td>';
- if(isset($extend['id_number'])){
- unset($extend['id_number']);
- }
- $excel_html.='<td><input type="text" maxlength="20" value="'.$val['id_number'].'" data="'.$val['id_number'].'" class="change_card" id="'.$val['id'].'"></td>';
- $excel_html.='<td>'.$sex[$val['sex']].'</td>';
- foreach($extend as $k => $v){
- if($k=='is_outer'){
- if($v){
- $v='否';
- }else{
- $v='是';
- }
- }
- $excel_html.='<td>'.$v.'</td>';
- }
- $excel_html.='</tr>';
- $i++;
- }
- $excel_html.='</table>';
- $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.=" where `realname` = '".$name."' and s.semester_id ='".$this->semesterId."' ";
- $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));
- }
- //导入学生执行
- public function actionConfirm_import(){
- $result['status']=0;
- $all_student=$this->sConn->createCommand("select modify_name,sex,extend,class_id,student_id,id_number,student_card from import_student_temp where is_repeat=0 and class_not_found=0 and is_normal=1")->queryAll();
- if(!$all_student){
- // Yii::app()->jump->error('没有可导入的数据! ');
- $result['msg']='没有可导入的数据!';
- exit(json_encode($result));
- }
- $grade = SGrade::model()->findAll(array('order'=>'id asc'));
- $cardGrade=array();
- $cardLengthGrade=array();
- foreach ($grade as $val){
- $cardGrade[$val->id]=$val->card_status;
- $cardLengthGrade[$val->id]=$val->card_length;
- }
- $updateBusiness = array();
- $updateStudentInfo = array();
- $updateStudentClassRelation = array();
- $insertStudentClassRelation = array();
- $school=$this->schoolManager->getSchoolInfo();
- $semesterId = $this->semesterId;
- $class_semester_data = ClassModel::model()->findAll('semester_id=:semester_id',array(':semester_id'=>$semesterId));
- $classGrade=array();
- if($class_semester_data)
- {
- foreach($class_semester_data as $v)
- {
- $class_ids[$v->class_id] = $v->class_id;
- $classGrade[$v->class_id] = $v->grade;
- }
- }
- unset($class_semester_data);
- if(!$class_ids)
- {
- //Yii::app()->jump->error('无班级信息,导入失败');
- $result['msg']='无班级信息,导入失败!';
- exit(json_encode($result));
- }
- $studentInClass=array();
- $getClassByStudent=array();
- $class_serial_number = array();
- // 获取在线学生
- $criteria = new CDbCriteria();
- $criteria->addInCondition('class_id',$class_ids);
- $criteria->addCondition('status=0');
- $criteria->addCondition('class_type=1');
- $semester_student_class_data = SStudentClassRelation::model()->findAll($criteria);
- if($semester_student_class_data)
- {
- foreach($semester_student_class_data as $v)
- {
- //在线学生ID
- $s_student_ids[(string)$v->student_id] = $v->student_id;
- //获取班级中的最大序号
- if(isset($class_serial_number[(string)$v->class_id]))
- {
- if($class_serial_number[(string)$v->class_id]<$v->serial_number)
- {
- $class_serial_number[(string)$v->class_id] = $v->serial_number;
- }
- }else
- {
- $class_serial_number[(string)$v->class_id] = $v->serial_number;
- }
- $studentInClass[(string)$v->class_id][]=(string)$v->student_id;
- $getClassByStudent[(string)$v->student_id]=(string)$v->class_id;
- }
- }
- $needCreateStudent = array();
- foreach($all_student as $val){
- $extend=array();
- if($val['extend']){
- $extend=json_decode($val['extend'],true);
- //检验扩展信息
- $preg_card='/^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/i';
- $preg_phone='/^1[34578]\d{9}$/ims';
- foreach ($extend as $key=>$item){
- if(!$item && $key!='is_outer'){
- unset($extend[$key]);
- continue;
- }
- if($key=='school_student_card'){
- // if($cardGrade[$classGrade[$val['class_id']]]==0 || $cardLengthGrade[$classGrade[$val['class_id']]]!=mb_strlen($item)){
- // unset($extend[$key]);
- // continue;
- // }
- $students=$this->schoolManager->getStudentIdBySchoolCard($item,$this->schoolId);
- if($students){
- foreach ($students as $sid){
- if(isset($s_student_ids[(string)$sid['student_id']]) && strcmp((string)$sid['student_id'],$val['student_id'])!=0){
- $result['msg']='学校准考证号('.$item.')系统中已存在,导入失败!';
- exit(json_encode($result));
- }
- }
- }
- }elseif($key=='id_number'){
- unset($extend[$key]);
- continue;
- }elseif($key=='student_phone'){
- if(!preg_match($preg_phone,$item)){
- unset($extend[$key]);
- continue;
- }
- }
- }
- }
- $val=array_merge($val,$extend);
- //处理扩展数据
- $school_student_card='';
- $zhixue_student_card='';
- $userno='';
- if(isset($val['school_student_card'])){
- $school_student_card=$val['school_student_card'];
- unset($extend['school_student_card']);
- }
- if(isset($val['zhixue_student_card'])){
- $zhixue_student_card=$val['zhixue_student_card'];
- unset($extend['zhixue_student_card']);
- }
- if(isset($val['userno'])){
- $userno=$val['userno'];
- unset($extend['userno']);
- }
- if($val['student_id']){
- //转班
- $studentInfo = $this->schoolManager->getStudentByStudentIds(array($val['student_id']));
- if(!$studentInfo){
- // Yii::app()->jump->error('数据异常! ');
- $result['msg']='数据异常,导入失败!';
- exit(json_encode($result));
- }
- $studentInfo=$studentInfo[0];
- $oldClass=isset($getClassByStudent[$val['student_id']])?$getClassByStudent[$val['student_id']]:0;
- //读取当前班级
- if(!isset($studentInClass[$val['class_id']]) || !inArray($val['student_id'],$studentInClass[$val['class_id']])){
- //班级不同,转班,补充扩展信息
- if($oldClass){
- $updateStudentClassRelation[$oldClass]['status'][$val['student_id']]=1;
- $updateStudentClassRelation[$oldClass]['operation'][$val['student_id']]=2;
- }
- if(!isset($class_serial_number[$val['class_id']])){
- $class_serial_number[$val['class_id']]=0;
- }
- $insertStudentClassRelation[$val['student_id']]="('".$val['class_id']."','".$val['student_id']."','".($class_serial_number[$val['class_id']]+1)."','".$userno."','".time()."',0)";
- $class_serial_number[$val['class_id']]++;
- $updateStudentInfo['class_id'][$val['student_id']]="'".$val['class_id']."'";
- }else{
- //验证是否已删除
- if(!isset($s_student_ids[(string)$val['student_id']])){
- if(!isset($class_serial_number[$val['class_id']])){
- $class_serial_number[$val['class_id']]=0;
- }
- $insertStudentClassRelation[$val['student_id']]="('".$val['class_id']."','".$val['student_id']."','".($class_serial_number[$val['class_id']]+1)."','".$userno."','".time()."',0)";
- $class_serial_number[$val['class_id']]++;
- $updateStudentInfo['class_id'][$val['student_id']]="'".$val['class_id']."'";
- }
- if($oldClass){
- if($userno){
- $updateStudentClassRelation[$oldClass]['userno'][$val['student_id']]=$userno;
- }
- }
- }
- if(isset($val['is_outer'])){
- $updateStudentInfo['is_outer'][$val['student_id']]="'".$val['is_outer']."'";
- }
- //更新business
- if($school_student_card || $zhixue_student_card){
- if($school_student_card){
- $updateBusiness['school_student_card'][$val['student_id']]=$school_student_card;
- }
- if($zhixue_student_card){
- $updateBusiness['zhixue_student_card'][$val['student_id']]=$zhixue_student_card;
- }
- }
- //更新student_info
- $updateStudentInfoSql=array();
- if($extend){
- foreach ($extend as $field=>$value){
- if($value){
- $updateStudentInfo[$field][$val['student_id']]="'".$value."'";
- }
- }
- }
- if($val['id_number'] && !$this->schoolManager->checkStudentIdNumber($val['id_number'])){
- $updateStudentInfo['id_number'][$val['student_id']]="'".$val['id_number']."'";
- }
- }else{
- //新学生,创建
- $needCreateStudent[]=$val;
- }
- }
- $student_sql=array();
- $student_info_sql=array();
- $class_student_sql=array();
- //创建学生
- if($needCreateStudent){
- $create_card_data = $this->createCard(count($needCreateStudent));
- $studentIdArr=getBatchUuid($this->schoolId,count($needCreateStudent));
- foreach ($needCreateStudent as $key => $val){
- $student_cart = 0;
- foreach ($create_card_data as $v) {
- if ($v['use'] == 0) {
- $student_cart = $v['student_card'];
- $create_card_data[$student_cart]['use'] = 1;
- break;
- }
- }
- //$studentId = getUUID();
- $studentId=current($studentIdArr);
- unset($studentIdArr[$studentId]);
- $student_cart = (int)$student_cart;
- $password = $student_cart;
- $school_student_card='';
- $zhixue_student_card='';
- $userno='';
- $id_number='';
- $student_phone=0;
- $field_1='';
- $field_2='';
- $field_3='';
- $field_4='';
- $field_5='';
- if(isset($val['school_student_card']) && !empty($val['school_student_card'])){
- $school_student_card=$val['school_student_card'];
- }
- if(isset($val['zhixue_student_card']) && !empty($val['zhixue_student_card'])){
- $zhixue_student_card=$val['zhixue_student_card'];
- }
- if(isset($val['userno']) && !empty($val['userno'])){
- $userno=$val['userno'];
- }
- if(isset($val['id_number']) && !empty($val['id_number']) && !$this->schoolManager->checkStudentIdNumber($val['id_number'])){
- $id_number=$val['id_number'];
- }
- if(isset($val['student_phone']) && !empty($val['student_phone'])){
- $student_phone=$val['student_phone'];
- }
- if(isset($val['field_1']) && !empty($val['field_1'])){
- $field_1=$val['field_1'];
- }
- if(isset($val['field_2']) && !empty($val['field_2'])){
- $field_2=$val['field_2'];
- }
- if(isset($val['field_3']) && !empty($val['field_3'])){
- $field_3=$val['field_3'];
- }
- if(isset($val['field_4']) && !empty($val['field_4'])){
- $field_4=$val['field_4'];
- }
- if(isset($val['field_5']) && !empty($val['field_5'])){
- $field_5=$val['field_5'];
- }
- // 将学生登录账号插入主数据
- if(!isset($class_serial_number[$val['class_id']])){
- $class_serial_number[$val['class_id']]=0;
- }
- $is_outer=0;
- if(isset($val['is_outer'])){
- $is_outer=$val['is_outer'];
- }
- $student_sql [$studentId]= "(".$studentId.",'".$student_cart."',".$student_cart.",'".$school_student_card."','".$zhixue_student_card."','".md5(sha1($password . 'wy') . 'fengche')."',".Yii::app()->session['coachInfo']['school_id'].",".time().")";
- $student_info_sql[$studentId]= "(".$studentId.",'".$val['modify_name']."',".$val['sex'].",".$this->schoolId.",".$val['class_id'].",'','','".$student_phone."','','','".$is_outer."',".time().",".time().",0,0.00,0,'".$id_number."','".$field_1."','".$field_2."','".$field_3."','".$field_4."','".$field_5."')";
- $class_student_sql[$studentId] = "(".$val['class_id'].",".$studentId.",".($class_serial_number[$val['class_id']] +$key+ 1).",'".$userno."',".time().",0)";
- }
-
- }
- //执行sql
- $transaction_conn = $this->conn->beginTransaction();
- try {
- if($student_sql){
- $sql="insert into student (`student_id`,`username`,`student_card`,`school_student_card`,`zhixue_student_card`,`password`,`school_id`,`register_time`) values ";
- $sql.=implode(',',$student_sql);
- $this->conn->createCommand($sql)->execute();
- }
- if($updateBusiness){
- $businessUpdateSql="update student set ";
- $businessUpdateSetArr=array();
- $studentId=array();
- foreach ($updateBusiness as $field =>$val){
- $businessUpdateSetStr=" `".$field."`= case student_id ";
- foreach ($val as $id=>$value){
- $businessUpdateSetStr.=" WHEN {$id} THEN '{$value}' ";
- $studentId[]=$id;
- }
- $businessUpdateSetStr.="ELSE `{$field}`";
- $businessUpdateSetStr.=" END ";
- $businessUpdateSetArr[]=$businessUpdateSetStr;
- }
- if($businessUpdateSetArr){
- $businessUpdateSql.=implode(',',$businessUpdateSetArr)." where student_id in (".implode(',',$studentId).") and school_id = '".$this->schoolId."' ";
- $this->conn->createCommand($businessUpdateSql)->execute();
- }
- }
- $businessRs=true;
- }catch (Exception $ec) {
- $transaction_conn->rollback();
- //Yii::app()->jump->error('导入失败');
- exit(json_encode($result));
- }
- if($businessRs){
- $transaction = $this->sConn->beginTransaction();
- try {
- if($updateStudentInfo){
- $studentInfoUpdateSql="update student_info set ";
- $studentInfoUpdateSetArr=array();
- $studentId=array();
- foreach ($updateStudentInfo as $field =>$val){
- $studentInfoUpdateSetStr=" `".$field."`= case student_id ";
- foreach ($val as $id=>$value){
- $studentInfoUpdateSetStr.=" WHEN {$id} THEN {$value} ";
- $studentId[]=$id;
- }
- $studentInfoUpdateSetStr.="ELSE `{$field}`";
- $studentInfoUpdateSetStr.=" END ";
- $studentInfoUpdateSetArr[]=$studentInfoUpdateSetStr;
- }
- if($studentInfoUpdateSetArr){
- $studentInfoUpdateSql.=implode(',',$studentInfoUpdateSetArr)." where student_id in (".implode(',',$studentId).") ";
- $this->sConn->createCommand($studentInfoUpdateSql)->execute();
- }
- }
- if($updateStudentClassRelation){
- foreach ($updateStudentClassRelation as $class_id =>$updateValue){
- $studentClassUpdateSql="update student_class_relation set ";
- $studentClassUpdateSetArr=array();
- foreach($updateValue as $field =>$val){
- $studentClassUpdateSetStr=" `".$field."`= case student_id ";
- foreach ($val as $id=>$value){
- $studentClassUpdateSetStr.=" WHEN {$id} THEN '{$value}' ";
- }
- $studentClassUpdateSetStr.="ELSE `{$field}`";
- $studentClassUpdateSetStr.=" END ";
- $studentClassUpdateSetArr[]=$studentClassUpdateSetStr;
- }
- if($studentClassUpdateSetArr){
- $studentClassUpdateSql.=implode(',',$studentClassUpdateSetArr)." where class_id ='".$class_id."' ";
- $this->sConn->createCommand($studentClassUpdateSql)->execute();
- }
- }
- }
- if($insertStudentClassRelation){
- $class_sql="insert into student_class_relation(`class_id`,`student_id`,`serial_number`,`userno`,`update_time`,`operation`) values";
- $class_sql.=implode(',',$insertStudentClassRelation);
- $this->sConn->createCommand($class_sql)->execute();
- }
- if($student_info_sql){
- $s_sql = 'INSERT INTO `student_info`
- (`student_id`,`realname`,`sex`,`school_id`,`class_id`,`family_tel`,`telephone`,`student_phone`,`picture`,`signature`,`is_outer`,`add_time`,`update_time`,`level`,`ave_score_rate`,`game_stars`,`id_number`,`field_1`,`field_2`,`field_3`,`field_4`,`field_5`)VALUES';
- $s_sql.=implode(',',$student_info_sql);
- $this->sConn->createCommand($s_sql)->execute();
- }
- if($class_student_sql){
- $class_sql="insert into student_class_relation(`class_id`,`student_id`,`serial_number`,`userno`,`update_time`,`operation`) values ";
- $class_sql.=implode(',',$class_student_sql);
- $this->sConn->createCommand($class_sql)->execute();
- }
- //$delSql="truncate table import_student_temp;";
- $delSql="delete from import_student_temp;";
- $this->sConn->createCommand($delSql)->execute();
- $transaction_conn->commit();
- $transaction->commit();
- 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:j')
- )));
- }
- $result['status']=1;
- }catch (Exception $e) {
- $transaction->rollback();
- $transaction_conn->rollback();
- //Yii::app()->jump->error('导入失败');
- exit(json_encode($result));
- }
- }
- unset($transaction);
- unset($transaction_conn);
- // 导入成功
- //$this->redirect(Yii::app()->createUrl('importstudent/index'));
- exit(json_encode($result));
- }
- //预生成系统准考证号
- private function createCard($num)
- {
- $cards = array();
- $student_cart = 0;
- if(!$num)
- {
- return $cards;
- }
- /*
- $b_student_data = BusinessStudent::model()->find(array(
- 'select' => 'student_card',
- 'order' => 'student_card desc',
- 'condition' => 'school_id=:school_id',
- 'limit' => 1,
- 'params' => array(':school_id'=>$this->schoolId)
- ));
- if($b_student_data)
- {
- if(!$b_student_data->student_card)
- {
- if($this->schoolId<100)
- {
- $student_cart = '9'.$this->schoolId.'00100';
- }else
- {
- $student_cart = $this->schoolId.'00100';
- }
- }else
- {
- $student_cart = $b_student_data->student_card;
- }
- }else
- {
- if($this->schoolId<100)
- {
- $student_cart = '9'.$this->schoolId.'00100';
- }else
- {
- $student_cart = $this->schoolId.'00100';
- }
- }
- */
- $b_student_data=$this->conn->createCommand("SELECT student_card FROM (SELECT student_card FROM `student` `t` WHERE school_id='".$this->schoolId."') sc ORDER BY student_card DESC LIMIT 1;")->queryRow();
- if($b_student_data)
- {
- if(!$b_student_data['student_card'])
- {
- if($this->schoolId<100)
- {
- $student_cart = '9'.$this->schoolId.'00100';
- }else
- {
- $student_cart = $this->schoolId.'00100';
- }
- }else
- {
- $student_cart = $b_student_data['student_card'];
- }
- }else
- {
- if($this->schoolId<100)
- {
- $student_cart = '9'.$this->schoolId.'00100';
- }else
- {
- $student_cart = $this->schoolId.'00100';
- }
- }
- unset($b_student_data);
- for($i=1;$i<=$num;$i++)
- {
- $cards[$student_cart+$i] = array(
- 'student_card'=>$student_cart+$i,
- 'use'=>0,
- 'order'=>$i
- );
- }
- return $cards;
- }
- //重名处理后检查
- public function actionRepeat_check(){
- $str=Req::post('str');
- $name=Req::post('name');
- $result['status']=0;
- $studentIds=array();
- $tempIds=array();
- if($str){
- 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];
- }
- }
- $nToId=null;
- }
- $updateSql=array();
- foreach($str as $val){
- @$nToId=explode('///',$val);
- if(isset($nToId[0]) && isset($nToId[1])){
- //判断学生id是否已关联过
- $related=$this->sConn->createCommand("select modify_name from import_student_temp where student_id='".$nToId[0]."' limit 1")->queryRow();
- if($related){
- $result['msg']='学生已经被关联,请重新检查:'.$related['modify_name'];
- exit(json_encode($result));
- }
- $updateSql[]="update import_student_temp set student_id='".$nToId[0]."',is_repeat=0,is_normal=1 where id='".$nToId[1]."'";
- }
- }
- if($updateSql){
- $transaction = $this->sConn->beginTransaction();
- try {
- foreach ($updateSql as $query) {
- $this->sConn->createCommand($query)->execute();
- }
- $transaction->commit();
- }catch (Exception $e) {
- $transaction->rollback();
- $result['msg']='关联失败';
- exit(json_encode($result));
- }
- }
- }
- unset($transaction);
- $updateIdNumberSql=array();
- $sql="select id,id_number from import_student_temp where modify_name='".$name."' and is_repeat=1";
- $excel_data = $this->sConn->createCommand($sql)->queryAll();
- if($excel_data){
- foreach ($excel_data as $val){
- if($val['id_number']){
- $updateIdNumberSql[]="update import_student_temp set is_repeat=0,is_normal=1 where id='".$val['id']."'";
- }
- }
- }
- if($updateIdNumberSql){
- $transaction = $this->sConn->beginTransaction();
- try {
- foreach($updateIdNumberSql as $query){
- $this->sConn->createCommand($query)->execute();
- }
- $transaction->commit();
- }catch (Exception $e) {
- $transaction->rollback();
- $result['msg']='关联失败';
- exit(json_encode($result));
- }
- }
- $result['status']=1;
- exit(json_encode($result));
- }
- //正常数据列表
- public function actionNormal(){
- $condition = array();
- $class_id = safe_replace(Yii::app()->request->getQuery('classId'));
- $realname = safe_replace(Yii::app()->request->getQuery('realname'));
- $grade = safe_replace(Yii::app()->request->getQuery('grade'));
- if($class_id){
- $condition[]=" class_id='".$class_id."'";
- }
- if($realname){
- $condition[]=" modify_name like '%".$realname."%'";
- }
- $condition[]="is_normal=1";
- $rs=$this->schoolManager->getNormalStudent($condition,20);
- $fileName=array(
- 'userno'=>'学号',
- 'school_student_card'=>'学校准考证号',
- 'zhixue_student_card'=>'智学网准考证号',
- 'id_number'=>'身份证号',
- 'student_phone'=>'手机号',
- 'is_outer'=>'在籍生'
- );
- //扩展字段
- $studentExtend=$this->schoolManager->getStudentExtend();
- if($studentExtend){
- foreach ($studentExtend as $key=> $value){
- $fileName[$key]=$value['field_mean'];
- }
- }
- $data['pages'] = $rs['pager'];
- $data['page_total'] = $rs['pager']->rowsCount;
- $data['list']=$rs['rs'];
- $data['class_id']=$class_id;
- $data['grade']=$grade;
- $data['realname']=$realname;
- $extendTh='';
- if($data['list']){
- foreach ($data['list'] as $key=>$val){
- $extendTd='';
- $json=json_decode($val['extend'],true);
- unset($json['id_number']);
- if(!$extendTh){
- foreach ($json as $k=>$v){
- $extendTh.='<th>'.$fileName[$k].'</th>';
- }
- }
- foreach ($json as $k=>$v){
- if($k=='is_outer'){
- if($v){
- $v='否';
- }else{
- $v='是';
- }
- }
- $extendTd.='<td>'.$v.'</td>';
- }
- $data['list'][$key]['ext']=$extendTd;
- }
- }
- $data['extTh']=$extendTh;
- $this->render('normal',$data);
- }
- //根据班级读取学生
- public function actionLoadStudentByClassName(){
- $realname = safe_replace(Req::post('classname'));
- $result['status']=0;
- if(!$realname){
- exit(json_encode($result));
- }
- $fileName=array(
- 'userno'=>'学号',
- 'school_student_card'=>'学校准考证号',
- 'zhixue_student_card'=>'智学网准考证号',
- 'id_number'=>'身份证号',
- 'student_phone'=>'手机号',
- 'is_outer'=>'在籍生'
- );
- //扩展字段
- $studentExtend=$this->schoolManager->getStudentExtend();
- if($studentExtend){
- foreach ($studentExtend as $key=> $value){
- $fileName[$key]=$value['field_mean'];
- }
- }
- $sex[1]='男';
- $sex[2]='女';
- $all_student=$this->sConn->createCommand("select student_name,modify_name,sex,extend,class_id,student_id,id_number from import_student_temp where class_name='".$realname."' and class_not_found=1")->queryAll();
- $extendTh='';
- $html='<tr>';
- $html.="<td>姓名</td>";
- $html.="<td>性别</td>";
- $html.="<td>身份证</td>";
- if($all_student){
- if($all_student){
- foreach ($all_student as $key=>$val){
- $extendTd='<tr>';
- $extendTd.="<td>{$val['modify_name']}(原{$val['student_name']})</td>";
- $extendTd.="<td>{$sex[$val['sex']]}</td>";
- $extendTd.="<td>{$val['id_number']}</td>";
- $json=json_decode($val['extend'],true);
- unset($json['id_number']);
- if(!$extendTh){
- foreach ($json as $k=>$v){
- $extendTh.='<td>'.$fileName[$k].'</td>';
- }
- $html.=$extendTh.'</tr>';
- }
- foreach ($json as $k=>$v){
- $extendTd.='<td>'.$v.'</td>';
- }
- $extendTd.="</tr>";
- $html.=$extendTd;
- }
- $html.="";
- }
- }
- $result['html']=$html;
- $result['status']=1;
- exit(json_encode($result));
- }
- private function getInClassStudents($class_ids)
- {
- $data = array();
- $student_ids = array();
- $student_names = array();
- $student_cards = array();
- $school_student_cards = array();
- $userno = array();
- $serial_number = array();
- $student_class_ids = array();
- $student_info = array();
- $class_student = array();
- $criteria = new CDbCriteria();
- $criteria->addInCondition('class_id',$class_ids);
- $criteria->addCondition('status=:status');
- $criteria->params[':status'] = 0;
- $criteria->order = 'serial_number desc,class_id desc';
- $student_class_data = SStudentClassRelation::model()->findAll($criteria);
- if($student_class_data)
- {
- foreach($student_class_data as $key=>$v)
- {
- if(isset($serial_number[$v->class_id]))
- {
- if($serial_number[$v->class_id]<$v->serial_number)
- {
- $serial_number[$v->class_id] = $v->serial_number;
- }
- }else
- {
- $serial_number[$v->class_id] = $v->serial_number;
- }
- $student_ids[$v->student_id] = $v->student_id;
- $userno[$v->student_id] = $v->userno;
- $class_student[$v->student_id] = $v;
- $student_class_ids[$v->student_id] = $v->class_id;
- }
- $criteria = new CDbCriteria();
- $criteria->addInCondition('student_id',$student_ids);
- $student_data = SStudentInfo::model()->findAll($criteria);
- if($student_data)
- {
- foreach($student_data as $v)
- {
- $student_names[$v->student_id] = $v->realname;
- $student_info[$v->student_id] = $v;
- }
- }
- unset($student_data);
- unset($criteria);
- $criteria = new CDbCriteria();
- $criteria->addInCondition('student_id',$student_ids);
- $b_student_data = BusinessStudent::model()->findAll($criteria);
- if($b_student_data)
- {
- foreach($b_student_data as $v)
- {
- $student_cards[$v->student_id] = $v->student_card;
- if($v->school_student_card)
- {
- $school_student_cards[$v->student_id] = $v->school_student_card;
- }
- }
- }
- unset($b_student_data);
- $data['student_names'] = $student_names;
- $data['student_cards'] = $student_cards;
- $data['student_ids'] = $student_ids;
- $data['school_student_cards'] = $school_student_cards;
- $data['student_userno'] = $userno;
- $data['student_info'] = $student_info;
- $data['class_student'] = $class_student;
- $data['student_class_ids'] = $student_class_ids;
- $data['serial_number'] = $serial_number;
- }
- return $data;
- }
- //教学班导入学生
- public function actionImportStudentClassified(){
- $this->sConn->createCommand("DELETE FROM `import_student_temp` where import_type=1 ")->execute();
- $student_all_data = $this->sConn->createCommand("SELECT id FROM `import_student_temp` limit 1 ")->queryRow();
- if($student_all_data){
- $this->render('check_classified');
- }else{
- //读取科目设置
- $subjects=array();
- $rs=$this->schoolManager->getSubjectByGrade(0,0,$this->semesterId);
- if($rs){
- foreach ($rs as $val){
- $subjects[$val['subject_id']]=Yii::app()->params['subjectId'][$val['subject_id']];
- }
- }
- $data['subjects']=$subjects;
- $this->render('import_classified',$data);
- }
- }
- public function actionImportClassified(){
- ini_set ('memory_limit', '300M');
- if(!$_FILES){
- Yii::app()->jump->error('文件大小超过范围');
- }else {
- if (!isset($_FILES['student_file']) || !isset($_FILES['student_file']['size']) || $_FILES['student_file']['size'] > 5242880) {
- Yii::app()->jump->error('文件大小超过范围');
- }
- }
- $subjectId=Req::post('subject');
- if (Yii::app()->request->getIsPostRequest()) {
- $uploader = new Uploader("upload/tmpDir/UploadClassesStudentsList/{$this->schoolId}/");
- $uploader->allowTypes = array("xls","xlsx");
- $uploader->fieldsMappings = array("exname" => array(0 => $this->schoolId));
- $file = $uploader->act();
- $file = Arr::current(Arr::current($file));
- if (!$file || !isset($file["error"]))
- Yii::app()->jump->error('请上传的Excel!');
- if ($file["error"] != 0) {
- switch ($file["error"]) {
- case 2001:
- Yii::app()->jump->error('文件类型不符');
- break;
- case 2002:
- Yii::app()->jump->error('文件大小超出允许范围');
- break;
- default:
- Yii::app()->jump->error('上传失败');
- break;
- }
- }
- $inputFileName = $file["src"];
- if(Yii::app()->params['handle_log_on_off'])
- {
- writeFileLog(jsonEncode(array(
- "exam_group_id" => 0,
- "operate_project" => 'zsyas2',
- "school_id" => $this->schoolId,
- "title" => '导入教学班学生excel',
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $this->getRoute(),
- "operate_sql" =>'',
- "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET,'file'=>$inputFileName)),
- "date"=>date('Y-m-d H:i:j')
- )));
- }
- // 导入PHPExcel类
- Yii::import('application.extensions.*');
- require_once('phpexcel/PHPExcel/IOFactory.php');
- try{
- $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
- $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
- //FIXME 2019-12-23
- @unlink($file["src"]);
- }catch (Exception $e){
- //FIXME 2019-12-23
- @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('请输入学生数据');
- }
- //获取当前学期的所有班级
- $semesterId = $this->semesterId;
- $class_semester_data = ClassModel::model()->findAll('semester_id=:semester_id and class_type=2',array(':semester_id'=>$semesterId));
- if($class_semester_data)
- {
- foreach($class_semester_data as $v)
- {
- $class_ids[$v->class_id] = $v->class_id;
- $c_class_names[$v->class_id] = (string)$v->class_name;
- }
- }
- unset($class_semester_data);
- if(!$class_ids)
- {
- Yii::app()->jump->error('当前学期无班级信息,导入失败');
- }
- $insertValue="insert into import_student_temp(`student_name`,`class_name`,`student_card`,`import_type`,`subject_id`) values ";
- $values=array();
- $studentCard=array();
- foreach ($sheetData as $val){
- if(!$val['A'] || !$val['B'] ){
- //Yii::app()->jump->error('班级,姓名,性别不能为空');
- continue;
- }
- if($val['C']){
- $studentCard[$val['C']][]=$val['C'];
- }
- $values[]="('".$val['B']."','".$val['A']."','".$val['C']."',2,'".$subjectId."')";
- }
- //检测系统准考证号是否重复
- $errorStudentCard=array();
- if($studentCard){
- foreach ($studentCard as $item){
- if(count($item)>1){
- $errorStudentCard[]=$item[0];
- }
- }
- }
- if($errorStudentCard){
- if(count($errorStudentCard)>3){
- Yii::app()->jump->error('系统准考证号重复: '.implode(',',array_slice($errorStudentCard,0,3)).' ...... ');
- }else{
- Yii::app()->jump->error('系统准考证号重复: '.implode(',',$errorStudentCard));
- }
- }
- if($values){
- $sql=$insertValue.implode(',',$values);
- $transaction = $this->sConn->beginTransaction();
- try{
- $this->sConn->createCommand($sql)->execute();
- $transaction->commit();
- // Yii::app()->jump->error('Excel导入成功!');
- //跳转检测页
- $this->redirect($this->createUrl('importstudent/checkClassified'));
- }catch(Exception $e){
- $transaction->rollBack();
- Yii::app()->jump->error('Excel导入失败!');
- }
- }else{
- Yii::app()->jump->error('Excel导入失败!');
- }
- }
- }
- public function actionCheckClassified(){
- $this->render('check_classified');
- }
- //检测姓名
- public function actionCheck_student_name_classified(){
- ini_set('memory_limit','512M');
- set_time_limit(0);
- $result['status']=0;
- $result['data']=0;
- $id_number=array();
- $clearIdNumber=array(); //需要清除身份证
- $studentCard=array();
- $student_all_data = $this->sConn->createCommand("SELECT id,student_name,id_number FROM `import_student_temp` `t` ")->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_student_temp set `modify_name`= case id ';
- foreach ($item as $key=> $val){
- $sql.=" WHEN ".$key." THEN '".$val."' ";
- }
- $sql.=" End ";
- $sql.=" where modify_name='' or modify_name is null";
- $this->sConn->createCommand($sql)->execute();
- }
- $transcation->commit();
- $result['status']=1;
- }catch (Exception $e){
- $transcation->rollback();
- }
- }
- $result['count']=$count;
- }
- exit(json_encode($result));
- }
- //匹配学生信息
- public function actionMatchingClassified(){
- $classNotFound=array(); //班级名称不一致
- $repeat=array(); //重名
- $success=array(); //正常
- $updateClassValue=array(); //需要更新的班级不存在数据
- $updateRepeatValue=array(); //需要更新重复数据
- $studentName=array();
- $studentCardValue=array(); //准考证号不存在
- $updateStudentCard=array();
- $idNumber=array();
- $updateStudentId=array(); //匹配成功需要更新student_id数据
- $updateClassId=array(); //更新班级id
- $result['status']=0;
- $student_all_data = $this->sConn->createCommand("SELECT id,student_name,class_name,modify_name,student_id,is_repeat,class_not_found,is_normal,id_number,student_card,subject_id FROM `import_student_temp` `t` ")->queryAll();
- if(!$student_all_data){
- $result['msg']='请先导入excel数据';
- exit(json_encode($result));
- }
- $nowSemester=$this->semesterId;
- foreach ($student_all_data as $key=>$val){
- if($val['is_repeat']==1){
- $repeat[]=$val['id'];
- unset($student_all_data[$key]);
- }
- if($val['class_not_found']==1){
- $classNotFound[$val['class_name']][]=$val;
- unset($student_all_data[$key]);
- }
- if($val['class_not_found']==2){
- $studentCardValue[]=$val['id'];
- unset($student_all_data[$key]);
- }
- if($val['is_normal']==1){
- $success[]=1;
- unset($student_all_data[$key]);
- }
- }
- if(!$student_all_data){
- $result['studentCard']=count($studentCardValue);
- $result['repeat']=count($repeat);
- $result['success']=count($success);
- $result['noExistent']=count($classNotFound);
- $result['status']=1;
- exit(json_encode($result));
- }
- //判断班级是否存在
- foreach($student_all_data as $val){
- $class_id=$this->schoolManager->classNameExists($val['class_name'],$nowSemester,2);
- if(!$class_id){
- $classNotFound[$val['class_name']][]=$val;
- $updateClassValue[]="'".$val['class_name']."'"; //班级不存在
- }else{
- //校验科目是否匹配
- $targetSubjects=$this->schoolManager->getSubjectByClass($class_id,'Arr');
- if(!in_array($val['subject_id'],$targetSubjects)){
- $classNotFound[$val['class_name']][]=$val;
- $updateClassValue[]="'".$val['class_name']."'"; //班级不存在
- continue;
- }
- $isFoundCard=false;
- //判断准考证号
- if($val['student_card']){
- $sql="select student_id from student where student_card ='".$val['student_card']."' and status=0 and school_id='".$this->schoolId."'";
- $b_student=$this->conn->createCommand($sql)->queryRow();
- if($b_student){
- //验证是否有行政班数据
- $checkXZB=$this->sConn->createCommand("select student_id from student_class_relation where student_id='".$b_student['student_id']."' and class_type=1 and status=0")->queryRow();
- if($checkXZB){
- //验证是否有教学班数据,有则转班
- $classifiedSql="SELECT c.class_id,c.class_name,subject_id,scr.student_id FROM `class_subject_relation` csr ";
- $classifiedSql.="join class c on csr.class_id=c.class_id ";
- $classifiedSql.="join student_class_relation scr on scr.class_id=c.class_id ";
- $classifiedSql.="where subject_id=".$val['subject_id']." and c.class_type=2 and student_id='".$b_student['student_id']."';";
- $studentClassified=$this->sConn->createCommand($classifiedSql)->queryRow();
- if($studentClassified){
- $updateStudentCard[]="update import_student_temp set class_id='".$class_id."',student_id='".$b_student['student_id']."',is_normal=2 where student_card='".$val['student_card']."'";
- }else{
- $updateStudentCard[]="update import_student_temp set class_id='".$class_id."',student_id='".$b_student['student_id']."',is_normal=1 where student_card='".$val['student_card']."'";
- }
- $success[]=$val['id'];
- $isFoundCard=true;
- }
- }
- }
- if(!$isFoundCard){
- //用学生姓名匹配
- $getAllStudentName = $this->schoolManager->getStudentByNameClass($val['modify_name'],$nowSemester);
- if(count($getAllStudentName)!=1){
- $repeat[]=$val['id'];
- }else{
- //判断教学班
- $subjectRepeat=false;
- $classifiedStudent=$this->schoolManager->getStudentByNameClassified($val['modify_name'],$nowSemester);
- if($classifiedStudent){
- //判断学科
- foreach ($classifiedStudent as $item){
- $subjects=$this->schoolManager->getSubjectByClass($item['class_id'],'Arr');
- if($subjects && in_array($val['subject_id'],$subjects)){ //已有教学班科目
- $subjectRepeat=true;
- $updateStudentCard[]="update import_student_temp set class_id='".$class_id."',student_id='".$item['student_id']."',is_normal=2 where modify_name='".$val['modify_name']."'";
- break;
- }
- }
- }
- if(!$subjectRepeat){
- $updateStudentCard[]="update import_student_temp set class_id='".$class_id."',student_id='".$getAllStudentName[0]['student_id']."',is_normal=1 where modify_name='".$val['modify_name']."'";
- }
- $success[]=$val['id'];
- }
- }
- }
- }
- //更新检测成功的数据
- if( $updateClassValue || $success || $updateStudentCard || $repeat){
- $transcation = $this->sConn->beginTransaction();
- try {
- if($updateClassValue){
- $updateClassValue=array_values($updateClassValue);
- $this->sConn->createCommand("update import_student_temp set class_not_found=1 where class_name in(".implode(',',$updateClassValue).")")->execute();
- }
- if($updateStudentCard){
- foreach ($updateStudentCard as $query){
- $this->sConn->createCommand($query)->execute();
- }
- }
- if($repeat){
- $this->sConn->createCommand("update import_student_temp set is_repeat=1 where id in(".implode(',',$repeat).")")->execute();
- }
- if($success){
- $success=array_values($success);
- $this->sConn->createCommand("update import_student_temp set is_normal=1 where id in(".implode(',',$success).")")->execute();
- }
- $transcation->commit();
- $result['status']=1;
- }catch (Exception $e){
- $result['status']=0;
- $transcation->rollback();
- }
- }
- $result['studentCard']=count($studentCardValue);
- $result['repeat']=count($repeat);
- $result['success']=count($success);
- $result['noExistent']=count($classNotFound);
- $result['status']=1;
- exit(json_encode($result));
- }
- //班级名称不匹配
- public function actionHandle_classified_existent(){
- $notFound=$this->sConn->createCommand("select id,class_name from import_student_temp where class_not_found=1")->queryAll();
- if(!$notFound) $this->redirect($this->createUrl('importstudent/checkClassified'));
- $className=array();
- foreach ($notFound as $val){
- $className[$val['class_name']][]=$val;
- }
- $data['className']=$className;
- $this->render('handle_classified_existent',$data);
- }
- //修改教学班级名称
- public function actionChange_classified_value(){
- $old_class_name=Req::post('data');
- $value=Req::post('value');
- $result['status']=0;
- if(!$old_class_name || !$value){
- $result['msg']='参数不正确';
- exit(json_encode($result));
- }
- $valueArr=array();
- $sql="select id,modify_name,student_name,sex,extend,student_id,student_card,subject_id from import_student_temp where class_name='".$old_class_name."' ";
- $data=$this->sConn->createCommand($sql)->queryAll();
- if(!$data){
- $result['msg']='数据异常';
- exit(json_encode($result));
- }
- $nowSemester=$this->semesterId;
- $class_id=$this->schoolManager->classNameExists($value,$nowSemester,2);
- if(!$class_id){
- $result['status']=0;
- $result['msg']='班级在系统中不存在';
- exit(json_encode($result));
- }else{
- //校验科目是否匹配
- $targetSubjects=$this->schoolManager->getSubjectByClass($class_id,'Arr');
- foreach ($data as $key => $val){
- if(!in_array($val['subject_id'],$targetSubjects)){
- $result['status']=0;
- $result['msg']='班级和选择的学科不匹配';
- exit(json_encode($result));
- }
- $isFoundCard=false;
- //判断准考证号
- if($val['student_card']){
- $sql="select student_id from student where student_card ='".$val['student_card']."' and status=0 and school_id='".$this->schoolId."'";
- $b_student=$this->conn->createCommand($sql)->queryRow();
- if($b_student){
- //验证是否有教学班数据,有则转班
- $classifiedSql="SELECT c.class_id,c.class_name,subject_id,scr.student_id FROM `class_subject_relation` csr ";
- $classifiedSql.="join class c on csr.class_id=c.class_id ";
- $classifiedSql.="join student_class_relation scr on scr.class_id=c.class_id ";
- $classifiedSql.="where subject_id=".$val['subject_id']." and c.class_type=2 and student_id='".$b_student['student_id']."';";
- $studentClassified=$this->sConn->createCommand($classifiedSql)->queryRow();
- if($studentClassified){
- $valueArr[]="('".$val['student_name']."','".$value."','1','".$val['modify_name']."','".$val['extend']."','".$b_student['student_id']."','".$class_id."','".$val['student_card']."',0,0,1)";
- }else{
- $valueArr[]="('".$val['student_name']."','".$value."','1','".$val['modify_name']."','".$val['extend']."','".$b_student['student_id']."','".$class_id."','".$val['student_card']."',0,0,1)";
- }
- $isFoundCard=true;
- }
- }
- if(!$isFoundCard){
- //用学生姓名匹配
- $getAllStudentName = $this->schoolManager->getStudentByNameClass($val['modify_name'],$nowSemester);
- if(count($getAllStudentName)!=1){
- $valueArr[]="('".$val['student_name']."','".$value."','1','".$val['modify_name']."','".$val['extend']."','','".$class_id."','".$val['student_card']."',1,0,0)";
- }else{
- //判断教学班
- $subjectRepeat=false;
- $classifiedStudent=$this->schoolManager->getStudentByNameClassified($val['modify_name'],$nowSemester);
- if($classifiedStudent){
- //判断学科
- foreach ($classifiedStudent as $item){
- $subjects=$this->schoolManager->getSubjectByClass($item['class_id']);
- if($subjects && in_array($val['subject_id'],$subjects)){ //已有教学班科目
- $subjectRepeat=true;
- $valueArr[]="('".$val['student_name']."','".$value."','1','".$val['modify_name']."','".$val['extend']."','".$item['student_id']."','".$class_id."','".$val['student_card']."',0,0,1)";
- break;
- }
- }
- }
- if(!$subjectRepeat){
- $valueArr[]="('".$val['student_name']."','".$value."','1','".$val['modify_name']."','".$val['extend']."','".$getAllStudentName[0]['student_id']."','".$class_id."','".$val['student_card']."',0,0,1)";
- }
- }
- }
- }
- $transcation = $this->sConn->beginTransaction();
- try {
- if($valueArr) {
- $insert="insert into import_student_temp(`student_name`,`class_name`,`sex`,`modify_name`,`extend`,`student_id`,`class_id`,`student_card`,`is_repeat`,`class_not_found`,`is_normal`) values ";
- $this->sConn->createCommand("delete from import_student_temp where class_name='".$old_class_name."'")->execute();
- $this->sConn->createCommand($insert.implode(',',$valueArr))->execute();
- }
- $transcation->commit();
- $result['status']=1;
- }catch (Exception $e){
- $result['status']=0;
- $transcation->rollback();
- }
- exit(json_encode($result));
- }
- }
- //修改准考证号码
- public function actionChangeClassifiedStudentCard(){
- $id=Req::post('id');
- $value=Req::post('value');
- $result['status']=0;
- if(!$id || !$value){
- $result['msg']='参数不正确';
- exit(json_encode($result));
- }
- $excel_data=$this->sConn->createCommand("select student_name,subject_id from import_student_temp where id='".$id."'")->queryRow();
- if(!$excel_data){
- $result['msg']='参数不正确';
- exit(json_encode($result));
- }
- //判断表格中是否存在
- $sql="select id,student_name from import_student_temp where student_card='".$value."' and id!='".$id."' ";
- $data=$this->sConn->createCommand($sql)->queryRow();
- if($data){
- $result['msg']='导入的数据中中已存在相同准考证'.$data['student_name'].',请检查后重新确认';
- exit(json_encode($result));
- }
- //验证系统中是否存在
- $sql="select student_id from student where student_card ='".$value."' and status=0 and school_id='".$this->schoolId."'";
- $b_student=$this->conn->createCommand($sql)->queryRow();
- if(!$b_student){
- $result['msg']='准考证号不存在,请检查后重新确认';
- exit(json_encode($result));
- }else{
- //判断姓名
- $student_card_name=$this->sConn->createCommand("select realname from student_info where student_id='".$b_student['student_id']."'")->queryRow();
- if(!$student_card_name){
- $result['msg']='准考证号不存在,请检查后重新确认';
- exit(json_encode($result));
- }elseif($student_card_name['realname']!=$excel_data['student_name']){
- $result['msg']='新的准考证号与表格姓名不匹配,请检查后重新确认';
- exit(json_encode($result));
- }else{
- //验证是否有教学班数据,有则转班
- $classifiedSql="SELECT c.class_id,c.class_name,subject_id,scr.student_id FROM `class_subject_relation` csr ";
- $classifiedSql.="join class c on csr.class_id=c.class_id ";
- $classifiedSql.="join student_class_relation scr on scr.class_id=c.class_id ";
- $classifiedSql.="where subject_id=".$excel_data['subject_id']." and c.class_type=2 and student_id='".$b_student['student_id']."';";
- $studentClassified=$this->sConn->createCommand($classifiedSql)->queryRow();
- if($studentClassified){
- if($this->sConn->createCommand("update import_student_temp set student_card='".$value."',is_normal=2,is_repeat=0,class_not_found=0,student_id='".$b_student['student_id']."' where id='".$id."'")->execute()){
- $result['status']=1;
- }
- }else{
- if($this->sConn->createCommand("update import_student_temp set student_card='".$value."',is_normal=1,is_repeat=0,class_not_found=0,student_id='".$b_student['student_id']."' where id='".$id."'")->execute()){
- $result['status']=1;
- }
- }
- }
- }
- exit(json_encode($result));
- }
- //正常数据列表
- public function actionNormalClassified(){
- $condition = array();
- $class_id = safe_replace(Yii::app()->request->getQuery('classId'));
- $realname = safe_replace(Yii::app()->request->getQuery('realname'));
- $grade = safe_replace(Yii::app()->request->getQuery('grade'));
- if($class_id){
- $condition[]=" class_id='".$class_id."'";
- }
- if($realname){
- $condition[]=" modify_name like '%".$realname."%'";
- }
- $condition[]="is_normal!=0";
- $rs=$this->schoolManager->getNormalStudent($condition,20);
- $data['pages'] = $rs['pager'];
- $data['page_total'] = $rs['pager']->rowsCount;
- $data['list']=$rs['rs'];
- $data['class_id']=$class_id;
- $data['grade']=$grade;
- $data['realname']=$realname;
- $this->render('normal_classified',$data);
- }
- //根据年级读取教学班
- public function actionGetClassifiedByGrade(){
- $grade=Req::post('grade');
- $semester=$this->semesterId;
- $class=ClassModel::model()->getClassBySemesternianji($semester,$grade,2);
- $result=array(
- 'status'=>1
- );
- $data=array();
- if($class){
- foreach($class as $val){
- $data[]=array(
- 'class_id'=>$val->class_id,
- 'class_name'=>$val->class_name,
- );
- }
- }
- $result['data']=$data;
- exit(json_encode($result));
- }
- //匹配失败
- public function actionHandleClassifiedCard(){
- $notFound=$this->sConn->createCommand("select id,student_name,modify_name,class_name,student_card from import_student_temp where is_repeat=1")->queryAll();
- if(!$notFound) $this->redirect($this->createUrl('importstudent/checkClassified'));
- $data['student']=$notFound;
- $this->render('handle_classified_card',$data);
- }
- //导入学生执行
- public function actionConfirm_classified_import(){
- $result['status']=0;
- $all_student=$this->sConn->createCommand("select modify_name,sex,extend,class_id,student_id,id_number,student_card,subject_id,is_normal from import_student_temp where is_repeat=0 and class_not_found=0 and is_normal<>0")->queryAll();
- if(!$all_student){
- $result['msg']='没有可导入的数据!';
- exit(json_encode($result));
- }
- $updateStudentClassRelation = array();
- $insertStudentClassRelation = array();
- $semesterId = $this->semesterId;
- $class_semester_data = ClassModel::model()->findAll('semester_id=:semester_id and class_type=2',array(':semester_id'=>$semesterId));
- $classGrade=array();
- if($class_semester_data)
- {
- foreach($class_semester_data as $v)
- {
- $class_ids[$v->class_id] = $v->class_id;
- $classGrade[$v->class_id] = $v->grade;
- }
- }
- unset($class_semester_data);
- if(!$class_ids)
- {
- //Yii::app()->jump->error('无班级信息,导入失败');
- $result['msg']='无班级信息,导入失败!';
- exit(json_encode($result));
- }
- $class_serial_number = array();
- // 获取在线学生
- $criteria = new CDbCriteria();
- $criteria->addInCondition('class_id',$class_ids);
- $criteria->addCondition('status=0');
- $semester_student_class_data = SStudentClassRelation::model()->findAll($criteria);
- if($semester_student_class_data)
- {
- foreach($semester_student_class_data as $v)
- {
- //获取班级中的最大序号
- if(isset($class_serial_number[(string)$v->class_id]))
- {
- if($class_serial_number[(string)$v->class_id]<$v->serial_number)
- {
- $class_serial_number[(string)$v->class_id] = $v->serial_number;
- }
- }else
- {
- $class_serial_number[(string)$v->class_id] = $v->serial_number;
- }
- }
- }
- foreach($all_student as $val){
- if($val['student_id']){
- //转班
- $studentInfo = $this->schoolManager->getStudentByStudentIds(array($val['student_id']));
- if(!$studentInfo){
- $result['msg']='数据异常,导入失败!';
- exit(json_encode($result));
- }
- //查询目标班是否已存在
- $checkRepeat=$this->sConn->createCommand("select student_id,status from student_class_relation where class_id='".$val['class_id']."' and student_id='".$val['student_id']."'")->queryRow();
- if($checkRepeat){
- if($checkRepeat['status']==0){
- continue;
- }
- }
- if(!isset($class_serial_number[$val['class_id']])){
- $class_serial_number[$val['class_id']]=0;
- }
- $insertStudentClassRelation[$val['student_id']]="('".$val['class_id']."','".$val['student_id']."','".($class_serial_number[$val['class_id']]+1)."','0','".time()."',0,2)";
- //删除相同科目其它教学班数据
- $classifiedSql="SELECT c.class_id,c.class_name,subject_id,scr.student_id FROM `class_subject_relation` csr ";
- $classifiedSql.="join class c on csr.class_id=c.class_id ";
- $classifiedSql.="join student_class_relation scr on scr.class_id=c.class_id ";
- $classifiedSql.="where subject_id=".$val['subject_id']." and c.class_type=2 and student_id='".$val['student_id']."';";
- $studentClassified=$this->sConn->createCommand($classifiedSql)->queryRow();
- if($studentClassified){
- $updateStudentClassRelation[$studentClassified['class_id']]['status'][$val['student_id']]=1;
- $updateStudentClassRelation[$studentClassified['class_id']]['operation'][$val['student_id']]=2;
- }
- $class_serial_number[$val['class_id']]++;
- }
- }
- //执行sql
- $transaction = $this->sConn->beginTransaction();
- try {
- if($updateStudentClassRelation){
- foreach ($updateStudentClassRelation as $class_id =>$updateValue){
- $studentClassUpdateSql="update student_class_relation set ";
- $studentClassUpdateSetArr=array();
- foreach($updateValue as $field =>$val){
- $studentClassUpdateSetStr=" `".$field."`= case student_id ";
- foreach ($val as $id=>$value){
- $studentClassUpdateSetStr.=" WHEN {$id} THEN '{$value}' ";
- }
- $studentClassUpdateSetStr.="ELSE `{$field}`";
- $studentClassUpdateSetStr.=" END ";
- $studentClassUpdateSetArr[]=$studentClassUpdateSetStr;
- }
- if($studentClassUpdateSetArr){
- $studentClassUpdateSql.=implode(',',$studentClassUpdateSetArr)." where class_id ='".$class_id."' ";
- $this->sConn->createCommand($studentClassUpdateSql)->execute();
- }
- }
- }
- if($insertStudentClassRelation){
- $class_sql="insert into student_class_relation(`class_id`,`student_id`,`serial_number`,`userno`,`update_time`,`operation`,`class_type`) values";
- $class_sql.=implode(',',$insertStudentClassRelation);
- $this->sConn->createCommand($class_sql)->execute();
- }
- //$delSql="truncate table import_student_temp;";
- $delSql="delete from import_student_temp;";
- $this->sConn->createCommand($delSql)->execute();
- $transaction->commit();
- 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')
- )));
- }
- $result['status']=1;
- }catch (Exception $e) {
- $transaction->rollback();
- exit(json_encode($result));
- }
- unset($transaction);
- exit(json_encode($result));
- }
- //根据教学班级读取学生
- public function actionLoadStudentByClassified(){
- $realname = safe_replace(Req::post('classname'));
- $result['status']=0;
- if(!$realname){
- exit(json_encode($result));
- }
- $all_student=$this->sConn->createCommand("select class_name,student_name,modify_name,class_id,student_id,student_card from import_student_temp where class_name='".$realname."' and class_not_found=1")->queryAll();
- $extendTh='';
- $html='<tr>';
- $html.="<td>教学班名称</td>";
- $html.="<td>姓名</td>";
- $html.="<td>准考证号</td>";
- if($all_student){
- if($all_student){
- foreach ($all_student as $key=>$val){
- $extendTd='<tr>';
- $extendTd.="<td>{$val['class_name']}</td>";
- $extendTd.="<td>{$val['modify_name']}(原{$val['student_name']})</td>";
- $extendTd.="<td>{$val['student_card']}</td>";
- $extendTd.="</tr>";
- $html.=$extendTd;
- }
- $html.="";
- }
- }
- $result['html']=$html;
- $result['status']=1;
- exit(json_encode($result));
- }
- }
|