request->getQuery('class_id'));
$grade_id = safe_replace(Yii::app()->request->getQuery('grade_id'));
$realname = safe_replace(Yii::app()->request->getQuery('realname'));
$semester_id = safe_replace(Yii::app()->request->getQuery('semester_id'));
$search_type = safe_replace(Yii::app()->request->getQuery('search_type'));
$where = '';
if ($realname) {
if($search_type==1)
{
$condition = array("stu.realname like '%{$realname}%'");
}else if($search_type==2)
{
$where = "school_id=".$this->schoolId." and username = '".$realname."'";
}else if($search_type==3)
{
$realname = (int)$realname;
$where = 'school_id='.$this->schoolId.' and student_card = '.$realname;
}else if($search_type==4)
{
$where = "school_id=".$this->schoolId." and school_student_card = '".$realname."'";
}else if($search_type==5)
{
$realname = (int)$realname;
$where = 'school_id='.$this->schoolId.' and zhixue_student_card = '.$realname;
}else{
$field_array=array('field_1','field_2','field_3','field_4','field_5');
if(in_array($search_type,$field_array)){
$condition = array(" `".$search_type."`='".$realname."'");
}
}
}
$grade_class_array = array();
$sort = '';
if (isset($_GET['sort'])) {
$sort = safe_replace(Yii::app()->request->getQuery('sort'));
}
if ($grade_id) {
$grade_class_data = ClassModel::model()->findAll('grade=:grade and semester_id=:semester_id and class_type=1', array(':grade' => $grade_id, ':semester_id' => $this->semesterId));
if ($grade_class_data) {
foreach ($grade_class_data as $v) {
$grade_class_array[$v->class_id] = $v->attributes;
}
}
array_push($condition, "c.grade=" . $grade_id);
}
array_push($condition, "c.class_type=1" );
if (empty($semester_id)) {
$smid = Yii::app()->session['session_semester_id'];
} else {
$smid = $semester_id;
}
$classes = $this->schoolManager->getClasses();
$resultClass = Arr::toObj($classes);
if (empty($class_id) && $classes) {
foreach ($classes as $v) {
$class_ids[$v['class_id']] = $v['class_id'];
}
$rs = $this->schoolManager->getClassStudentsListWithAccounts($class_ids, $condition, 20,$where);
} else {
$rs = $this->schoolManager->getClassStudentsListWithAccounts($class_id, $condition, 20,$where);
}
$userList = $rs["rs"];
$studentClass=array();
$studentIds=array();
if($rs["rs"]){
foreach ($rs["rs"] as $key =>$val){
$studentIds[]=$val['student_id'];
}
//查询所有走班
$studentClass=$this->schoolManager->getAllClassByStudentId($studentIds);
}
$data = array();
// 处理学生按学号排序
if ($sort == 1) {
$sort = 2;
} elseif ($sort == 2) {
$sort = 1;
}
// 获取所有学期
//$data['allSemester']= Semester::model()->findAll();
//扩展字段
$studentExtend=$this->schoolManager->getStudentExtend();
$data['studentExtend']=$studentExtend;
$data['grade_id'] = $grade_id;
$data['userList'] = $userList;
$data['pages'] = $rs['pager'];
$data['page_total'] = $rs['pager']->rowsCount;
$data['class_id'] = $class_id;
$data['search_type'] = $search_type;
$data['realname'] = $realname;
$data['grade_class'] = $grade_class_array;
$data['semester_id'] = $smid;
$data['classInfo'] = $resultClass;
$data['sort'] = $sort;
$data['calssName'] = ClassModel::model()->getClassName($class_id);
$data['student_class'] = $studentClass;
if (isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue)) {
$data["use_zhixue"] = $this->schoolInfo->use_zhixue;
} else {
$data["use_zhixue"] = 0;
}
unset($resultClass, $classes);
$this->render('index', $data);
}
public function actionClassstu()
{
$orderid = Yii::app()->request->getParam('orderid');
$cid = Yii::app()->request->getParam('cid');
$classname = ClassModel::model()->find('class_id=:cid', array(":cid" => $cid));
$order_data = CMSOrder::model()->find('id=:id',array(':id'=>$orderid));
if($order_data->classify!=2){
$stu = CMSOrderStudent::model()->findAll("order_id =:orderid and clazz_id=:cid", array(":orderid" => $orderid, ":cid" => $cid));
}else{
$stu = SStudentInfo::model()->findAll("class_id=:cid", array(":cid" => $cid));
}
$this->render("stuinfo", array("stu" => $stu, "classname" => $classname));
}
// 添加学生
public function actionAdd()
{
checkAuthority(2); // 非当前使用学期无法操作
if (Yii::app()->request->getIsPostRequest()) {
$redis_add_student_status = Yii::app()->add_student_status->hmget('add_students_status_'.$this->schoolId,array('status'));
if($redis_add_student_status && $redis_add_student_status[0]){
Yii::app()->jump->error('请稍后再试!');
}
Yii::app()->add_student_status->hmset('add_students_status_'.$this->schoolId,array('status'=>1));
Yii::app()->add_student_status->expire('add_students_status_'.$this->schoolId,10);
$realname = Yii::app()->request->getPost('realname');
$class_id = Yii::app()->request->getPost('class_id');
$userno = Yii::app()->request->getPost('userno');
$sex = Yii::app()->request->getPost('sex');
$school_student_card = (string)Yii::app()->request->getPost('school_student_card');
$is_outer = Yii::app()->request->getPost('is_outer');
$id_number = Yii::app()->request->getPost('id_number');
//扩展设置
$field_1=-1;
$field_2=-1;
$field_3=-1;
$field_4=-1;
$field_5=-1;
$regex = '/^[a-zA-Z0-9]+$/u';
$studentExtend=$this->schoolManager->getStudentExtend();
if($studentExtend){
foreach($studentExtend as $key=>$val){
if($val['is_enable']==1){
$check_field_value=Yii::app()->request->getPost($key);
if($check_field_value && !preg_match($regex, $check_field_value)){
Yii::app()->jump->error('自定义考号内容只能是数字和字母');
}
$$key=$check_field_value;
}
}
}
//验证身份证
if($id_number){
$check_id_number=$this->sConn->createCommand("select student_id from student_info where id_number='".$id_number."'")->queryRow();
if($check_id_number){
Yii::app()->jump->error('身份证号已存在!');
}
}
/**
* 学校准考证号
*/
$class_data = ClassModel::model()->find('class_id=:class_id',array(':class_id'=>$class_id));
/**
* 智学网准考证号
*/
if (isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue)) {
$zhixue_student_card = (string)Yii::app()->request->getPost('zhixue_student_card');
if ($zhixue_student_card) {
if(!is_numeric($zhixue_student_card)){
Yii::app()->jump->error('智学网准考证号格式不正确!');
}
$b_student_data = BusinessStudent::model()->find(array('select'=>array('student_id'),'condition'=>'school_id =:school_id and zhixue_student_card=:zhixue_student_card','params'=>array(':school_id'=>$this->schoolId,':zhixue_student_card' => $zhixue_student_card)));
if ($b_student_data) {
Yii::app()->jump->error('智学网准考证号已存在!');
}
}
} else {
$zhixue_student_card = '';
}
if($school_student_card)
{
if(!is_numeric($school_student_card)){
Yii::app()->jump->error('学校准考证号格式不正确!');
}
$semester_class_data = ClassModel::model()->findAll('semester_id=:semester_id', array(':semester_id' => $this->semesterId));
if ($semester_class_data)
{
foreach ($semester_class_data as $v)
{
$class_ids[$v->class_id] = $v->class_id;
}
}
$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)
{
$s_student_ids = array();
}else
{
foreach($semester_student_class_data as $v)
{
$s_student_ids[$v->student_id] = $v->student_id;
}
}
unset($criteria);
$criteria = new CDbCriteria();
$criteria->select = 'student_id,school_student_card';
$criteria->addCondition('school_id=:school_id');
$criteria->addInCondition('student_id',$s_student_ids);
$criteria->params[':school_id'] = $this->schoolId;
$s_student_data = BusinessStudent::model()->findAll($criteria);
if($s_student_data)
{
foreach($s_student_data as $v)
{
$school_student_studentId[$v->school_student_card] = $v->student_id;
}
}
unset($s_student_data);
if(isset($school_student_studentId[$school_student_card]) && !empty($school_student_studentId[$school_student_card]) )
{
Yii::app()->jump->error('学校准考证号已存在!');
}
/**
* 获取班级信息
*/
$_school_student_card = '';
$_school_student_status = 0;
$grade_data = SGradeModel::model()->findAll();
if($class_data && $grade_data)
{
foreach($grade_data as $v)
{
if($class_data->grade == $v->id)
{
$_school_student_card = $v->card_length;
$_school_student_status = $v->card_status;
}
}
if($_school_student_status)
{
if($_school_student_card)
{
if(strlen((string)$school_student_card) != $_school_student_card)
{
Yii::app()->jump->error('准考证长度与学校设置长度不一致!');
}
}else
{
Yii::app()->jump->error('学校未设置准考证位数,请到学校管理中设置');
}
}
}
}
$telephone = 0;
$serial_number = 1;
$student_phone = Yii::app()->request->getPost('student_phone');
if (empty($realname) || empty($class_id)) {
Yii::app()->jump->error('请确认学生个人信息是否填写完整!');
}
if ($class_data) {
$semester_class_data = ClassModel::model()->findAll('semester_id=:semester_id', array(':semester_id' => $class_data->semester_id));
if ($semester_class_data) {
foreach ($semester_class_data as $v) {
$class_ids[$v->class_id] = $v->class_id;
}
}
}
if (!$class_ids) {
Yii::app()->jump->error('不在当前学期!');
}
$student_class_data = SStudentClassRelation::model()->find(array(
'select' => 'serial_number',
'order' => 'serial_number desc',
'condition' => 'class_id=:class_id and status=:status',
'limit' => 1,
'params' => array(':class_id' => $class_id, ':status' => 0)
));
if ($student_class_data) {
if ($student_class_data->serial_number) {
$serial_number = $student_class_data->serial_number + 1;
}
}
/*
$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)
));
*/
$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();
$student_cart = 0;
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'] + 1;
}
} else {
if ($this->schoolId < 100) {
$student_cart = '9' . $this->schoolId . '00100';
} else {
$student_cart = $this->schoolId . '00100';
}
}
if($id_number){
$student_all_data = $this->sConn->createCommand("SELECT student_id FROM `student_info` `t` WHERE class_id IN (" . implode(',', $class_ids) . ") and realname='" . $realname . "' and id_number='".$id_number."'")->queryAll();
}else{
$student_all_data = $this->sConn->createCommand("SELECT student_id FROM `student_info` `t` WHERE class_id IN (" . implode(',', $class_ids) . ") and realname='" . $realname . "'")->queryAll();
}
//unset($criteria);
$student_data = array();
if ($student_all_data) {
if (count($student_all_data) > 1) {
$_student_ids = array();
foreach($student_all_data as $v)
{
$_student_ids[$v['student_id']] = $v['student_id'];
}
$criteria = new CDbCriteria();
$criteria->addInCondition('student_id',$_student_ids);
$criteria->addCondition('status=:status');
$criteria->params[':status'] = 0;
$student_c_r = SStudentClassRelation::model()->findAll($criteria);
if($student_c_r)
{
Yii::app()->jump->error('已经存在此学生!');
}
}
foreach ($student_all_data as $v) {
$student_data = $v;
}
$student_class_data = SStudentClassRelation::model()->find('student_id=:student_id and status=:status', array(':student_id' => $student_data['student_id'], ':status' => 0));
if ($this->schoolId == Yii::app()->session['coachInfo']['school_id']) {
if ($student_class_data) {
Yii::app()->jump->error('创建学生失败,学生账号已存在!');
}
$_serial_number_data = SStudentClassRelation::model()->find('class_id=:class_id and status=:status and serial_number=:serial_number', array(':class_id' => $class_id, ':status' => 0, ':serial_number' => $serial_number));
if ($_serial_number_data) {
Yii::app()->jump->error('班级序号已存在!');
}
// $b_student_one_data = BusinessStudent::model()->find(array(
// 'select' => 'student_card',
// 'condition' => 'school_id=:school_id and student_card=:student_card',
// 'params' => array(':school_id' => $this->schoolId,':student_card'=>$student_cart)
// ));
// if($b_student_one_data){
// Yii::app()->jump->error('生成的学生准考证号已存在,请重新添加!');
// }
// $b_student_one_data = BusinessStudent::model()->find(array(
// 'select' => 'student_card',
// 'condition' => 'school_id=:school_id and username=:username',
// 'params' => array(':school_id' => $this->schoolId,':username'=>$student_cart)
// ));
// if($b_student_one_data){
// Yii::app()->jump->error('生成的学生准考证号已存在,请重新添加!');
// }
$b_student_one_data = BusinessStudent::model()->find(array(
'select' => 'student_card',
'condition' => 'student_card=:student_card ',
'params' => array(':student_card'=>$student_cart)
));
if($b_student_one_data){
Yii::app()->jump->error('生成的学生准考证号已存在,请重新添加!');
}else{
$b_student_one_data = BusinessStudent::model()->find(array(
'select' => 'student_card',
'condition' => 'username=:username',
'params' => array(':username'=>$student_cart)
));
if($b_student_one_data){
Yii::app()->jump->error('生成的学生准考证号已存在,请重新添加!');
}
}
// $studentId = getUUID();
$studentId = getUniqueId($this->schoolId);
// 判断登录账号是否已存在
//if (BusinessStudent::model()->count('username=:name and status=0',array(':name'=>$username))) {
// throw new CException('登录账号已存在!');
//}
// 将学生登录账号插入主数据
$studentModel = new BusinessStudent();
$studentModel->username = $student_cart;
$studentModel->password = md5(sha1($student_cart . 'wy') . 'fengche');
$studentModel->school_id = Yii::app()->session['coachInfo']['school_id'];
$studentModel->student_id = $studentId;
$studentModel->student_card = $student_cart;
$studentModel->school_student_card = $school_student_card;
if (isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue)) {
$studentModel->zhixue_student_card = $zhixue_student_card;
}
$studentModel->register_time = time();
if (!$studentModel->save()) {
throw new CException('主数据库录入信息失败!');
}
$transaction = StudentInfo::model()->dbConnection->beginTransaction();
try {
// 学校库插入学生基本信息
$userModel = new StudentInfo();
$studentToClass = new StudentToClass();
$userModel->student_id = $studentId;
$userModel->realname = $realname;
$userModel->school_id = Yii::app()->session['coachInfo']['school_id'];
$userModel->class_id = $class_id;
$userModel->add_time = time();
$userModel->update_time = time();
$userModel->sex = $sex;
$userModel->is_outer = $is_outer;
$userModel->student_phone = $student_phone;
if($id_number){
$userModel->id_number = $id_number;
}
//扩展数据
if($field_1!=-1){
$userModel->field_1 = $field_1;
}
if($field_2!=-1){
$userModel->field_2 = $field_2;
}
if($field_3!=-1){
$userModel->field_3 = $field_3;
}
if($field_4!=-1){
$userModel->field_4 = $field_4;
}
if($field_5!=-1){
$userModel->field_5 = $field_5;
}
$studentToClass->userno = $userno;
$studentToClass->serial_number = $serial_number;
$studentToClass->student_id = $studentId;
$studentToClass->update_time = time();
$studentToClass->class_id = $class_id;
if (!$userModel->save() || !$studentToClass->save()) {
Yii::app()->jump->error('学校数据库录入失败!');
}
// 创建学生与班级关联关系
/*$studentClass = new StudentToClass();
$studentClass->class_id = $class_id;
$studentClass->student_id = $studentId;
if (!$studentClass->save()) {
Yii::app()->jump->error('创建学生与班级关系失败!');
}*/
$transaction->commit();
} catch (Exception $e) {
//如果操作失败, 数据回滚
$transaction->rollback();
Yii::app()->jump->error('创建学生失败!');
}
} else {
Yii::app()->jump->error('登录账号已在其他学校使用!');
}
} else {
// $b_student_one_data = BusinessStudent::model()->find(array(
// 'select' => 'student_card',
// 'condition' => 'school_id=:school_id and student_card=:student_card',
// 'params' => array(':school_id' => $this->schoolId,':student_card'=>$student_cart)
// ));
// if($b_student_one_data){
// Yii::app()->jump->error('生成的学生准考证号已存在,请重新添加!');
// }
// $b_student_one_data = BusinessStudent::model()->find(array(
// 'select' => 'student_card',
// 'condition' => 'school_id=:school_id and username=:username',
// 'params' => array(':school_id' => $this->schoolId,':username'=>$student_cart)
// ));
// if($b_student_one_data){
// Yii::app()->jump->error('生成的学生准考证号已存在,请重新添加!');
// }
$b_student_one_data = BusinessStudent::model()->find(array(
'select' => 'student_card',
'condition' => 'username=:username',
'params' => array(':username'=>$student_cart)
));
if($b_student_one_data){
Yii::app()->jump->error('生成的学生准考证号已存在,请重新添加!');
}else{
$b_student_one_data = BusinessStudent::model()->find(array(
'select' => 'student_card',
'condition' => 'student_card=:student_card',
'params' => array(':student_card'=>$student_cart)
));
if($b_student_one_data){
Yii::app()->jump->error('生成的学生准考证号已存在,请重新添加!');
}
}
// 创建学生事务
//$transaction = Yii::app()->db->beginTransaction();
//$studentId = getUUID();
$studentId=getUniqueId($this->schoolId);
// 判断登录账号是否已存在
//if (BusinessStudent::model()->count('username=:name and status=0',array(':name'=>$username))) {
// throw new CException('登录账号已存在!');
//}
// 将学生登录账号插入主数据
$studentModel = new BusinessStudent();
$studentModel->username = $student_cart;
$studentModel->password = md5(sha1($student_cart . 'wy') . 'fengche');
$studentModel->school_id = Yii::app()->session['coachInfo']['school_id'];
$studentModel->student_id = $studentId;
$studentModel->student_card = $student_cart;
$studentModel->school_student_card = $school_student_card;
if (isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue)) {
$studentModel->zhixue_student_card = $zhixue_student_card;
}
$studentModel->register_time = time();
if (!$studentModel->save()) {
throw new CException('主数据库录入信息失败!');
}
$transaction = StudentInfo::model()->dbConnection->beginTransaction();
try {
// 学校库插入学生基本信息
$userModel = new StudentInfo();
$studentToClass = new StudentToClass();
$userModel->student_id = $studentId;
$userModel->realname = $realname;
$userModel->school_id = Yii::app()->session['coachInfo']['school_id'];
$userModel->class_id = $class_id;
$userModel->add_time = time();
$userModel->update_time = time();
$userModel->sex = $sex;
$userModel->is_outer = $is_outer;
$userModel->student_phone = $student_phone;
if($id_number){
$userModel->id_number = $id_number;
}
$studentToClass->userno = $userno;
$studentToClass->serial_number = $serial_number;
$studentToClass->student_id = $studentId;
$studentToClass->update_time = time();
$studentToClass->class_id = $class_id;
if (!$userModel->save() || !$studentToClass->save()) {
Yii::app()->jump->error('学校数据库录入失败!');
}
$transaction->commit();
} catch (Exception $e) {
//如果操作失败, 数据回滚
$transaction->rollback();
Yii::app()->jump->error('创建学生失败!');
}
}
Yii::app()->add_student_status->del('add_students_status_'.$this->schoolId);
$this->redirect(array('studentinfo/index'));
}
$data = array();
$cid = safe_replace(Yii::app()->request->getQuery('cid'));
$cname = ClassModel::model()->getClassName($cid);
// 获取当前学校班级
$getClass = ClassModel::model()->findAll('semester_id="' . Yii::app()->session['session_semester_id'] . '" and class_type=1 and is_hide=0');
$resultClass = $getClass;
if (Yii::app()->session['coachInfo']['leader'] != 1) {
$resultClass = array();
$coachClass = $this->schoolManager->getCoachClassesRelations($this->coachId, "OBJ");
foreach ($getClass as $t) {
foreach ($coachClass as $tt) {
if ($t->class_id == $tt->class_id) {
$resultClass[] = $t;
}
}
}
}
$data['cid'] = $cid;
$data['cname'] = $cname;
$data['classInfo'] = $resultClass;
if (isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue)) {
$data['use_zhixue'] = $this->schoolInfo->use_zhixue;
} else {
$data['use_zhixue'] = 0;
}
//判断扩展字段设置
$studentExtend=$this->schoolManager->getStudentExtend();
if(!$studentExtend){
$studentExtend=$this->schoolManager->setDefaultStudentExtend();
}
$data['studentExtend']=$studentExtend;
unset($transaction, $getClass);
$this->render('add2', $data);
}
// 编辑学生
public function actionEdit()
{
checkAuthority(2); // 非当前使用学期无法操作
$studentId = safe_replace(Yii::app()->request->getQuery('stid'));
if (empty($studentId)) {
Yii::app()->jump->error('您访问的页面不存在!');
}
// 学生信息
$userInfo = StudentInfo::model()->find('student_id=:stid', array(':stid' => $studentId));
$studentInfo = $this->schoolManager->getStudentInfo($studentId, "OBJ");
if (empty($userInfo) || empty($studentInfo)) {
Yii::app()->jump->error('未找到该学生信息!');
}
// 获取学生登录名密码等
$studentAccount = BusinessStudent::model()->find('student_id=:stid', array(':stid' => $studentId));
if (empty($studentAccount)) {
Yii::app()->jump->error('未找到该学生信息!');
}
if (Yii::app()->request->getIsPostRequest()) {
$class_ids = array();
$username = safe_replace(Yii::app()->request->getPost('username'));
$password = safe_replace(Yii::app()->request->getPost('password'));
$password2 = safe_replace(Yii::app()->request->getPost('password2'));
$school_student_card = safe_replace(Yii::app()->request->getPost('school_student_card'));
$is_outer = safe_replace(Yii::app()->request->getPost('is_outer'));
$class_id = safe_replace(Yii::app()->request->getPost('class_id'));
$status = safe_replace(Yii::app()->request->getPost('status'));
$logoutStatus = safe_replace(Yii::app()->request->getPost('logout_status'));
$id_number = safe_replace(Yii::app()->request->getPost('id_number'));
$id_number = Yii::app()->request->getPost('id_number');
//扩展设置
$field_1=-1;
$field_2=-1;
$field_3=-1;
$field_4=-1;
$field_5=-1;
$regex = '/^[a-zA-Z0-9]+$/u';
$studentExtend=$this->schoolManager->getStudentExtend();
if($studentExtend){
foreach($studentExtend as $key=>$val){
if($val['is_enable']==1){
$check_field_value=Yii::app()->request->getPost($key);
if($check_field_value && !preg_match($regex, $check_field_value)){
Yii::app()->jump->error('自定义考号内容只能是数字和字母');
}
$$key=$check_field_value;
}
}
}
//验证身份证
if($id_number){
$check_id_number=$this->sConn->createCommand("select student_id from student_info where id_number='".$id_number."' and student_id <>'".$studentId."'")->queryRow();
if($check_id_number){
Yii::app()->jump->error('身份证号已存在!');
}
}
/**
* 学校班级信息
*/
$class_data = ClassModel::model()->find('class_id=:class_id',array(':class_id'=>$class_id));
/**
* 智学网准考证号
*/
if (isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue)) {
$zhixue_student_card = safe_replace(Yii::app()->request->getPost('zhixue_student_card'));
if ($zhixue_student_card) {
if(!is_numeric($zhixue_student_card)){
Yii::app()->jump->error('智学网准考证号格式不正确!');
}
$b_student_data = BusinessStudent::model()->findAll('school_id =:school_id and zhixue_student_card=:zhixue_student_card', array(':school_id'=>$this->schoolId,':zhixue_student_card' => $zhixue_student_card));
if ($b_student_data && $studentAccount->zhixue_student_card != $zhixue_student_card) {
Yii::app()->jump->error('智学网准考证号已存在!');
}
}
} else {
$zhixue_student_card = '';
}
/**
* 学校准考证号
*/
$semester_class_data = ClassModel::model()->findAll('semester_id=:semester_id', array(':semester_id' => $this->semesterId));
if ($semester_class_data)
{
foreach ($semester_class_data as $v)
{
$class_ids[$v->class_id] = $v->class_id;
}
}
$s_student_ids = array();
$school_student_studentId = array();
if($school_student_card)
{
if(!is_numeric($school_student_card)){
Yii::app()->jump->error('学校准考证号格式不正确!');
}
$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)
{
$s_student_ids = array();
}else
{
foreach($semester_student_class_data as $v)
{
$s_student_ids[$v->student_id] = $v->student_id;
}
}
unset($semester_student_class_data);
unset($criteria);
$criteria = new CDbCriteria();
$criteria->addInCondition('student_id',$s_student_ids);
$criteria->addCondition('school_student_card=:school_student_card');
$criteria->params[':school_student_card'] = $school_student_card;
$s_student_data = BusinessStudent::model()->findAll($criteria);
if($s_student_data)
{
foreach($s_student_data as $v)
{
$school_student_studentId[(string)$v->student_id] = $v->student_id;
}
}
unset($criteria);
unset($s_student_ids);
unset($s_student_data);
//print_r($school_student_studentId)
if($school_student_studentId)
{
if(!isset($school_student_studentId[(string)$studentId]) )
{
Yii::app()->jump->error('学校准考证号已存在!');
}
}
unset($school_student_studentId);
/**
* 获取班级信息
*/
$_school_student_card = '';
$_school_student_status = 0;
$grade_data = SGradeModel::model()->findAll();
if($class_data && $grade_data)
{
foreach($grade_data as $v)
{
if($class_data->grade == $v->id)
{
$_school_student_card = $v->card_length;
$_school_student_status = $v->card_status;
}
}
if($_school_student_status)
{
if($_school_student_card)
{
if(strlen((string)$school_student_card) != $_school_student_card)
{
Yii::app()->jump->error('准考证长度与学校设置长度不一致!');
}
}else
{
Yii::app()->jump->error('学校未设置准考证位数,请到学校管理中设置');
}
}
}
}
$realname = Yii::app()->request->getPost('realname');
$serial_number = Yii::app()->request->getPost('serial_number');
$userno = Yii::app()->request->getPost('userno');
$sex = Yii::app()->request->getPost('sex');
$is_outer = Yii::app()->request->getPost('is_outer');
$student_phone = Yii::app()->request->getPost('student_phone');
if (!$class_ids)
{
Yii::app()->jump->error('不在当前学期!');
}
if (empty($realname))
{
Yii::app()->jump->error('请确认学生信息是否填写完整!');
}
$class_ids = array_merge($class_ids);
if($id_number){
$student_info_data = $this->sConn->createCommand("SELECT * FROM `student_info` `t` WHERE class_id IN (" . implode(',', $class_ids) . ") and realname='" . $realname . "' and id_number='".$id_number."'")->queryAll();
}else{
$student_info_data = $this->sConn->createCommand("SELECT * FROM `student_info` `t` WHERE class_id IN (" . implode(',', $class_ids) . ") and realname='" . $realname . "'")->queryAll();
}
if ($student_info_data)
{
if (count($student_info_data) > 1)
{
$student_ids = array();
foreach($student_info_data as $v)
{
$student_ids[$v['student_id']] = $v['student_id'];
}
$criteria = new CDbCriteria();
$criteria->addInCondition('student_id',$student_ids);
$criteria->addCondition('status=0');
$student_class_datas = SStudentClassRelation::model()->findAll($criteria);
if( count($student_class_datas)>1)
{
Yii::app()->jump->error('学生真实姓名已经存在');
}
if($student_class_datas && $student_class_datas[0]['student_id']!=$studentId)
{
Yii::app()->jump->error('学生真实姓名已经存在');
}
unset($student_class_datas);
} else
{
$student_class_datas = SStudentClassRelation::model()->find('student_id=:student_id and status=:status',array(':student_id'=>$student_info_data[0]['student_id'],':status'=>0));
if($student_class_datas)
{
if ($student_info_data[0]['student_id'] != $studentId)
{
Yii::app()->jump->error('学生真实姓名已经存在');
}
}
}
}
$serial_number_student_class = SStudentClassRelation::model()->find('class_id=:class_id and serial_number=:serial_number and status=:status', array(':class_id' => $class_id, ':serial_number' => $serial_number, ':status' => 0));
if ($serial_number_student_class)
{
$student_number_student_class = SStudentClassRelation::model()->find('class_id=:class_id and student_id=:student_id and serial_number=:serial_number and status=:status', array(':class_id' => $class_id, ':student_id' => $studentId, ':serial_number' => $serial_number, ':status' => 0));
if (!$student_number_student_class)
{
Yii::app()->jump->error('班级序号已经存在');
}
unset($student_number_student_class);
}
// 创建学生事务
$_password = '';
$update_arr = array();
// 更新主库学生登录账号信息
if (!empty($password) && !empty($password2))
{
if ($password != $password2)
{
Yii::app()->jump->error('两次密码输入不一致!');
} else
{
$_password = md5(sha1($password . 'wy') . 'fengche');
}
$update_arr['password'] = $_password;
//更新密码,清除缓存
$studentLoginKey='zsy:login_verify_token_'.$studentId;
$studentZBKLoginKey='zbk:login_verify_token_'.$studentId;
$server = Yii::app()->params["student_login_cache"]["servers"];
$redis = new Redis();
foreach ($server as $value){
$redis->connect($value["hostname"], $value["port"]);
if(isset($value['password'])){
$redis->auth($value['password']);
}
$redis->select($value['database']);
$redis->del($studentLoginKey);
$redis->del($studentZBKLoginKey);
}
}
$update_arr['zhixue_student_card'] = $zhixue_student_card;
$update_arr['school_student_card'] = $school_student_card;
$update_arr['status'] = $status;
$update_arr['logout_status'] = $logoutStatus;
if (false === (BusinessStudent::model()->updateAll($update_arr, 'student_id=:stid', array(':stid' => $studentId)))) {
Yii::app()->jump->error('主数据库更新失败!');
}
//更新REDIS
Yii::app()->redis_business_student->del('redis_business_del_student:'.$this->schoolId);
$transaction = $studentAccount->dbConnection->beginTransaction();
try {
$updateArr=array(
'realname' => $realname,
'student_phone' => $student_phone,
'sex' => $sex,
'is_outer' => $is_outer,
'update_time' => time(),
'id_number'=>$id_number
);
//扩展数据
if($field_1!=-1){
$updateArr['field_1'] = $field_1;
}
if($field_2!=-1){
$updateArr['field_2'] = $field_2;
}
if($field_3!=-1){
$updateArr['field_3'] = $field_3;
}
if($field_4!=-1){
$updateArr['field_4'] = $field_4;
}
if($field_5!=-1){
$updateArr['field_5'] = $field_5;
}
SStudentInfo::model()->updateAll($updateArr, 'student_id=:stid', array(':stid' => $studentId));
SStudentClassRelation::model()->updateAll(array(
'userno' => $userno, 'serial_number' => $serial_number
), 'student_id=:student_id and class_id =:class_id', array(':student_id' => $studentId, ':class_id' => $class_id));
$transaction->commit();
if(Yii::app()->params['handle_log_on_off'])
{
writeFileLog(jsonEncode(array(
"student_id" => $studentId,
"operate_project" => 'zsyas2',
"school_id" => $this->schoolId,
"title" => '编辑学生',
"operate_account" => Yii::app()->session['coachInfo']['coach_name'],
"operate_method" => $this->action,
"operate_url" => $this->getRoute(),
"operate_sql" =>'',
"operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
"date"=>date('Y-m-d H:i:s')
)));
}
} catch (Exception $e) {
//如果操作失败, 数据回滚
$transaction->rollback();
Yii::app()->jump->error('编辑学生失败!');
}
$this->redirect(array('studentinfo/index'));
};
//$this->redirect(array('studentinfo/index'));
$data = array();
// 获取当前学校班级
$data['classInfo'] = ClassModel::model()->findAll('semester_id="' . Yii::app()->session['session_semester_id'] . '" and is_hide=0');
$studentClass=SStudentClassRelation::model()->find('student_id=:sid and status=:status and class_type=1', array(':sid' => $studentId, ':status' => 0));
$data['studentClass']=$studentClass->class_id;
$data['userInfo'] = $studentInfo;
$data['studentInfo'] = $studentAccount;
$data["studentId"] = $studentId;
if (isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue)) {
$data['use_zhixue'] = $this->schoolInfo->use_zhixue;
} else {
$data['use_zhixue'] = 0;
}
//$data['use_zhixue'] = $this->schoolInfo->use_zhixue;
//判断扩展字段设置
$data['studentExtend']=$this->schoolManager->getStudentExtend();
//判断学校是否设置平板登陆权限
$school_data = BusinessSchool::model()->find("school_id=:sid",array(':sid'=>Yii::app()->session['coachInfo']['school_id']));
$data['is_login_permission'] = $school_data['is_login_permission'];
// $stu_login_id = Yii::app()->stu_login_permission->getValue('zsy_student:student_app_unique_no:'.$studentId);
// 获取设备号
require_once(Yii::app()->basePath . '/extensions/RedisLoginCtrl.php');
$group_redis_obj = RedisLoginCtrl::getRedisObj($studentId);
$stu_login_id = $group_redis_obj->hGet('zsy_student:zxhx_login_info:' . $studentId, 'bind_unique_no');
if($stu_login_id){
$data['stu_login_id'] = 1;
}else{
$data['stu_login_id'] = 0;
}
$this->render('edit2', $data);
}
// 根据班级id获取学生
public function actionGetstudent()
{
$cid = safe_replace($_POST['cid']);
if (empty($cid)) {
$json['flag'] = false;
echo json_encode($json);
die;
}
//$getStudent = StudentInfo::model()->findAll('class_id=:cid',array('cid'=>$cid));
$getStudent = $this->schoolManager->getClassStudents($cid);
if (empty($getStudent)) {
$json['flag'] = false;
$json['number'] = 1;
echo json_encode($json);
die;
}
$resArray = array();
$student_ids = array();
foreach ($getStudent as $key => $val) {
$student_ids[$val->student_id] = $val->student_id;
}
$criteria = new CDbCriteria();
$b_student = array();
$criteria->addInCondition('student_id',$student_ids);
$b_student_data = BusinessStudent::model()->findAll($criteria);
if($b_student_data)
{
foreach($b_student_data as $v)
{
$b_student[$v->student_id] = $v->student_card;
}
foreach ($getStudent as $key => $val) {
$resArray[$key]['student_id'] = $val->student_id;
$resArray[$key]['realname'] = $val->realname;
if(isset($b_student[$val->student_id]) && !empty($b_student[$val->student_id]))
{
$resArray[$key]['student_card'] = $b_student[$val->student_id];
}else{
$resArray[$key]['student_card'] = '';
}
}
}else{
foreach ($getStudent as $key => $val) {
$resArray[$key]['student_id'] = $val->student_id;
$resArray[$key]['realname'] = $val->realname;
$resArray[$key]['student_card'] = '';
}
}
unset($getStudent);
$json['flag'] = true;
$json['resArray'] = $resArray;
echo json_encode($json);exit;
}
// ajax验证登录账号是否存在
public function actionVerifyname()
{
//$getName = safe_replace($_POST['name']);
//$getSid = safe_replace($_POST['sid']);
$getName = Req::post("name");
$getSid = Req::post("sid");
if (!empty($getName)) {
if ($getSid != 1) {
$getCount = BusinessStudent::model()->count('username=:name and student_id!=:sid', array(':name' => $getName, ':sid' => $getSid));
if ($getCount) {
exit('1'); // 已存在
} else {
exit('2'); // 不存在
}
} else {
$student_data = BusinessStudent::model()->find('username=:name', array(':name' => $getName));
if ($student_data) {
$student_info_data = StudentInfo::model()->find('student_id=:student_id', array(':student_id' => $student_data->student_id));
if ($student_info_data) {
$student_class_data = SStudentClassRelation::model()->find('student_id=:student_id and status=:status', array(':student_id' => $student_data->student_id, ':status' => 0));
if (!$student_class_data) {
exit('2');
}
}
exit('1'); // 已存在
}
exit('2'); // 不存在
}
} else {
exit('1'); // 已存在
}
}
public function actionVerifyrealname()
{
$getName = preg_replace("/[^\x{2E80}-\x{FE4F}]+/u", "", exsl_safe_replace(Req::post("realname")));
$p_type = Req::post("p_type");
$cid = Req::post("cid");
$class_ids = array();
if (!$cid) {
echo json_encode(array('status' => 0));
exit;
}
$class_data = ClassModel::model()->find('class_id=:class_id', array(':class_id' => $cid));
if ($class_data) {
$semester_class_data = ClassModel::model()->findAll('semester_id=:semester_id', array(':semester_id' => $class_data->semester_id));
if ($semester_class_data) {
foreach ($semester_class_data as $v) {
$class_ids[$v->class_id] = $v->class_id;
}
}
}
if ($p_type && $p_type == 2) {
$student_id = Req::post("student_id");
$studentinfo_data = SStudentInfo::model()->find('student_id=:student_id', array(':student_id' => $student_id));
if ($studentinfo_data) {
if ($studentinfo_data->realname == $getName) {
echo json_encode(array('status' => 1));
exit;
} else {
$criteria = new CDbCriteria();
$criteria->addInCondition('class_id', $class_ids);
$criteria->addCondition('realname=:realname');
$criteria->params[':realname'] = $getName;
$student_data = SStudentInfo::model()->findAll($criteria);
unset($criteria);
if ($student_data) {
if (count($student_data) > 1) {
$_student_ids = array();
foreach($student_data as $v)
{
$_student_ids[$v->student_id] = $v->student_id;
}
$criteria = new CDbCriteria();
$criteria->addInCondition('student_id',$_student_ids);
$criteria->addCondition('status=:status');
$criteria->params[':status'] = 0;
$student_c_r = SStudentClassRelation::model()->findAll($criteria);
if($student_c_r)
{
echo json_encode(array('status' => 0));
exit;
}
echo json_encode(array('status' => 1));
exit;
} else {
$student_class_all_data = SStudentClassRelation::model()->findAll('student_id=:student_id and status=:status', array(':student_id' => $student_data[0]->student_id, ':status' => 0));
if ($student_class_all_data) {
echo json_encode(array('status' => 0));
exit;
}
echo json_encode(array('status' => 1));
exit;
}
} else {
echo json_encode(array('status' => 1));
exit;
}
}
}
echo json_encode(array('status' => 0));
exit;
} else {
/*$cid = Req::post("cid");
if($cid <= 0)
{
echo json_encode(array('status'=>2));exit;
}
$class_data = ClassModel::model()->find('class_id=:class_id and semester_id=:semester_id',array(':class_id'=>$cid,':semester_id'=>$this->semesterId));
if(!$class_data)
{
echo json_encode(array('status'=>3));exit;
}*/
if (!empty($getName)) {
$criteria = new CDbCriteria();
$criteria->addInCondition('class_id', $class_ids);
$criteria->addCondition('realname=:realname');
$criteria->params[':realname'] = $getName;
$student_data = SStudentInfo::model()->findAll($criteria);
//$student_data = SStudentInfo::model()->findAll('realname=:realname',array(':realname'=>$getName));
if ($student_data) {
if (count($student_data) > 1) {
$_student_ids = array();
foreach($student_data as $v)
{
$_student_ids[$v->student_id] = $v->student_id;
}
$criteria = new CDbCriteria();
$criteria->addInCondition('student_id',$_student_ids);
$criteria->addCondition('status=:status');
$criteria->params[':status'] = 0;
$student_c_r = SStudentClassRelation::model()->findAll($criteria);
if($student_c_r)
{
echo json_encode(array('status' => 0));
exit;
}
echo json_encode(array('status' => 1));
exit;
} else {
$student_class_all_data = SStudentClassRelation::model()->findAll('student_id=:student_id and status=:status', array(':student_id' => $student_data[0]->student_id, ':status' => 0));
if ($student_class_all_data) {
echo json_encode(array('status' => 0));
exit;
}
echo json_encode(array('status' => 1));
exit;
}
} else {
echo json_encode(array('status' => 1));
exit;
}
}
echo json_encode(array('status' => 0));
exit;
}
}
// ajax验证学号、序号是否重复
public function actionVerifynum()
{
//$getNum = safe_replace($_POST['pnumber']);
//$getSid = safe_replace($_POST['sid']);
//$type = (int)$_POST['type'];
$getNum = Req::post("pnumber");
$getSid = Req::post("sid");
$type = Req::post("type");
if ($type == 1) { // 验证唯一的学号
if (!empty($getNum)) {
if ($getSid == 1) { // 表示新加数据
$countNum = SStudentClassRelation::model()->count('userno=:uno and status=:status and class_id=:class_id', array(':uno' => $getNum, ':status' => 0, ':class_id' => $getSid));
if ($countNum) {
exit('1'); // 已存在
} else {
exit('2'); // 不存在
}
} else {
$countNum = SStudentClassRelation::model()->count('userno=:uno and status=:status and class_id=:class_id', array(':uno' => $getNum, ':status' => 0, ':class_id' => $getSid));
if ($countNum) {
exit('1'); // 已存在
} else {
exit('2'); // 不存在
}
}
}
} elseif ($type == 2) {
//$getCid = safe_replace($_POST['cid']);
$getCid = Req::post("cid");
if (!empty($getNum)) {
if ($getSid == 1) { // 表示新加数据
//$countNum = StudentInfo::model()->count('class_id=:cid and serial_number=:uno',array(':uno'=>$getNum,':cid'=>$getCid));
$countNum = $this->schoolManager->serialNumberExistsInClass($getNum, $getCid);
if ($countNum) {
echo json_encode(array('status' => 1));
exit;
} else {
echo json_encode(array('status' => 2));
exit;
}
} else {
//$countNum = StudentInfo::model()->count('class_id=:cid and serial_number=:uno and student_id!=:sid',array(':uno'=>$getNum,':cid'=>$getCid,':sid'=>$getSid));
$countNum = $this->schoolManager->serialNumberExistsInClass($getNum, $getCid, $getSid);
if ($countNum) {
echo json_encode(array('status' => 1));
exit;
} else {
echo json_encode(array('status' => 2));
exit;
}
}
}
}
}
public function actionKick()
{
}
public function actionDelStudentAct()
{
$studentId = Req::post("studentId");
$classId = Req::post("classId");
$logTitle='删除学生';
if($classId){
$classInfo=$this->schoolManager->getClass($classId);
if($classInfo['class_type']==2){
$logTitle='删除教学班学生';
}
}
if(Yii::app()->params['handle_log_on_off'])
{
writeFileLog(jsonEncode(array(
"exam_group_id" => 0,
"operate_project" => 'zsyas2',
"school_id" => $this->schoolId,
"title" => $logTitle,
"operate_account" => Yii::app()->session['coachInfo']['coach_name'],
"operate_method" => $this->action,
"operate_url" => $this->getRoute(),
"operate_sql" =>json_encode(array('delete'=>array('student_id'=>$studentId))),
"operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
"date"=>date('Y-m-d H:i:s')
)));
}
$delAntherClass=0;
if($classId && $classInfo && $classInfo['class_type']==2){
$delAntherClass=$classId;
}
//更新REDIS
Yii::app()->redis_business_student->del('redis_business_del_student:'.$this->schoolId);
if(isset(Yii::app()->session['testFlag']) && Yii::app()->session['testFlag']==1)
{
echo json_encode($this->schoolManager->purgeStudent($studentId,1,$delAntherClass));exit;
}
echo json_encode($this->schoolManager->purgeStudent($studentId,0,$delAntherClass));exit;
}
public function actionInputRecord()
{
$studentId = Req::get("studentId");
}
public function actionSchoolCard()
{
$this->render('schoolcard');
}
public function actionImport()
{
if (Yii::app()->request->getIsPostRequest()) {
$uploader = new Uploader("upload/tmpDir/UploadClassesStudentsList/{$this->schoolId}/");
$uploader->allowTypes = array("xls");
$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"];
Yii::import('application.extensions.*');
require_once('phpexcel/PHPExcel/IOFactory.php');
$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
//FIXME 2019-12-02
@unlink($file["src"]);
unset($sheetData[1]);
krsort($sheetData);
$sheetData = array_reverse($sheetData);
if ($sheetData)
{
$_err = array();
//获取学校
$school_data = BusinessSchool::model()->find('school_id=:school_id',array(':school_id'=>$this->schoolId));
if(!$school_data)
{
Yii::app()->jump->error('非法学校');
}
$semester_class_data = ClassModel::model()->findAll('semester_id=:semester_id', array(':semester_id' => $this->semesterId));
if ($semester_class_data)
{
foreach ($semester_class_data as $v)
{
$class_ids[$v->class_id] = $v->class_id;
}
}
$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)
{
Yii::app()->jump->error('当前学期无数据!');
}
foreach($semester_student_class_data as $v)
{
$s_student_ids[$v->student_id] = $v->student_id;
}
unset($criteria);
$criteria = new CDbCriteria();
$criteria->addInCondition('student_id',$s_student_ids);
$s_student_data = BusinessStudent::model()->findAll($criteria);
if($s_student_data)
{
foreach($s_student_data as $v)
{
$school_student_studentId[$v->school_student_card] = $v->student_id;
}
}
foreach ($sheetData as $key => $val)
{
if ( empty($val['A']) || empty($val['B']) || empty($val['C']) )
{
continue;
}
$realname = preg_replace("/[^\x{4E00}-\x{9FFF}^0-9·]+/u", "", exsl_safe_replace($val['A']));
$student_card = safe_replace($val['B']);
$school_student_card = safe_replace($val['C']);
//验证长度
/*if(strlen((string)$school_student_card) != $school_data->card_length)
{
$_err[$key]['school_student_card'] = $school_student_card;
$_err[$key]['student_card'] = $student_card;
$_err[$key]['username'] = $realname;
$_err[$key]['msg'] = '准考证长度与学校设置长度不一致';
continue;
}*/
//验证是否已存在
if(isset($school_student_studentId[$school_student_card]) && !empty($school_student_studentId[$school_student_card]) )
{
$_err[$key]['school_student_card'] = $school_student_card;
$_err[$key]['student_card'] = $student_card;
$_err[$key]['username'] = $realname;
$_err[$key]['msg'] = '同学期同学校,学校准考证号为唯一,学校准考证号已存在';
continue;
}
$is_student_card = BusinessStudent::model()->find('school_id=:school_id and student_card=:student_card ',array(':school_id'=>$this->schoolId,':student_card'=>$student_card));
if(!$is_student_card)
{
$_err[$key]['school_student_card'] = $school_student_card;
$_err[$key]['student_card'] = $student_card;
$_err[$key]['username'] = $realname;
$_err[$key]['msg'] = '学生准考证号不存在';
continue;
}
$student_class_data = SStudentClassRelation::model()->find('student_id=:student_id and status=:status',array(':student_id'=>$is_student_card->student_id,':status'=>0));
if(!$student_class_data)
{
$_err[$key]['school_student_card'] = $school_student_card;
$_err[$key]['student_card'] = $student_card;
$_err[$key]['username'] = $realname;
$_err[$key]['msg'] = '学生已被删除';
continue;
}
$class_data = ClassModel::model()->find('class_id=:class_id',array(':class_id'=>$student_class_data->class_id));
if(!$class_data)
{
$_err[$key]['school_student_card'] = $school_student_card;
$_err[$key]['student_card'] = $student_card;
$_err[$key]['username'] = $realname;
$_err[$key]['msg'] = '学生所在班级不存在';
}
//验证长度
$grade_data = SGradeModel::model()->find('id=:id',array(':id'=>$class_data->grade));
if($grade_data->card_status)
{
if(strlen((string)$school_student_card) != $grade_data->card_length)
{
$_err[$key]['school_student_card'] = $school_student_card;
$_err[$key]['student_card'] = $student_card;
$_err[$key]['username'] = $realname;
$_err[$key]['msg'] = '准考证长度与学校设置长度不一致';
continue;
}
}
$flage=BusinessStudent::model()->updateAll(array('school_student_card'=>$school_student_card),'student_card=:student_card',array(':student_card'=>$student_card));
if(!$flage)
{
$_err[$key]['school_student_card'] = $school_student_card;
$_err[$key]['student_card'] = $student_card;
$_err[$key]['username'] = $realname;
$_err[$key]['msg'] = '写入失败';
continue;
}
}
if($_err)
{
$this->create_xls($_err);
}else
{
Yii::app()->jump->success('全部学生关联成功');exit;
}
}
}
}
public function create_xls($_err)
{
if(!$_err)
{
return false;
}
$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(25);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(30);
$objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(22);
$objPHPExcel->getActiveSheet()->getRowDimension('2')->setRowHeight(20);
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', '姓名(当前学期唯一)')
->setCellValue('B1', '系统准考证号')
->setCellValue('C1', '学校准考证号')
->setCellValue('D1', '错误原因');
$i = 1;
foreach($_err as $v)
{
$i = $i + 1;
$objPHPExcel->getActiveSheet(0)->setCellValue('A' . $i, $v['username']);
$objPHPExcel->getActiveSheet(0)->setCellValueExplicit('B' . $i, (string)$v['student_card'], PHPExcel_Cell_DataType::TYPE_STRING);
$objPHPExcel->getActiveSheet()->getStyle('B' . $i)->getNumberFormat()->setFormatCode("@");
$objPHPExcel->getActiveSheet(0)->setCellValue('C' . $i, $v['school_student_card']);
$objPHPExcel->getActiveSheet(0)->setCellValue('D' . $i, $v['msg']);
}
$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');
}
//待分班学生
public function actionWaitlist(){
$condition = array();
$class_id = safe_replace(Yii::app()->request->getQuery('class_id'));
$grade_id = safe_replace(Yii::app()->request->getQuery('grade_id'));
$realname = safe_replace(Yii::app()->request->getQuery('realname'));
$search_type = safe_replace(Yii::app()->request->getQuery('search_type'));
$where = '';
$semester_id = $this->schoolManager->getPrevSemesterId();
//dd($semester_id);
if ($realname) {
if($search_type==1)
{
$condition = array("stu.realname like '%{$realname}%'");
}
if($search_type==2)
{
$where = "school_id=".$this->schoolId." and username = '".$realname."'";
}
if($search_type==3)
{
$realname = (int)$realname;
$where = 'school_id='.$this->schoolId.' and student_card = '.$realname;
}
if($search_type==4)
{
$where = "school_id=".$this->schoolId." and school_student_card = '".$realname."'";
}
if($search_type==5)
{
$realname = (int)$realname;
$where = 'school_id='.$this->schoolId.' and zhixue_student_card = '.$realname;
}
}
$grade_class_array = array();
$sort = '';
if (isset($_GET['sort'])) {
$sort = safe_replace(Yii::app()->request->getQuery('sort'));
}
if ($grade_id) {
$grade_class_data = ClassModel::model()->findAll('grade=:grade and semester_id=:semester_id', array(':grade' => $grade_id, ':semester_id' => $semester_id));
if ($grade_class_data) {
foreach ($grade_class_data as $v) {
$grade_class_array[$v->class_id] = $v->attributes;
}
}
array_push($condition, "c.grade=" . $grade_id);
}
array_push($condition, "c.semester_id=" . $semester_id);
array_push($condition, "scr.status=2" );
$classes = $this->schoolManager->getClassesBySemesterId($semester_id);
$resultClass = Arr::toObj($classes);
if (empty($class_id) && $classes) {
foreach ($classes as $v) {
$class_ids[$v['class_id']] = $v['class_id'];
}
$rs = $this->schoolManager->getPrevSemesterClassStudentsList($class_ids, $condition, 20,$where);
} else {
$rs = $this->schoolManager->getPrevSemesterClassStudentsList($class_id, $condition, 20,$where);
}
$userList = $rs["rs"];
$data = array();
// 处理学生按学号排序
if ($sort == 1) {
$sort = 2;
} elseif ($sort == 2) {
$sort = 1;
}
// 获取所有学期
//$data['allSemester']= Semester::model()->findAll();
//读取待分班学生数量
$waitStudent=$this->schoolManager->getWaitStudent();
$data['waitStudent'] = $waitStudent;
$data['grade_id'] = $grade_id;
$data['userList'] = $userList;
$data['pages'] = $rs['pager'];
$data['page_total'] = $rs['pager']->rowsCount;
$data['class_id'] = $class_id;
$data['search_type'] = $search_type;
$data['realname'] = $realname;
$data['grade_class'] = $grade_class_array;
$data['semester_id'] = $semester_id;
$data['classInfo'] = $resultClass;
$data['sort'] = $sort;
$data['calssName'] = ClassModel::model()->getClassName($class_id);
if (isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue)) {
$data["use_zhixue"] = $this->schoolInfo->use_zhixue;
} else {
$data["use_zhixue"] = 0;
}
unset($resultClass, $classes);
$this->render('index_prev_semester', $data);
}
//获取上学期班级
public function actionGetPrevSemesterClassByGrade(){
$grade_id = Req::post("grade_id");
$class_array = array();
if(!in_array($grade_id,array(0,1,2,3)))
{
echo json_encode(array('status'=>0,'result'=>array()));exit;
}
$semester_id = $this->schoolManager->getPrevSemesterId();
$class_data = ClassModel::model()->findAll('grade=:grade and semester_id=:semester_id',array(':grade' => $grade_id,':semester_id'=>$semester_id));
if($class_data){
foreach($class_data as $v )
{
$class_array[] = $v->attributes;
}
echo json_encode(array('status'=>1,'result'=>$class_array));exit;
}
echo json_encode(array('status'=>0,'result'=>array()));exit;
}
//待分配学生分配
public function actionAssignStudent()
{
$class_id = Req::post('class_id');
$studentId = Req::post('student_id');
$result['status'] = 0;
if (!is_array($studentId) || count($studentId) == 0 || !$class_id) {
$result['msg'] = '参数错误';
exit(json_encode($result));
}
$classStudentSql = "insert into student_class_relation(`class_id`,`student_id`,`status`,`serial_number`,`userno`,`update_time`,`operation`) values ";
$classStudentValues = array();
$oldClassIds = array();
foreach ($studentId as $sid) {
$classStudent = $this->sConn->createCommand("select student_id,serial_number,userno from student_class_relation where student_id='" & $sid & "' and status=2 ")->queryRow();
$classStudentValues[] = "('" . $class_id . "','" . $sid . "',0,'" . $classStudent['serial_number'] . "','" . $classStudent['userno'] . "','" . time() . "',0)";
$oldClassIds[] = $classStudent['class_id'];
}
if ($classStudentValues) {
$classStudentSql = $classStudentSql . implode(',', $classStudentValues);
}
$updateStudentInfoSql = "update student_info set class_id='" . $class_id . "' where student_id in(" . implode(',', $studentId) . ") ;";
$updateClassStudentSql = "update student_class_relation set status=1,operation=3 where class_id in(" . implode(',', $oldClassIds) . ") and student_id in(" . implode(',', $studentId) . ") and status=2; ";
$trans = $this->sConn->beginTransaction();
try {
$this->sConn->createCommand($classStudentSql)->execute();
$this->sConn->createCommand($updateClassStudentSql)->execute();
$this->sConn->createCommand($updateStudentInfoSql)->execute();
$trans->commit();
$result['status'] = 1;
} catch (Exception $e) {
$trans->rollBack();
$result['msg'] = '分班失败';
}
exit(json_encode($result));
}
public function actionCheck(){
$data=array();
$this->render('check', $data);
}
//设置扩展字段
public function actionAjaxStudentExtendSetting(){
$field_1=Req::post('field_1');
$field_1_status=Req::post('field_1_status');
$field_2=Req::post('field_2');
$field_2_status=Req::post('field_2_status');
$field_3=Req::post('field_3');
$field_3_status=Req::post('field_3_status');
$field_4=Req::post('field_4');
$field_4_status=Req::post('field_4_status');
$field_5=Req::post('field_5');
$field_5_status=Req::post('field_5_status');
if($field_1_status=='true'){
$field_1_is_enable=1;
}else{
$field_1_is_enable=0;
}
if($field_2_status=='true'){
$field_2_is_enable=1;
}else{
$field_2_is_enable=0;
}
if($field_3_status=='true'){
$field_3_is_enable=1;
}else{
$field_3_is_enable=0;
}
if($field_4_status=='true'){
$field_4_is_enable=1;
}else{
$field_4_is_enable=0;
}
if($field_5_status=='true'){
$field_5_is_enable=1;
}else{
$field_5_is_enable=0;
}
$result['status']=0;
$insert="insert into student_info_extend(`field_name`,`field_mean`,`is_enable`) values ";
$insert.="('field_1','".$field_1."','".$field_1_is_enable."'),";
$insert.="('field_2','".$field_2."','".$field_2_is_enable."'),";
$insert.="('field_3','".$field_3."','".$field_3_is_enable."'),";
$insert.="('field_4','".$field_4."','".$field_4_is_enable."'),";
$insert.="('field_5','".$field_5."','".$field_5_is_enable."')";
$transcation = $this->sConn->beginTransaction();
try {
$del_sql = "truncate `student_info_extend`;";
$this->sConn->createCommand($del_sql)->execute();
$this->sConn->createCommand($insert)->execute();
$transcation->commit();
$result['status']=1;
}catch (Exception $e){
$transcation->rollback();
}
exit(json_encode($result));
}
//添加教学班学生
public function actionAddClassified(){
$gradeArr=array(
1=>'高一',
2=>'高二',
3=>'高三',
);
$data = array();
$cid = safe_replace(Yii::app()->request->getQuery('cid'));
// $cname = ClassModel::model()->getClassName($cid);
$classInfo = $this->schoolManager->getClassInfo($cid);
$subjects=$this->schoolManager->getSubjectByClass($cid);
// 获取当前学校班级
$getClass = ClassModel::model()->findAll('semester_id="' . Yii::app()->session['session_semester_id'] . '" and class_type=1 and grade="'.$classInfo['grade'].'" and is_hide=0');
$resultClass = $getClass;
if (Yii::app()->session['coachInfo']['leader'] != 1) {
$resultClass = array();
$coachClass = $this->schoolManager->getCoachClassesRelations($this->coachId, "OBJ");
foreach ($getClass as $t) {
foreach ($coachClass as $tt) {
if ($t->class_id == $tt->class_id) {
$resultClass[] = $t;
}
}
}
}
$data['cid'] = $cid;
$data['grade']=$classInfo['grade'];
$data['gradeName']=$gradeArr[$classInfo['grade']];
$data['cname'] = $classInfo['class_name'];
$data['classInfo'] = $resultClass;
$data['subjects'] = $subjects;
$this->render('add_classified', $data);
}
//加载未走班学生
public function actionGetStudentByClassified(){
$class_id=Req::post('class_id');
$subjects=Req::post('subjects');
$grade=Req::post('grade');
//读取科目下已走班学生
$studentIds=$this->schoolManager->getStudentBySubjects($subjects,$grade,$this->semesterId);
$studentList=array();
//读取当前班级学生
$studentInfo=$this->schoolManager->getClassStudents($class_id,array(),'ARR');
if($studentInfo){
foreach ($studentInfo as $item){
if(!in_array((string)$item['student_id'],$studentIds,true)){
//查询系统准考证
$studentInfo=$this->conn->createCommand("select student_card from student where student_id='{$item['student_id']}'")->queryRow();
if($studentInfo){
$item['realname']=$item['realname'].'('.$studentInfo['student_card'].')';
}
$studentList[]=$item;
}
}
}
$result['status']=1;
$result['data']=$studentList;
exit(json_encode($result));
}
//查询未走班学生
public function actionSearchStudentByClassified(){
$realname = safe_replace(Req::post('realname'));
$subjects=Req::post('subjects');
$grade=(int)Req::post('grade');
//查询学生
$students=$this->schoolManager->getClassifiedStudentByName($realname,$subjects,$grade,$this->semesterId);
$result['status']=1;
$result['data']=$students;
exit(json_encode($result));
}
//添加走班学生
public function actionAddClassifiedStudent(){
$classId=Req::post('cid');
$studentIds=Req::post('student_id');
$result['status']=0;
if(!$classId || !$studentIds || !is_array($studentIds)){
$result['msg']='参数异常';
exit(json_encode($result));
}
$classInfo = $this->schoolManager->getClassInfo($classId);
if(!$classInfo){
$result['msg']='未找到班级信息';
exit(json_encode($result));
}
$rs=$this->schoolManager->addClassifiedStudent($studentIds,$classId);
if($rs==-1){
$result['msg']='已有走班科目记录,不能重复添加走班记录';
exit(json_encode($result));
}elseif($rs){
$result['status']=1;
}
exit(json_encode($result));
}
//教学班转班加载学生
public function actionGetClassifiedStudent(){
$class_id=Req::post('class_id'); //来源班级
$subjects=Req::post('subjects');
$grade=Req::post('grade');
$semester=Req::post('semester');
$to_class_id=Req::post('to_class_id'); //目标班级
//读取目标班级已有学生
$studentIds=array();
$studentList=$this->schoolManager->getClassStudents($to_class_id,array(),'ARR');
if($studentList){
foreach ($studentList as $val){
$studentIds[]=$val['student_id'];
}
}
//读取来源班级学生
$resultStudentList=array();
$fromStudentList=$this->schoolManager->getClassStudents($class_id,array(),'ARR');
if($fromStudentList){
foreach ($fromStudentList as $key => $item){
if(!inArray($item['student_id'],$studentIds)){
//查询系统准考证
$studentInfo=$this->conn->createCommand("select student_card from student where student_id='{$item['student_id']}'")->queryRow();
if($studentInfo){
$item['realname']=$item['realname'].'('.$studentInfo['student_card'].')';
}
$resultStudentList[]=$item;
}
}
}
$result['status']=1;
$result['data']=$resultStudentList;
exit(json_encode($result));
}
//教学班按改名搜索
public function actionGetClassifiedStudentByName(){
$classIds=Req::post('classIds'); //来源班级
$to_class_id=Req::post('to_class_id'); //目标班级
$realname = safe_replace(Req::post('realname'));
//读取目标班级已有学生
$studentIds=array();
$studentList=$this->schoolManager->getClassStudents($to_class_id,array(),'ARR');
if($studentList){
foreach ($studentList as $val){
$studentIds=$val['student_id'];
}
}
$resultStudentList=$this->schoolManager->searchStudentByClassIdsStudentName($classIds,$realname,$studentIds);
$resultStudentList=array_values($resultStudentList);
$result['status']=1;
$result['data']=$resultStudentList;
exit(json_encode($result));
}
//教学班转班
public function actionCopyClassified(){
$to_class_id=Req::post('cid'); //目标班级
$studentData=Req::post('student_id');
$result['status']=0;
if(!$studentData || !$to_class_id){
$result['msg']='参数异常';
exit(json_encode($result));
}
$classInfo = $this->schoolManager->getClassInfo($to_class_id);
if(!$classInfo){
$result['msg']='未找到班级信息';
exit(json_encode($result));
}
//分解学生班级信息
$classAndStudent=array();
foreach($studentData as $val){
$temp=@explode('///',$val);
if(isset($temp[0]) && isset($temp[1])){
$classAndStudent[$temp[1]]=$temp[0];
}
}
if($this->schoolManager->copyClassified($to_class_id,$classAndStudent)){
$result['status']=1;
exit(json_encode($result));
}
exit(json_encode($result));
}
// 目标院校管理
public function actionTarget()
{
$page = Req::get('page') ? Req::get('page') : 1;
$gradeName = Req::get('grade_name');
$className = Req::get('class_name');
$studentName = Req::get('student_name');
$pageLimit=10;
$userModel=new BusinessStudentTargetUniversity();
$result = $userModel->getStudentTargetList($this->schoolId,$gradeName,$className,$studentName,$page,$pageLimit);
return $this->render('target', array(
'dataList' => $result['dataList'],
'pages' => $result['pages'],
'page'=>$page,
'gradeName' => $gradeName,
'className' => $className,
'studentName' => $studentName,
));
}
//重制学生设备登陆ID
public function actionAjaxResetLoginId(){
$error = array();
$studentId = (string)Req::post('studentId') ? (string)Req::post('studentId') : "";
if(!$studentId){
$error[] = "学生ID错误";
}
if(!$error){
// 获取设备号
// $stu_login_id = Yii::app()->stu_login_permission->getValue('zsy_student:student_app_unique_no:'.$studentId);
require_once(Yii::app()->basePath . '/extensions/RedisLoginCtrl.php');
$group_redis_obj = RedisLoginCtrl::getRedisObj($studentId);
$stu_login_id = $group_redis_obj->hGet('zsy_student:zxhx_login_info:' . $studentId, 'bind_unique_no');
if ($stu_login_id) {
foreach (range(0, RedisLoginCtrl::getRedisNum()) as $redisNun) {
RedisLoginCtrl::getRedisObj($redisNun)->del('zsy_student:device_unique_no:' . $stu_login_id);
}
$group_redis_obj->hSet('zsy_student:zxhx_login_info:' . $studentId, 'bind_unique_no', '');
} else {
$error[] = "重制失败";
}
}
if($error){
$result['status'] = 0;
$result['msg']=implode("
",$error);
}else{
$result['status'] = 1;
}
exit(json_encode($result));exit;
}
//英语能力等级管理
public function actionLevel()
{
$page = Req::get('page') ? Req::get('page') : 1;
$grade = Req::get('grade');
$classId = Req::get('classId');
$studentName = Req::get('name');
$pageLimit=20;
$userModel=new SStudentInfo();
$result = $userModel->getStudentLevelList($grade,$classId,$studentName,$this->semesterId, $page,$pageLimit);
$classes = $grade ? $this->schoolManager->getClasses($grade) : array();
return $this->render('level', array(
'dataList' => $result['dataList'],
'pages' => $result['pages'],
'page'=>$page,
'grade' => $grade,
'classId' => $classId,
'studentName' => $studentName,
'classes' => $classes
));
}
//手动更新英语人工等级
public function actionAjaxUpdateLevel(){
$error = array();
$studentIds = (array)Req::post('studentIds') ? (array)Req::post('studentIds') : array();
$type = (int)Req::post('type') ? (int)Req::post('type') : 0;
$level = (int)Req::post('level') ? (int)Req::post('level') : 0;
if(!$studentIds){
$error[] = "学生ID错误";
}
if(!$type && !$level){
$error[] = "参数错误";
}
$result['status'] = 0;
if(!$error){
$trans = $this->sConn->beginTransaction();
try {
$studentIdsStr = implode(',', $studentIds);
if($level){
$sql = "update student_info set english_level_artificial={$level} where student_id in ({$studentIdsStr})";
}else{
switch ($type){
case 1:
$sql = "update student_info set english_level_artificial=if(english_level_one+1>10,10, english_level_one+1) where student_id in ({$studentIdsStr})";
break;
case 2:
$sql = "update student_info set english_level_artificial=if(english_level_one+2>10,10, english_level_one+2) where student_id in ({$studentIdsStr})";
break;
case 3:
$sql = "update student_info set english_level_artificial=if(english_level_one<2, 1, english_level_one-1) where student_id in ({$studentIdsStr})";
break;
case 4:
$sql = "update student_info set english_level_artificial=if(english_level_one<3, 1, english_level_one-2) where student_id in ({$studentIdsStr})";
break;
}
}
$this->sConn->createCommand($sql)->execute();
$trans->commit();
$result['status'] = 1;
} catch (Exception $e) {
$trans->rollBack();
$result['msg'] = '操作失败';
}
}
if($error){
$result['msg']=implode("
",$error);
}else{
$result['status'] = 1;
}
exit(json_encode($result));exit;
}
}