123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364 |
- <?php
- /**
- * 学生管理控制器类
- * @author jiangfei
- * @date 2015-07-21 9:50:00
- * @company 上海风车教育有限公司.
- */
- class StudentinfoController extends Controller
- {
- // 学生列表
- public function actionIndex()
- {
- $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'));
- $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("<br>",$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("<br>",$error);
- }else{
- $result['status'] = 1;
- }
- exit(json_encode($result));exit;
- }
- }
|