123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739 |
- <?php
- /**
- * 班级管理控制器类
- * @author jiangfei
- * @date 2015-09-22 10:50:00
- * @company 上海风车教育有限公司.
- */
- class ParentController extends Controller{
- // 首页
- public function actionIndex(){
- $data = array();
- $realname = Req::get("realname");
- $grade_id = Req::get("grade_id");
- $arts_science = Req::get("arts_science");
- $_teachers = array();
- // 获取所有学期
- $criteria = new CDbCriteria;
- $criteria->limit = 10;
- $criteria->order = "create_time desc";
- $allSemester = Semester::model()->findAll($criteria);
- $smid = safe_replace(Yii::app()->request->getParam('semesterId'));
- if(empty($smid)){
- $semeseter_id = $this->semesterId;
- }
- else{
- $semeseter_id = $smid;
- }
- $semesterId = $semeseter_id;
- // 判断是否教员组长
- if($semesterId){
- if($grade_id)
- {
- $con[] = "seme.semester_id = '{$semesterId}'";
- $con[] = "c.grade=".$grade_id;
- }else
- {
- $con[] = "seme.semester_id = '{$semesterId}'";
- }
- if($realname)
- {
- $_class_ids = $this->schoolManager->getTeachersByteacherName($realname);
- if($_class_ids)
- {
- $con[] = "c.class_id in (".implode(',',$_class_ids).")";
- }else
- {
- $con[] = "c.class_id in (0)";
- }
- }
- if($arts_science){
- $con[] = "c.arts_science=".$arts_science;
- }
- $con[] = " c.is_hide=0 ";
- $rs = $this->schoolManager->getClassesDetailListre($con,9);
- }
- if($rs["rs"]){
- foreach($rs["rs"] as $key => $class){
- $students=$this->schoolManager->getStudentIdByClassId($class['class_id']);
- if($students){
- $rs['rs'][$key]['student_count']=count($students);
- $rs['rs'][$key]['student_bind_count']=$this->schoolManager->countBindStudentIds($students,$this->schoolId);
- }else{
- $rs['rs'][$key]['student_count']=0;
- $rs['rs'][$key]['student_bind_count']=0;
- }
- }
- }
- $currSemester = $this->schoolManager->getCurrSemester();
- $data["grade_id"] = $grade_id;
- $data["arts_science"] = $arts_science;
- $data["realname"] = $realname;
- $data["currSemester"] = $currSemester;
- $data['yearsList'] = $rs["rs"];
- $data['pages'] = $rs["pager"];
- $data['page_total'] = $rs["pager"]->rowsCount;
- $data['semeseter_id'] = $semeseter_id;
- $data["semesters"] = $allSemester;
- $data["semesterId"] = $semesterId;
- $data["thisSemester"] = $this->schoolManager->getSemester($semesterId);
- $this->render('index',$data);
- }
- public function actionView(){
- $get_id = safe_replace(Yii::app()->request->getQuery('cid'));
- if (empty($get_id)) {
- Yii::app()->jump->error('无法访问!');
- }
- $class_info=$this->schoolManager->getClass($get_id);
- if(!$class_info){
- Yii::app()->jump->error('无法访问!');
- }
- $get_list = $this->schoolManager->getClassStudentsList($get_id);
- $teachers = $this->schoolManager->getTeachersByClassesIds(array($get_id));
- $subject=array();
- $subjectTid=array();
- $class_bzr='';
- $class_bzr_id='';
- $studentIds=array();
- $bzr_subject=0;
- //班主任
- if($class_info['teacher_id']){
- $class_bzr_id=$class_info['teacher_id'];
- $class_bzr=Teacher::model()->getTeacherName($class_bzr_id);
- }
- if($teachers){
- foreach ($teachers as $val){
- $subject[$val['subjects']]=$val['teacher_name'];
- $subjectTid[$val['subjects']]=$val['teacher_id'];
- }
- }
- /*
- if($bzr_subject && !isset($subject[$bzr_subject])){
- $subject[$bzr_subject]=$class_bzr;
- $subjectTid[$bzr_subject]=$class_bzr_id;
- }
- */
- foreach ($get_list['rs'] as $val){
- $studentIds[]=$val['student_id'];
- }
- $parentRole=array('0'=>'爸爸','1'=>'妈妈','2'=>'爷爷','3'=>'奶奶','4'=>'叔叔','5'=>'阿姨','6'=>'家长','7'=>'本人','8'=>'其他');
- $parents=$this->schoolManager->getParentByStudentIds($studentIds,$this->schoolId);
- foreach ($get_list['rs'] as $key => $val){
- if(isset($parents[$val['student_id']])){
- foreach ($parents[$val['student_id']] as $k => $v){
- if(isset($parentRole[$v['type']])){
- $parents[$val['student_id']][$k]['type']=$parentRole[$v['type']];
- }else{
- $parents[$val['student_id']][$k]['type']='';
- }
- }
- $get_list['rs'][$key]['parents']=$parents[$val['student_id']];
- $get_list['rs'][$key]['is_bind']=1;
- }else{
- $get_list['rs'][$key]['is_bind']=0;
- }
- }
- $allSubject=Yii::app()->params['subjectId'];
- unset($allSubject[6]);
- unset($allSubject[51]);
- unset($allSubject[18]);
- unset($allSubject[19]);
- $data["allSubject"] = $allSubject;
- $data["students"] = $get_list;
- $data['pages'] = $get_list['pager'];
- $data['page_total'] = $get_list['pager']->rowsCount;
- $data["cid"] = $get_id;
- $data['class_name'] = $class_info['class_name'];
- $data['class_bzr'] = $class_bzr;
- $data['subject_teacher'] = $subject;
- $data['subject_tid'] = $subjectTid;
- $data['class_bzr_id'] = $class_bzr_id;
- $this->render('view',$data);
- }
- //解绑功能
- public function actionUnbind(){
- $parent_id = safe_replace(Yii::app()->request->getParam('parent_id'));
- $student_id = safe_replace(Yii::app()->request->getParam('student_id'));
- $result['status']=0;
- if(!$parent_id){
- exit(json_encode($result));
- }
- if($this->schoolManager->UnbindZl($parent_id,$student_id,$this->schoolId)){
- $result['status']=1;
- }
- exit(json_encode($result));
- }
- //加载teacher
- public function actionLoadTeacher(){
- $keyword = safe_replace(Yii::app()->request->getParam('keyword'));
- $subject = safe_replace(Yii::app()->request->getParam('subject'));
- $class_id = safe_replace(Yii::app()->request->getParam('class_id'));
- $result['status']=0;
- if(!$keyword){
- exit(json_encode($result));
- }
- $data=$this->schoolManager->loadTeacher($keyword,$subject);
- if($data){
- foreach ($data as $key => $v){
- if(isset(Yii::app()->params['subjectId'][$v['subjects']])){
- $data[$key]['subject_name']=Yii::app()->params['subjectId'][$v['subjects']];
- }else{
- $data[$key]['subject_name']='';
- }
- }
- }
- $result['data']=$data;
- $result['status']=1;
- exit(json_encode($result));
- }
- //保存班级教师信息
- public function actionSaveClassTeacher(){
- $cid = safe_replace(Yii::app()->request->getParam('cid'));
- $main_teacher = safe_replace(Yii::app()->request->getParam('main_teacher'));
- $teacher_subject = Yii::app()->request->getParam('teacher_subject');
- $result['status']=0;
- if(!$cid){
- exit(json_encode($result));
- }
- $insertSql="insert into teacher_class_relation(`class_id`,`teacher_id`,`semester_id`,`hxb_ing`,`is_bzr`) values ";
- $insertValues=array();
- if($teacher_subject){
- $teacherIds=$teacher_subject;
- $teachers=$this->schoolManager->getTeachersByTeacherIds($teacherIds);
- if(!$teachers){
- exit(json_encode($result));
- }
-
- $checkSubject=array();
- foreach ($teachers as $v){
- if(isset($checkSubject[$v['subjects']])){
- $result['msg']='同一科目只能设置一位教师';
- exit(json_encode($result));
- }else{
- $checkSubject[$v['subjects']]=$v;
- }
- }
- unset($checkSubject);
- unset($teachers);
- foreach ($teacher_subject as $key=>$val){
- if($val){
- $insertValues[]="('".$cid."','".$val."','".$this->semesterId."',0,0)";
- }
- }
- }
- if($insertValues){
- $transcation = $this->sConn->beginTransaction();
- try {
- $deleteSql="delete from teacher_class_relation where class_id='".$cid."'";
- $this->sConn->createCommand($deleteSql)->execute();
- $insertSql.=implode(',',$insertValues);
- $this->sConn->createCommand($insertSql)->execute();
- //更新班主任
- if( $main_teacher){
- $this->sConn->createCommand("update class set teacher_id='".$main_teacher."' where class_id='".$cid."'")->execute();
- }
- $transcation->commit();
- $result['status']=1;
- }catch (Exception $e){
- $result['status']=0;
- $transcation->rollback();
- }
- }else{
- $result['msg']='必须保留一位任教老师';
- $result['status']=0;
- }
- exit(json_encode($result));
- }
- //下载excel
- public function actionDownloadExcel(){
- $rs = $this->schoolManager->getClasses('ALL',array('class_id desc'));
- $objPHPExcel = new PHPExcel();
- $objPHPExcel->getProperties()->setCreator("ctos")
- ->setLastModifiedBy("ctos")
- ->setTitle("班级信息")
- ->setSubject("班级信息")
- ->setDescription("班级信息")
- ->setKeywords("excel")
- ->setCategory("result file");
- $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(20);
- $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(30);
- $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(10);
- $letters = array('E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
- $allSubject=Yii::app()->params['subjectId'];
- unset($allSubject[3]);
- unset($allSubject[51]);
- unset($allSubject[18]);
- unset($allSubject[19]);
- // $commandStr="$objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', '班级')->setCellValue('B1', '学期')->setCellValue('C1', '年级') ->setCellValue('D1', '班主任')";
- // foreach ($allSubject as $key =>$val){
- // $column=$ExcelToSubject[$key].'1';
- // $commandStr.=" ->setCellValue('".$column."', '".$val."')";
- // }
- // $commandStr.=";";
- // debug($commandStr);
- // eval($commandStr);
- $objPHPExcel->setActiveSheetIndex(0)
- ->setCellValue('A1', '班级')
- ->setCellValue('B1', '学期')
- ->setCellValue('C1', '年级')
- ->setCellValue('D1', '班主任');
- $i=0;
- foreach ($allSubject as $key =>$val){
- $column=$letters[$i].'1';
- $objPHPExcel->getActiveSheet(0)->setCellValue($column,$val);
- $i++;
- }
- $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
- $criteria = new CDbCriteria;
- $criteria->limit = 1;
- $criteria->order = "create_time desc";
- $criteria->condition = " semester_id={$this->semesterId}";
- $semester = Semester::model()->find($criteria);
- $semName = $semester->semester_name;
- $gradeNameArr = array(1=>'高一',2=>'高二',3=>'高三');
- $i = 1;
- foreach($rs as $v)
- {
- $grade = isset(Yii::app()->params['grade_list'][$v['grade']]) ? Yii::app()->params['grade_list'][$v['grade']]['grade_name'] : '';
- $i = $i + 1;
- $objPHPExcel->getActiveSheet(0)->setCellValue('A' . $i, $v['class_name']);
- $objPHPExcel->getActiveSheet(0)->setCellValue('B' . $i, $semName);
- $objPHPExcel->getActiveSheet(0)->setCellValue('C' . $i, $grade);
- $objPHPExcel->getActiveSheet(0)->setCellValue('D' . $i, '');
- $subjectOrder=0;
- foreach ($allSubject as $key =>$val){
- $column=$letters[$subjectOrder].$i;
- $subjectOrder++;
- $objPHPExcel->getActiveSheet(0)->setCellValue($column, '');
- }
- //
- // $objPHPExcel->getActiveSheet(0)->setCellValue('E' . $i, '');
- // $objPHPExcel->getActiveSheet(0)->setCellValue('F' . $i, '');
- // $objPHPExcel->getActiveSheet(0)->setCellValue('G' . $i, '');
- // $objPHPExcel->getActiveSheet(0)->setCellValue('H' . $i, '');
- // $objPHPExcel->getActiveSheet(0)->setCellValue('I' . $i, '');
- // $objPHPExcel->getActiveSheet(0)->setCellValue('J' . $i, '');
- // $objPHPExcel->getActiveSheet(0)->setCellValue('K' . $i, '');
- // $objPHPExcel->getActiveSheet(0)->setCellValue('L' . $i, '');
- // $objPHPExcel->getActiveSheet(0)->setCellValue('M' . $i, '');
- // $objPHPExcel->getActiveSheet(0)->setCellValue('N' . $i, '');
- }
- $objPHPExcel->getActiveSheet()->setTitle('家校管理班级信息');
- $objPHPExcel->setActiveSheetIndex(0);
- ob_end_clean(); // Added by me
- header("Accept-Ranges:bytes");
- header('Content-Type:application/vnd.ms-excel');
- header("Content-type:application/vnd.ms-excel;charset=UTF-8");
- header('Content-Disposition:attachment;filename="家校管理班级信息.xls"');
- header('Cache-Control:max-age=0');
- $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
- $objWriter->save('php://output');
- exit;
- }
- //导入班主任信息
- public function actionImport(){
- ini_set ('memory_limit', '300M');
- if(!$_FILES){
- Yii::app()->jump->error('文件大小超过范围');
- }else {
- if (!isset($_FILES['file']) || !isset($_FILES['file']['size']) || $_FILES['file']['size'] > 5242880) {
- Yii::app()->jump->error('文件大小超过范围');
- }
- }
- $uploader = new Uploader("upload/tmpDir/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"];
- // 导入PHPExcel类
- Yii::import('application.extensions.*');
- require_once('phpexcel/PHPExcel/IOFactory.php');
- try{
- $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
- $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
- //FIXME 2019-12-02
- @unlink($file["src"]);
- }catch (Exception $e){
- //FIXME 2019-12-02
- @unlink($file["src"]);
- Yii::app()->jump->error('Excel格式不正确:'.$e->getMessage());
- }
- if(!$sheetData)
- {
- Yii::app()->jump->error('请正确的Excel!');
- }
- unset($objPHPExcel);
- $letters = array('E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','AA','AB','AC','AD','AE','AF','AG','AH','AI','AJ','AK','AL','AM');
- $allSubject=Yii::app()->params['subjectId'];
- unset($allSubject[3]);
- unset($allSubject[51]);
- unset($allSubject[18]);
- unset($allSubject[19]);
- //模板校验
- $excelTemp = array('A'=>'班级','B'=>'学期','C'=>'年级','D'=>'班主任');
- $subjectExcel=array();
- $subjectOrder=0;
- foreach ($allSubject as $key =>$val){
- $subjectExcel[$letters[$subjectOrder]]=$val;
- $subjectOrder++;
- }
- $excelTemp=array_merge($excelTemp,$subjectExcel);
- if(count($excelTemp) != count($sheetData[1])){
- Yii::app()->jump->error('导入的excel格式与模版不一致,请重新上传');
- }
- foreach($excelTemp as $key=>$temp){
- if(!(isset($sheetData[1][$key]) && $sheetData[1][$key] == trim($temp))){
- Yii::app()->jump->error('导入的excel格式与模版不一致,请重新上传');
- }
- }
- unset($sheetData[1]);
- if(!$sheetData)
- {
- Yii::app()->jump->error('请输入数据');
- }
- $updateSql = '';
- $cls = array();
- foreach($sheetData as $sheet){
- $cls[] = $sheet['A'];
- }
- //班级信息
- $className = array_unique($cls);
- $classNameIdRel = ClassModel::model()->getClassByName($className);
- $classArr = array_keys($classNameIdRel);
- $teacherSheet = array_keys($subjectExcel);
- $nameArr = array();
- foreach($sheetData as $sheet){
- foreach($teacherSheet as $ts){
- if(isset($sheet[$ts]) && $sheet[$ts]) $nameArr[] = $this->myTrim($sheet[$ts]);
- }
- }
- //查询是否存在重名老师
- $teacherInfo = Teacher::model()->getNameCount(array_unique($nameArr));
- $teacherSub = Teacher::model()->getTeacherSub();
- if(empty($teacherInfo)){
- Yii::app()->jump->error('教师信息为空或填写错误');
- }
- $teacherArr = $teacherInfo['info'];
- $nameIdRel = array_flip($teacherArr);
- $same = $teacherInfo['same'];
- $phoneInfo = BusinessTeacher::model()->getTeacherInfo($this->schoolId,true);
- $insertValues = $updateClassIds = array();
- $delSql = '';
- foreach (Yii::app()->params['grade_config'] as $param){
- $gradeArr[]=$param['grade_name'];
- }
-
- $semName = Semester::model()->getSemesterName($this->semesterId);
- foreach ($sheetData as $val){
- $classValues = array();
- $className = trim($val['A']);
- if(empty($className)){
- Yii::app()->jump->error('班级名称不能为空');
- }
- if(!in_array($className,$classArr)){
- Yii::app()->jump->error($className.'班级不存在');
- }
- $classId = $classNameIdRel[$className];
- $sem = trim($val['B']);
- if(empty($sem)){
- Yii::app()->jump->error('学期不能为空');
- }elseif($semName != $sem){
- Yii::app()->jump->error('当前学期信息有误');
- }
- $grade = trim($val['C']);
- if(empty($grade)){
- Yii::app()->jump->error('年级不能为空');
- }elseif(!in_array($grade,$gradeArr)){
- Yii::app()->jump->error($grade.'年级不存在');
- }
- $val['D'] = $this->myTrim($val['D']);
- $origin = $name = trim($val['D']);
- preg_match('/\d+/',$name,$match);
- $name = trim(preg_replace('/\d+/','',$name));
- if($name){
- if(!in_array($name,$teacherArr)){
- Yii::app()->jump->error("您上传的教师姓名有误,请重新上传</br>{$className}-班主任-$origin");
- }
- if(in_array($name,$same)){
- if(!empty($match)){
- $phonNum = $match[0];
- if(isset($phoneInfo[$phonNum])) $chargeTeacherId = $phoneInfo[$phonNum];
- else Yii::app()->jump->error($phonNum.'后四位手机号匹配不到老师');
- }else{
- Yii::app()->jump->error('有多个'.$name.'老师,请在姓名后面添加手机号后四位');
- }
- }else{
- $chargeTeacherId = $nameIdRel[$name];
- }
- $updateSql .= "UPDATE class SET teacher_id='".$chargeTeacherId."' where class_id='".$classId."';";
- }
- foreach ($subjectExcel as $key => $item){
- $classValues[] = $this->nameHandle($val[$key],$teacherArr,$same,$phoneInfo,$nameIdRel,$classId,$teacherSub,$item,$delSql,$className);
- }
- // $classValues[] = $this->nameHandle($val['E'],$teacherArr,$same,$phoneInfo,$nameIdRel,$classId,$teacherSub,$excelTemp['E'],$delSql,$className);
- // $classValues[] = $this->nameHandle($val['F'],$teacherArr,$same,$phoneInfo,$nameIdRel,$classId,$teacherSub,$excelTemp['F'],$delSql,$className);
- // $classValues[] = $this->nameHandle($val['G'],$teacherArr,$same,$phoneInfo,$nameIdRel,$classId,$teacherSub,$excelTemp['G'],$delSql,$className);
- // $classValues[] = $this->nameHandle($val['H'],$teacherArr,$same,$phoneInfo,$nameIdRel,$classId,$teacherSub,$excelTemp['H'],$delSql,$className);
- // $classValues[] = $this->nameHandle($val['I'],$teacherArr,$same,$phoneInfo,$nameIdRel,$classId,$teacherSub,$excelTemp['I'],$delSql,$className);
- // $classValues[] = $this->nameHandle($val['J'],$teacherArr,$same,$phoneInfo,$nameIdRel,$classId,$teacherSub,$excelTemp['J'],$delSql,$className);
- // $classValues[] = $this->nameHandle($val['K'],$teacherArr,$same,$phoneInfo,$nameIdRel,$classId,$teacherSub,$excelTemp['K'],$delSql,$className);
- // $classValues[] = $this->nameHandle($val['L'],$teacherArr,$same,$phoneInfo,$nameIdRel,$classId,$teacherSub,$excelTemp['L'],$delSql,$className);
- // $classValues[] = $this->nameHandle($val['M'],$teacherArr,$same,$phoneInfo,$nameIdRel,$classId,$teacherSub,$excelTemp['M'],$delSql,$className);
- // $classValues[] = $this->nameHandle($val['N'],$teacherArr,$same,$phoneInfo,$nameIdRel,$classId,$teacherSub,$excelTemp['N'],$delSql,$className);
- $classValues = array_filter($classValues);
- if(!empty($classValues)){
- $insertValues = array_merge($insertValues,$classValues);
- $updateClassIds[] = $classId;
- }
- }
- if(($insertValues && $updateClassIds) || $updateSql){
- $transcation = $this->sConn->beginTransaction();
- $insertSql="insert into teacher_class_relation(`class_id`,`teacher_id`,`semester_id`,`hxb_ing`,`is_bzr`) values ";
- try {
- if($delSql){
- $this->sConn->createCommand($delSql)->execute();
- }
- if($insertValues){
- $insertSql.=implode(',',$insertValues);
- $this->sConn->createCommand($insertSql)->execute();
- }
- //更新班主任
- if( $updateSql){
- $this->sConn->createCommand($updateSql)->execute();
- }
- $transcation->commit();
- Yii::app()->jump->error('家校批量上传成功!',$this->createUrl('/parent/index'));
- }catch (Exception $e){
- Yii::app()->jump->error('家校批量上传失败!');
- }
- }else{
- Yii::app()->jump->error('请输入数据!');
- }
- }
- public function actionExcelInfo(){
- $this->render('excelinfo',array());
- }
- protected function nameHandle($name,$teacherArr,$same,$phoneInfo,$nameIdRel,$classId,$subArr,$sub,&$del,$className){
- $subjectArr=Yii::app()->params['subjectId'];
- unset($subjectArr[3]);
- unset($subjectArr[51]);
- unset($subjectArr[18]);
- unset($subjectArr[19]);
- $name = $this->myTrim($name);
- $origin = $name = trim($name);
- if(empty($name) && $name !== '0') return '';
- preg_match('/\d+/',$name,$match);
- $name = trim(preg_replace('/\d+/','',$name));
- if(!in_array($name,$teacherArr)){
- Yii::app()->jump->error("您上传的教师姓名有误,请重新上传</br>{$className}-{$sub}-$origin");
- }
- if(in_array($name,$same)){
- if(!empty($match)){
- $phonNum = $match[0];
- if(isset($phoneInfo[$phonNum])) $teacherId = $phoneInfo[$phonNum];
- else Yii::app()->jump->error($phonNum.'后四位手机号匹配不到老师');
- }else{
- Yii::app()->jump->error('有多个'.$name.'老师,请在姓名后面添加手机号后四位');
- }
- }else{
- $teacherId = $nameIdRel[$name];
- }
- if(isset($subjectArr[$subArr[$teacherId]]) && $subjectArr[$subArr[$teacherId]] != $sub){
- Yii::app()->jump->error("您上传的教师与任教学科不符,请重新上传</br>$name:上传{$sub},任课".$subjectArr[$subArr[$teacherId]]);
- }
- $sql = "SELECT tcr.* FROM teacher_class_relation tcr INNER JOIN teacher t ON tcr.teacher_id=t.teacher_id WHERE subjects=".$subArr[$teacherId]." AND class_id={$classId}";
- $relation = TeacherToClass::model()->getTeacher($sql);
- if(!empty($relation)){
- $del .= "DELETE FROM teacher_class_relation WHERE teacher_id={$relation['teacher_id']} AND class_id={$classId} AND semester_id=".$this->semesterId.';';
- }
- return "('".$classId."','".$teacherId."','".$this->semesterId."',0,0)";
- }
- protected function myTrim($str)
- {
- $search = array(" "," ","\n","\r","\t");
- $replace = array("","","","","");
- return str_replace($search, $replace, $str);
- }
- //当天绑定日志
- public function actionBindCodeLog(){
- $cid =safe_replace(Yii::app()->request->getParam('cid'));
- $time=date('Y-m-d 00:00:00',time());
- $criteria = new CDbCriteria();
- $criteria->addCondition('create_time>:time');
- $criteria->addCondition('clazz_id=:cid');
- $criteria->params[':time'] = $time;
- $criteria->params[':cid'] = $cid;
- $criteria->order = 'create_time desc';
- $dataLog=SStudentBindCodeLog::model()->findAll($criteria);
- $data=array();
- if($dataLog){
- foreach ($dataLog as $item){
- $student=SStudentInfo::model()->find("student_id=:sid",array(':sid'=>$item['student_id']));
- $mobile=substr_replace($item['mobile'],'****',3,4);
- $data[]=array(
- 'time'=>date('H:i:s',strtotime($item['create_time'])),
- 'student_name'=>$student['realname'],
- 'mobile'=>$mobile,
- 'code'=>$item['bind_code']
- );
- }
- }
- $result['status']=1;
- $result['data']=$data;
- exit(jsonEncode($result));
- }
- }
|