"任课教师",
1 => "班主任",
2 => "教研组长",
3 => "年级主任",
4 => "任课教师",
5 => "校长",
);
private $subjects = array(
1 => "语文",
3 => "数学",
6 => "数学",
2 => "英语",
12 => "物理",
13 => "化学",
14 => "生物",
7 => "政治",
8 => "历史",
9 => "地理",
10 => "信息技术",
);
private $title = array(
0 => "",
1 => "一级教师",
2 => "二级教师",
3 => "三级教师",
4 => "高级教师",
);
// 教师列表
public function actionIndex()
{
$data = array();
// 判断是否教员组长
$teachArray = array();
$teacherList = array();
$realname = safe_replace(Yii::app()->request->getQuery('realname'));
$subject_id = safe_replace(Yii::app()->request->getQuery('subject_id'));
$class_id = safe_replace(Yii::app()->request->getQuery('class_id'));
if (!isset($subject_id) || empty($subject_id)) {
$subject_id = 0;
}
$class_data = array();
if(is_numeric($realname)){
//搜索教师账号
$BTeacher=new BusinessTeacher();
$teacherIdArr=$BTeacher->getTeacherIdByNumber($realname,$this->schoolId);
if(!$teacherIdArr){
$teachersList=array();
$teachersList['rs']=array();
$teachersList["pager"]=new CPagination(0, 10);
}else{
$teachersList = $this->schoolManager->getTeachersListre($teacherIdArr, $subject_id, $class_id, array("add_time desc"));
}
}else{
$teachersList = $this->schoolManager->getTeachersListre($realname, $subject_id, $class_id, array("add_time desc"));
}
$classes = ClassModel::model()->findAll('semester_id=:semester_id and is_hide=0', array(':semester_id' => $this->semesterId));
if ($classes) {
foreach ($classes as $v) {
$class_data[$v->class_id] = $v->class_name;
}
}
$data['teachArray'] = $teachersList["rs"];
$data['realname'] = $realname;
$data['class_id'] = $class_id;
$data['class_data'] = $class_data;
$data['subject_id'] = $subject_id;
$data['pages'] = $teachersList["pager"];
$data['page_total'] = $teachersList["pager"]->rowsCount;
$data['postlist'] = $this->post;
$data['subjectslist'] = Yii::app()->params['subjectId'];
if(isset($data['subjectslist'][6])){
unset($data['subjectslist'][6]);
}
if(isset($data['subjectslist'][51])){
unset($data['subjectslist'][51]);
}
if(isset($data['subjectslist'][18])){
unset($data['subjectslist'][18]);
}
if(isset($data['subjectslist'][19])){
unset($data['subjectslist'][19]);
}
$data['titlelist'] = $this->title;
$this->render('index', $data);
}
// 添加老师
public function actionAdd()
{
if (Yii::app()->request->getIsPostRequest()) {
$class_id = Yii::app()->request->getPost('class_array');
$teacher_name = safe_replace(Yii::app()->request->getPost('teacher_name'));
//$account = safe_replace(Yii::app()->request->getPost('account'));
$phone_number = safe_replace(Yii::app()->request->getPost('phone_number'));
$teacher_email = safe_replace(Yii::app()->request->getPost('teacher_email'));
$teacher_age = safe_replace(Yii::app()->request->getPost('teacher_age'));
$teacher_sex = safe_replace(Yii::app()->request->getPost('teacher_sex'));
$status = safe_replace(Yii::app()->request->getPost('status'));
$password = safe_replace(Yii::app()->request->getPost('password'));
$password2 = safe_replace(Yii::app()->request->getPost('password2'));
$posts = safe_replace(Yii::app()->request->getPost('posts'));
$title = safe_replace(Yii::app()->request->getPost('title'));
$subjects = safe_replace(Yii::app()->request->getPost('subjects'));
$grade = safe_replace(Yii::app()->request->getPost('grade')); ///年级
//$changeSchool=safe_replace(Yii::app()->request->getPost('changeSchool')); //教师更新学校标记
$changeSchool=0;
if (empty($teacher_name) || empty($phone_number) || empty($password)) {
Yii::app()->jump->error('请确认教师信息是否填写完整!');
}
if (!preg_match("/1[3456789]{1}\d{9}$/", $phone_number)) {
Yii::app()->jump->error('手机号格式有误!');
}
if ($password != $password2) {
Yii::app()->jump->error('两次输入的密码不一致!');
} elseif (strlen($password) < 5) {
Yii::app()->jump->error('密码长度至少需要6位数!');
}
// 判断当前手机是否在当前学校已使用
$businessTeacher=BusinessTeacher::model()->find('phone_number=:num ', array(':num' => $phone_number));
if ($businessTeacher && !$changeSchool) {
Yii::app()->jump->error('手机号已存在!');
}
//同学科同年级只能有六个年级主任
if ($posts==3){
if(!$grade){
Yii::app()->jump->error('岗位为年级主任时必须填写年级!');
}
$has_3_posts = Teacher::model()->count('grade=:grade and posts=:posts and subjects=:subjects',
array(':grade'=> $grade, ':posts'=> $posts, ':subjects'=> $subjects));
if ($has_3_posts>=6){
Yii::app()->jump->error('同学科,同年级最多可以创建六个主任账号!');
}
}else{
$grade=0;
}
// 将教师登录账号插入主数据
$password=md5(sha1($password));
$time=time();
$businessRs=false;
$transaction_conn = $this->conn->beginTransaction();
try{
// $phoneLog=BusinessTeacherMoveLog::model()->find('phone_number=:pn and school_id=:sid',array(':pn'=>$phone_number,':sid'=>$this->schoolId));
// if($phoneLog){
// $teacherId=$phoneLog->teacher_id;
// }else{
// $teacherId=getUniqueId($this->schoolId);
// }
// if($changeSchool && $businessTeacher){
//
// $insertLog="insert into teacher_move_log(`teacher_id`,`phone_number`,`school_id`,`move_time`,`because`) values ('".$businessTeacher->teacher_id."','".$phone_number."','".$businessTeacher->school_id."','".$time."','1')";
// $this->conn->createCommand($insertLog)->execute();
// $this->conn->createCommand("delete from teacher where teacher_id='".$businessTeacher->teacher_id."'")->execute();
// }
$teacherId=getUniqueId($this->schoolId);
$insertSql="insert into xb_teacher(`teacher_id`,`phone_number`,`password`,`school_id`,`add_time`,`status`) values ('".$teacherId."','".$phone_number."','".$password."','".$this->schoolId."','".$time."','".$status."')";
$this->conn->createCommand($insertSql)->execute();
$businessRs=true;
}catch (\Exception $e){
$transaction_conn->rollback();
Yii::app()->jump->error('添加老师失败!');
}
if($businessRs){
$transaction = $this->sConn->beginTransaction();
try{
$teacherSql="insert into teacher(`teacher_id`,`teacher_name`,`teacher_email`,`teacher_age`,`teacher_sex`,`add_time`,`status`,`coach_id`,`posts`,`title`,`subjects`,`grade`) values ";
$teacherSql.="('".$teacherId."','".$teacher_name."','".$teacher_email."','".$teacher_age."','".$teacher_sex."','".$time."','".$status."','".$this->coachId."','".$posts."','".$title."','".$subjects."','".$grade."')";
$this->sConn->createCommand($teacherSql)->execute();
$transaction_conn->commit();
$transaction->commit();
$this->redirect(array('teacher/index'));
}catch (\Exception $e){
$transaction->rollback();
$transaction_conn->rollback();
Yii::app()->jump->error('添加老师失败!');
}
}
}
$data = array();
// 获取当前学校当前学期班级未分配班级
$classInfo = ClassModel::model()->findAll('semester_id=' . Yii::app()->session['session_semester_id']);
// 获取当前学期已分配班级
$getClass = TeacherToClass::model()->findAll('semester_id=' . Yii::app()->session['session_semester_id']);
foreach ($classInfo as $key => $val) {
foreach ($getClass as $k => $v) {
if ($v->class_id == $val->class_id) {
unset($classInfo[$key]);
}
}
}
if (Yii::app()->session['coachInfo']['leader'] == 0) {
// 获取当前教员管理班级
$conclass = array();
$coachClass = $this->schoolManager->getCoachClassesRelations($this->coachId, "OBJ");
foreach ($coachClass as $cc => $aa) {
array_push($conclass, $aa->class_id);
}
foreach ($classInfo as $ci => $cf) {
if (!in_array($cf->class_id, $conclass)) {
unset($classInfo[$ci]);
}
}
}
if (empty($classInfo)) {
//Yii::app()->jump->error('暂无班级可分配请先添加班级!',$this->createUrl('classes/index'));
}
$data['classInfo'] = $classInfo;
$this->render('add', $data);
}
public function actionVerifyphone_number()
{
$phone_number = safe_replace(Yii::app()->request->getPost('phone_number'));
$is_edit = safe_replace(Yii::app()->request->getPost('is_edit'));
if (!preg_match("/1[3456789]{1}\d{9}$/", $phone_number)) {
Yii::app()->jump->error('手机号格式有误!');
}
if ($is_edit == 1) {
$teacher_id = safe_replace(Yii::app()->request->getPost('teacher_id'));
$getBtteacher = BusinessTeacher::model()->find('teacher_id=:tid', array(':tid' => $teacher_id));
$Btteacher = BusinessTeacher::model()->find('phone_number=:phone_number', array(':phone_number' => $phone_number));
if (!$getBtteacher) {
echo json_encode(array('status' => 0));
exit;
}
if(!$Btteacher || $Btteacher->teacher_id==$teacher_id){
exit(json_encode(array('status' => 1)));
}elseif($Btteacher->school_id==$this->schoolId){
exit(json_encode(array('status' => -1)));
}else{
//查学校
$teacherSchool=BusinessSchool::model()->find('school_id=:sid',array(':sid'=>$Btteacher->school_id));
exit(json_encode(array('status' => 0,'data'=>$teacherSchool->school_name)));
}
} else {
$teacher=BusinessTeacher::model()->find('phone_number=:phone_number', array(':phone_number' => $phone_number));
if($teacher){
if($teacher->school_id==$this->schoolId){
echo json_encode(array('status' => -1));
exit;
}else{
//查学校
$teacherSchool=BusinessSchool::model()->find('school_id=:sid',array(':sid'=>$teacher->school_id));
echo json_encode(array('status' => 0,'data'=>$teacherSchool->school_name));
exit;
}
}
echo json_encode(array('status' => 1));
exit;
}
}
// 编辑教师
public function actionEdit()
{
$thid = safe_replace(Yii::app()->request->getQuery('thid'));
if (empty($thid)) {
Yii::app()->jump->error('您访问的页面不存在!');
}
// 当前教师信息
$teacherInfo = Teacher::model()->find('teacher_id=:tid', array(':tid' => $thid));
$getBtteacher = BusinessTeacher::model()->find('teacher_id=:tid', array(':tid' => $thid));
if (empty($teacherInfo) || empty($getBtteacher)) {
Yii::app()->jump->error('未找到该教师信息!');
}
if (Yii::app()->request->getIsPostRequest()) {
$data = array();
//$account = safe_replace(Yii::app()->request->getPost('account'));
$teacher_name = safe_replace(Yii::app()->request->getPost('teacher_name'));
$phone_number = safe_replace(Yii::app()->request->getPost('phone_number'));
$teacher_email = safe_replace(Yii::app()->request->getPost('teacher_email'));
$teacher_age = safe_replace(Yii::app()->request->getPost('teacher_age'));
$teacher_sex = safe_replace(Yii::app()->request->getPost('teacher_sex'));
$status = safe_replace(Yii::app()->request->getPost('status'));
$password = safe_replace(Yii::app()->request->getPost('password'));
$password2 = safe_replace(Yii::app()->request->getPost('password2'));
//$class_id = Yii::app()->request->getPost('class_array');
$posts = safe_replace(Yii::app()->request->getPost('posts'));
$title = safe_replace(Yii::app()->request->getPost('title'));
$subjects = safe_replace(Yii::app()->request->getPost('subjects'));
$grade = safe_replace(Yii::app()->request->getPost('grade'));
//$changeSchool = safe_replace(Yii::app()->request->getPost('changeSchool'));
$changeSchool=0;
if (empty($teacher_name) || empty($phone_number)) {
Yii::app()->jump->error('请确认教师信息是否填写完整!');
}
$businessTeacher=BusinessTeacher::model()->find('phone_number=:num ', array(':num' => $phone_number));
if($businessTeacher && $businessTeacher->teacher_id!=$thid){
if($businessTeacher->school_id==$this->schoolId){
Yii::app()->jump->error('手机号在本校已存在!');
}elseif(!$changeSchool){
Yii::app()->jump->error('手机号已存在!');
}
}
if (!empty($password) && !empty($password2) && ($password == $password2)) {
if (strlen($password) < 5) {
Yii::app()->jump->error('密码长度至少需要6位数!');
}
//$teacherInfo->password = md5(sha1($password));
//$getBtteacher->password = md5(sha1($password));
$data = array(
'phone_number' => $phone_number,
'password' => md5(sha1($password)),
'status' => $status
);
} else {
$data = array(
'phone_number' => $phone_number,
'status' => $status
);
}
//同学科同年级只能有六个年级主任
if ($posts==3){
if(!$grade){
Yii::app()->jump->error('岗位为年级主任时必须填写年级!');
}
$has_3_posts = Teacher::model()->count('teacher_id!=:teacher_id and grade=:grade and posts=:posts and subjects=:subjects',
array(':teacher_id'=>$thid,':grade'=> $grade, ':posts'=> $posts, ':subjects'=> $subjects));
if ($has_3_posts>=6){
Yii::app()->jump->error('同学科,同年级最多可以创建六个主任账号!');
}
}else{
$grade=0;
}
// 将教师登录账号插入主数据
$time=time();
$businessRs=false;
$transaction_conn = $this->conn->beginTransaction();
try{
$updateSql="update xb_teacher set ";
$setArr=array();
foreach ($data as $key => $val){
$setArr[]="`".$key."`='".$val."'";
}
$updateSql.=implode(',',$setArr);
$updateSql.=" where teacher_id='".$thid."'";
$this->conn->createCommand($updateSql)->execute();
$businessRs=true;
}catch (\Exception $e){
$transaction_conn->rollback();
Yii::app()->jump->error('修改老师失败!');
}
if($businessRs){
$transaction = $this->sConn->beginTransaction();
try{
$teachdata['teacher_name'] = $teacher_name;
$teachdata['teacher_email'] = $teacher_email;
$teachdata['teacher_age'] = $teacher_age;
$teachdata['teacher_sex'] = $teacher_sex;
$teachdata['add_time'] = $time;
$teachdata['status'] = $status;
$teachdata['posts'] = $posts;
$teachdata['title'] = $title;
$teachdata['subjects'] = $subjects;
$teachdata['grade'] = $grade;
$updateSql="update teacher set ";
$setArr=array();
foreach ($teachdata as $key => $val){
$setArr[]="`".$key."`='".$val."'";
}
$updateSql.=implode(',',$setArr);
$updateSql.=" where teacher_id='".$thid."'";
$this->sConn->createCommand($updateSql)->execute();
$transaction_conn->commit();
$transaction->commit();
$this->redirect(array('teacher/index'));
}catch (\Exception $e){
$transaction->rollback();
$transaction_conn->rollback();
Yii::app()->jump->error('修改失败!');
}
}
}
$data = array();
// 当前教师所执教班级
$getClass = TeacherToClass::model()->findAll('teacher_id=:tid', array(':tid' => $thid));
$toTeacher = array();
foreach ($getClass as $va) {
array_push($toTeacher, $va->class_id);
}
// 获取当前学校班级
$classInfo = ClassModel::model()->findAll('semester_id=' . Yii::app()->session['session_semester_id']);
if (Yii::app()->session['coachInfo']['leader'] == 0) {
// 获取当前教员管理班级
$coachClass = $this->schoolManager->getCoachClassesRelations($this->coachId, "OBJ");
$ttttt = array();
foreach ($coachClass as $cc => $aa) {
array_push($ttttt, $aa->class_id);
}
foreach ($classInfo as $ci => $cf) {
if (!in_array($cf->class_id, $ttttt)) {
unset($classInfo[$ci]);
}
}
}
$data['classStr'] = implode(',', $toTeacher);
$data['toTeacher'] = $toTeacher;
$data['classInfo'] = $classInfo;
$data['teacherInfo'] = $teacherInfo;
$data['getBtteacher'] = $getBtteacher;
$this->render('edit', $data);
}
public function actionDelTeacherAct()
{
$teacherId = Req::post("teacherId");
echo json_encode($this->schoolManager->purgeTeacher($teacherId));
exit;
}
public function actionExcelInfo(){
$this->render('excelinfo');
}
//导入教师信息
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);
//模板校验
$excelTemp = array('A'=>'*教师姓名','B'=>'*登录手机号','C'=>'*学科','D'=>'*岗位','E'=>'职称','F'=>'执教班级','G'=>'教龄','H'=>'性别','I'=>'年级');
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 = '';
$password = '123456';
$busTeacherData = $schoolTeacherData = array(); //新增记录
$updateTeacherData=array(); //修改教师信息
$delOldTeacherClass=array(); //删除同科目原执教教师记录
$addTeacherClass=array(); //添加新执教教师
Yii::app()->jump->setErrorWait('5');
$schoolId = Yii::app()->session['coachInfo']['school_id'];
$postArr = $this->post;
unset($postArr[0]);
$titleArr = $this->title;
unset($titleArr[0]);
$subjectArr = array(
3 => "数学",
8 => "英语",
9 => "语文",
12 => "物理",
13 => "化学",
14 => "生物",
15 => "政治",
16 => "历史",
17 => "地理",
20 => "其它",
);
$subjectArr=Yii::app()->params['subjectId'];
if(Yii::app()->params['section']==1){
unset($subjectArr[6]);
unset($subjectArr[51]);
}
$phoneArr = array();
foreach($sheetData as $value){
$value['B'] = trim($value['B']);
if(!empty($value['B'])){
$phoneArr[] = '"'.$this->myTrim($value['B']).'"';
}
}
//查询老师手机号
$phoneInfo = BusinessTeacher::model()->getAddTeacherInfo($phoneArr);
$samePhone = array();
foreach($sheetData as $val){
$samePhone[] = ''.$val['B'];
}
$countSame = array_count_values($samePhone);
$alert = "教师手机号有重复请重新上传";
$check = false;
$count = 0;
foreach($countSame as $key=>$item){
if(empty($key)) continue;
if($item>1){
$check = true;
foreach($sheetData as $v){
if($v['B'] == $key){
$count++;
$alert .= "{$v['A']}:{$v['B']}";
}
}
}
}
if($check){
Yii::app()->jump->setHeight(100+$count*15);
Yii::app()->jump->error($alert);
}
$classError=array();
$directorCount=array();
$classSubject=array();
foreach ($sheetData as $val){
if(empty($val['B'])){
Yii::app()->jump->error('手机号不能为空');
}
$oldTeacherId=0;
$phoneNum = trim($val['B']);
$phoneNum = $this->myTrim($phoneNum);
if(empty($val['A'])){
Yii::app()->jump->error('教师姓名不能为空');
}
$teacherName = $this->myTrim($val['A']);
if(preg_match('/^[\x{4e00}-\x{9fa5}a-zA-Z0-9·]+$/u', $teacherName)>0){
$teacherName = $this->myTrim($val['A']);
}elseif(preg_match('/[\x{4e00}-\x{9fa5}0-9]/u', $teacherName)>0){
Yii::app()->jump->error('确保教师姓名是汉字'.$teacherName);
}
// if(preg_match('/^[\x{4e00}-\x{9fa5}·]+$/u', $teacherName)>0){
// $teacherName = $this->myTrim($val['A']);
// }else{
// Yii::app()->jump->error('确保教师姓名是汉字'.$teacherName);
// }
if (!preg_match("/1[3456789]{1}\d{9}$/", $phoneNum)) {
Yii::app()->jump->error("教师手机号有误请重新上传{$teacherName}:$phoneNum");
}
if(isset($phoneInfo[$phoneNum])){
// Yii::app()->jump->error("教师手机号已存在,勿重复添加{$teacherName}:$phoneNum");
//对比姓名
$teacherAccount=$this->schoolManager->getTeacherAccount($phoneInfo[$phoneNum]);
if($teacherAccount){
// 当前教师信息
$teacherInfo = Teacher::model()->find('teacher_id=:tid', array(':tid' => $phoneInfo[$phoneNum]));
if($teacherAccount['school_id']!=$this->schoolId){
Yii::app()->jump->error("该手机号已存在,请仔细核查是否填写错误,若需转校可联系技术支持处理{$teacherName}:$phoneNum");
}
if($teacherInfo->teacher_name!=$teacherName){
Yii::app()->jump->error("教师姓名与系统内教师不匹配,请检查{$teacherName}:$phoneNum");
}
$oldTeacherId=$phoneInfo[$phoneNum];
}
}
if(empty($val['C'])){
Yii::app()->jump->error('学科不能为空');
}
$subject = $this->myTrim($val['C']);
if(!in_array($subject,$subjectArr)){
Yii::app()->jump->error($subject.'学科不存在');
}
$subjectId = array_search($subject,$subjectArr);
if(empty($val['D'])){
Yii::app()->jump->error('岗位不能为空');
}
$post = $this->myTrim($val['D']);
if(!in_array($post,$postArr)){
Yii::app()->jump->error($post.'岗位不存在');
}
$post = array_search($post,$postArr);
$grade=$val['I'];
if(!empty($val['I']) && !isset(Yii::app()->params['grade_config'][$val['I']])){
Yii::app()->jump->error('年级设置不正确');
}
if($post==3){
if(empty($val['I'])){
Yii::app()->jump->error('岗位为年级主任时必须填写年级!');
}
if(isset($phoneInfo[$phoneNum]) && $teacherInfo){
if($teacherInfo->posts!=3 || $teacherInfo->grade!=$grade || $teacherInfo->subjects!=$subjectId){
if(!isset($directorCount[$subjectId][$grade])){
$directorCount[$subjectId][$grade]=1;
}else{
$directorCount[$subjectId][$grade]++;
}
}
}else{
if(!isset($directorCount[$subjectId][$grade])){
$directorCount[$subjectId][$grade]=1;
}else{
$directorCount[$subjectId][$grade]++;
}
}
}else{
$grade=0;
}
$title = $this->myTrim($val['E']);
if(empty($title)){
// Yii::app()->jump->error('职称不能为空');
}
if(!empty($val['E']) && !in_array($title,$titleArr)){
Yii::app()->jump->error($val['E'].'职称不存在');
}
//执教班级
$needAddClass=array();
if(!empty($val['F'])){
$val['F']=str_replace(";",";",$val['F']);
$classNames=explode(";",$val['F']);
$notFondClass=array();
if($classNames){
foreach ($classNames as $className){
if(!$className) continue;
$classId=$this->schoolManager->getClassInfoByClassName($className,$this->semesterId);
//查询
if($classId){
if(isset($classSubject[$classId]) && $classSubject[$classId]['subjectId']==$subjectId){
Yii::app()->jump->error('多名同学科教师不能执教同一班级
'.$val['A'].','.$classSubject[$classId]['name']);
}else{
$classSubject[$classId]=array(
'subjectId'=>$subjectId,
'name'=>$val['A']
);
}
$classSubjectTeacher=$this->schoolManager->getTeacherByClassSubject($classId,$subjectId);
if($classSubjectTeacher){
//已有相同科目教师,覆盖原记录
$delOldTeacherClass[]="delete from teacher_class_relation where class_id='{$classId}' and teacher_id='{$classSubjectTeacher['teacher_id']}'";
}
$needAddClass[]=$classId;
}else{
$notFondClass[]=$className;
}
}
if($notFondClass){
$classError[]=$teacherName.":".$phoneNum." ".implode(',',$notFondClass);
}
}
}
$title = intval(array_search($title,$titleArr));
if($val['G'] && !is_numeric($val['G'])){
Yii::app()->jump->error('教龄需填写数字');
}
$teacherAge = intval($val['G']);
$sex = trim($val['H']);
$teacherSex = 0;
if(strstr($sex,'女') !== false) $teacherSex = 1;
if($oldTeacherId){
$teacherId=$oldTeacherId;
$updateTeacherData[]="update teacher set teacher_age='{$teacherAge}',teacher_sex='{$teacherSex}',posts='{$post}',title='{$title}',subjects='{$subjectId}',grade='{$grade}' where teacher_id='{$teacherId}'";
}else{
$teacherId=getUniqueId($this->schoolId);
$pwd = '"'.md5(sha1($password)).'"';
$busTeacherData[] = array($teacherId,$phoneNum,$pwd,$schoolId,time());
$schoolTeacherData[] = array($teacherId,'"'.$teacherName.'"',$teacherAge,$teacherSex,time(),$this->coachId,$post,$title,$subjectId,$grade);
}
if($needAddClass){
foreach ($needAddClass as $cid){
$addTeacherClass[]="('".$cid."','".$teacherId."','".$this->semesterId."')";
}
}
}
if($classError){
Yii::app()->jump->error('以下老师的部分执教班级系统不存在,请核对后重新输入
'.implode('
',$classError));
}
if($directorCount){
foreach ($directorCount as $subject=>$val){
foreach ($val as $grade =>$num){
$has_3_posts = Teacher::model()->count('grade=:grade and posts=:posts and subjects=:subjects',
array(':grade'=> $grade, ':posts'=> 3, ':subjects'=> $subject));
if(($has_3_posts+$num)>6){
Yii::app()->jump->error('同学科,同年级最多可以创建6个年级主任账号');
}
}
}
}
$businessCommit=false;
if( $updateTeacherData || $busTeacherData) {
$schInsertSql='';
if($busTeacherData && $schoolTeacherData){
$busInsertSql = 'INSERT INTO xb_teacher (`teacher_id`, `phone_number`,`password`,`school_id`,`add_time`) VALUES ';
$schInsertSql = 'INSERT INTO teacher (`teacher_id`, `teacher_name`,`teacher_age`,`teacher_sex`,`add_time`,`coach_id`,`posts`,`title`,`subjects`,`grade`) VALUES ';
foreach($busTeacherData as $btVal){
$busInsertSql .= '('.implode(',',$btVal).'),';
}
foreach($schoolTeacherData as $stVal){
$schInsertSql .= '('.implode(',',$stVal).'),';
}
$busInsertSql = substr($busInsertSql,0,-1);
$schInsertSql = substr($schInsertSql,0,-1);
$busTran = $this->conn->beginTransaction();
try{
$this->conn->createCommand($busInsertSql)->execute();
$businessCommit=true;
}catch(Exception $e){
$busTran->rollBack();
Yii::app()->jump->error('教师批量上传失败!');
}
}
if($businessCommit || !$busTeacherData){
$transaction = $this->sConn->beginTransaction();
try{
if($schInsertSql){
$this->sConn->createCommand($schInsertSql)->execute();
}
if($updateTeacherData){
foreach ($updateTeacherData as $sql){
$this->sConn->createCommand($sql)->execute();
}
}
if($delOldTeacherClass){
foreach ($delOldTeacherClass as $sql){
$this->sConn->createCommand($sql)->execute();
}
}
if($addTeacherClass){
$insertTeacherClassRelationSql="insert into teacher_class_relation(`class_id`,`teacher_id`,`semester_id`) values ".implode(',',$addTeacherClass);
$this->sConn->createCommand($insertTeacherClassRelationSql)->execute();
}
if($businessCommit){
$busTran->commit();
}
$transaction->commit();
$url=$this->createUrl('/teacher/index');
$get_cookie = Yii::app()->request->getCookies();
$nowAction=strtolower($this->controller.'/'.$this->action);
if (isset($get_cookie['needMemoryAction']) && in_array($nowAction,Yii::app()->params['needMemoryAction'])) {
$url=$get_cookie['needMemoryAction'];
unset(Yii::app()->request->cookies['needMemoryAction']);
}
Yii::app()->jump->error('教师批量上传成功!',$url);
}catch(Exception $e){
if($businessCommit){
$busTran->rollBack();
}
$transaction->rollBack();
Yii::app()->jump->error('教师批量上传失败!');
}
}
}else{
Yii::app()->jump->error('教师批量上传失败!');
}
}
protected function myTrim($str)
{
$search = array(" "," ","\n","\r","\t");
$replace = array("","","","","");
return str_replace($search, $replace, $str);
}
//技术支持修改手机号功能
public function actionChange(){
$phone_number = safe_replace(Yii::app()->request->getPost('phone_number'));
if (Yii::app()->request->getIsPostRequest()) {
if(isset(Yii::app()->session['testFlag']) && (Yii::app()->session['testFlag']==1)){
if (!preg_match("/1[3456789]{1}\d{9}$/", $phone_number)) {
Yii::app()->jump->error('手机号格式有误!');
}
// 判断当前手机是否在当前学校已使用
$getPhone = BusinessTeacher::model()->find('phone_number=:phnum ', array(':phnum' => $phone_number));
if (!$getPhone) {
Yii::app()->jump->error('该手机号不存在!');
}elseif($getPhone->school_id==$this->schoolId){
Yii::app()->jump->error('该手机号已在当前学校注册!');
}
$allowChange=false;
$needle='1';
//校验修改后号码是否存在
for($i=1;$i<10;$i++){
$newPhoneNumber = substr_replace($phone_number,$i,strpos($phone_number,$needle),strlen($needle));
$checkNumber=BusinessTeacher::model()->find('phone_number=:phnum ', array(':phnum' => $newPhoneNumber));
if(!$checkNumber){
$allowChange=true;
break;
}
}
if(!$allowChange){
Yii::app()->jump->error('该手机号去重次数过多,不允许再次去重!');
}
if (BusinessTeacher::model()->updateAll(array('phone_number'=>$newPhoneNumber), "phone_number=:phone_number", array(":phone_number" => $phone_number))) {
Yii::app()->jump->error('手机号修改成功!');
}else{
Yii::app()->jump->error('手机号修改失败!');
}
}else{
Yii::app()->jump->error('请联系技术支持处理!');
}
}
$this->render('change');
}
public function actionGetTeacherForNumber()
{
$phone_number = safe_replace(Yii::app()->request->getPost('phone_number'));
if (!preg_match("/1[3456789]{1}\d{9}$/", $phone_number)) {
echo json_encode(array('status' => 1));
}
$teacher=BusinessTeacher::model()->find('phone_number=:phone_number', array(':phone_number' => $phone_number));
if($teacher){
if($teacher->school_id==$this->schoolId){
echo json_encode(array('status' => -1));
exit;
}else{
$schoolName='';
$teacherName='';
//查学校
$teacherSchool=BusinessSchool::model()->find('school_id=:sid',array(':sid'=>$teacher->school_id));
if($teacherSchool){
$schoolName=$teacherSchool->school_name;
}
//查询教师信息
$schoolConn=$this->getSchoolDbConnection($teacher->school_id);
if($schoolConn){
$teacherInfo=$this->getSchoolDbConnection($teacher->school_id)->createCommand("select teacher_name from teacher where teacher_id='{$teacher->teacher_id}'")->queryRow();
if($teacherInfo){
$teacherName=$teacherInfo['teacher_name'];
}
}
$data=array(
'schoolName'=>$schoolName,
'teacherName'=>$teacherName
);
exit(json_encode(array('status' => 0,'data'=>$data)));
}
}else{
exit(json_encode(array('status' => -2)));
}
}
/**
* 导出教师
*/
public function actionBatchImport(){
$realname = safe_replace(Yii::app()->request->getQuery('realname'));
$subject_id = safe_replace(Yii::app()->request->getQuery('subject_id'));
$class_id = safe_replace(Yii::app()->request->getQuery('class_id'));
$excel_title = '教师信息导出';
$condition = array();
// $condition[] = "(tcr.semester_id='{$this->semesterId}' or tcr.semester_id is null)";
$condition[] = "(c.is_hide=0 or c.is_hide is null)";
if($realname){
$condition[] = "t.teacher_name like '%{$realname}%'";
}
if($subject_id){
$condition[] = "t.subjects = {$subject_id}";
}
if($class_id){
$condition[] = "tcr.class_id = '{$class_id}'";
}
if($condition){
$condition = " where ".implode(" and ", $condition);
}else{
$condition = '';
}
$sql = "select t.*,GROUP_CONCAT(c.class_name SEPARATOR ';') class_name from teacher t "
. "left join teacher_class_relation tcr on t.teacher_id = tcr.teacher_id "
. "left join class c on c.class_id=tcr.class_id {$condition} "
. "group by t.teacher_id";
$teacher_data = $this->sConn->createCommand($sql)->queryAll();
if($teacher_data){
$teacher_phone = array();
$subjects_name = array();
$teacher_ids = _array_column($teacher_data, 'teacher_id');
$subject_ids = _array_column($teacher_data, 'subjects');
$sql = "select subject_id,subject_name from subject where subject_id in (".implode(',',$subject_ids).")";
$subjectInfo = $this->conn->createCommand($sql)->queryAll();
if($subjectInfo){
foreach($subjectInfo as $k=>$v){
$subjects_name[$v['subject_id']] = $v['subject_name'];
}
}
$sql = "select teacher_id,phone_number from xb_teacher where teacher_id in (".implode(',',$teacher_ids).")";
$teacherInfo = $this->conn->createCommand($sql)->queryAll();
if($teacherInfo){
foreach($teacherInfo as $val){
$teacher_phone[$val['teacher_id']] = $val['phone_number'];
}
}
foreach($teacher_data as $k=>$v){
//查询班级
$classNames=array();
$teacherClass=$this->sConn->createCommand("select class_name from teacher_class_relation tcr left join class c on c.class_id=tcr.class_id where tcr.teacher_id='{$v['teacher_id']}' and c.semester_id='{$this->semesterId}'")->queryAll();
if($teacherClass){
foreach ($teacherClass as $c){
$classNames[]=$c['class_name'];
}
$teacher_data[$k]['class_name']=implode(',',$classNames);
}else{
$teacher_data[$k]['class_name']='';
}
$teacher_data[$k]['phone_number'] = '';
if(isset($teacher_phone[$v['teacher_id']])){
$teacher_data[$k]['phone_number'] = $teacher_phone[$v['teacher_id']];
}
$teacher_data[$k]['subject_name'] = '';
if(isset($subjects_name[$v['subjects']])){
$teacher_data[$k]['subject_name'] = $subjects_name[$v['subjects']];
}
$teacher_data[$k]['posts_name'] = '';
if($v['posts'] == 1){
$teacher_data[$k]['posts_name'] = '班主任';
}else if($v['posts'] == 2){
$teacher_data[$k]['posts_name'] = '教研组长';
}else if($v['posts'] == 3){
$teacher_data[$k]['posts_name'] = '年级主任';
}else if($v['posts'] == 4){
$teacher_data[$k]['posts_name'] = '任课教师';
}else if($v['posts'] == 5){
$teacher_data[$k]['posts_name'] = '校长';
}
$teacher_data[$k]['title_name'] = '';
if($v['title'] == 1){
$teacher_data[$k]['title_name'] = '一级教师';
}else if($v['title'] == 2){
$teacher_data[$k]['title_name'] = '二级教师';
}else if($v['title'] == 3){
$teacher_data[$k]['title_name'] = '三级教师';
}else if($v['title'] == 4){
$teacher_data[$k]['title_name'] = '高级教师';
}
$teacher_data[$k]['teacher_sex_name'] = '';
if($v['teacher_sex'] == 1){
$teacher_data[$k]['teacher_sex_name'] = '女';
}else{
$teacher_data[$k]['teacher_sex_name'] = '男';
}
if($v['posts'] == 3){
if(!$v['grade']){
$teacher_data[$k]['grade_name'] = '年级未识别,请手动调整';
}else{
$teacher_data[$k]['grade_name'] = $v['grade'];
}
}else{
$teacher_data[$k]['grade_name'] = '';
}
}
// debug($teacherInfo);
}
if($teacher_data){
$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties()->setCreator("ctos")
->setLastModifiedBy("ctos")
->setTitle("教师信息")
->setSubject("教师信息")
->setDescription("导出教师信息")
->setKeywords("excel")
->setCategory("result file");
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(15);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(15);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(10);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(15);
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(40);
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(10);
$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(10);
$objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(10);
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', '*教师姓名')
->setCellValue('B1', '*登录手机号')
->setCellValue('C1', '*学科')
->setCellValue('D1', '*岗位')
->setCellValue('E1', '职称')
->setCellValue('F1', '执教班级')
->setCellValue('G1', '教龄')
->setCellValue('H1', '性别')
->setCellValue('I1', '年级');
$i = 2;
foreach($teacher_data as $key=>$val){
$objPHPExcel->getActiveSheet(0)->setCellValue('A' . $i, $val['teacher_name']);
$objPHPExcel->getActiveSheet(0)->setCellValue('B' . $i, $val['phone_number']);
$objPHPExcel->getActiveSheet(0)->setCellValue('C' . $i, $val['subject_name']);
$objPHPExcel->getActiveSheet(0)->setCellValue('D' . $i, $val['posts_name']);
$objPHPExcel->getActiveSheet(0)->setCellValue('E' . $i, $val['title_name']);
$objPHPExcel->getActiveSheet(0)->setCellValue('F' . $i, $val['class_name']);
$objPHPExcel->getActiveSheet(0)->setCellValue('G' . $i, $val['teacher_age']);
$objPHPExcel->getActiveSheet(0)->setCellValue('H' . $i, $val['teacher_sex_name']);
$objPHPExcel->getActiveSheet(0)->setCellValue('I' . $i, $val['grade_name']);
$i++;
}
$objPHPExcel->setActiveSheetIndex(0);
ob_end_clean(); // Added by me
header("Accept-Ranges:bytes");
header("Content-type:application/vnd.ms-excel;charset=UTF-8");
header('Content-Disposition:attachment;filename="'.$excel_title.'.xls"');
header('Cache-Control:max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit;
}else{
Yii::app()->jump->error('导出失败,无教师数据',Yii::app()->createUrl('teacher/index'));
}
debug($teacher_data);
}
}