123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898 |
- <?php
- /**
- * 学校管理控制器类
- * @author 李凯磊
- * @date 2016-08-31 10:50:00
- * @company 上海风车教育有限公司.
- */
- class SchoolController extends Controller{
- private $errors;
- public function actionadd(){
- $data['schoolinfo'] = BusinessSchool::model()->find("school_id=:sid",array(':sid'=>Yii::app()->session['coachInfo']['school_id']));
- //查询学段
- $data['gradeGroup'] = BusinessGradeGroup::model()->findAll("section=:sid",array(':sid'=>$data['schoolinfo']['section']));
- //查询学制
- $data['gradeConfig'] = BusinessGradeConfig::model()->findAll();
- $gradeArr=array();
- foreach ($data['gradeConfig'] as $datum){
- $gradeArr[$datum['group_id']][$datum['grade_id']]=$datum['grade_name'];
- }
- $data['gradeConfig'] = $gradeArr;
- $realGradeArr=array();
- $grade = SGrade::model()->findAll();
- foreach ($grade as $item){
- if(isset($gradeArr[$data['schoolinfo']['grade_group_id']][$item->id])){
- $realGradeArr[]=$item;
- }
- }
- $data['grade']=$realGradeArr;
- $data['area'] = CMRegion::model()->findAllBySql("select region_name from region where region_id in ({$data['schoolinfo']['province_id']},{$data['schoolinfo']['city_id']},{$data['schoolinfo']['area_id']})");
- $semesterId = Yii::app()->session['session_semester_id'];
- $classList = SClass::model()->findAll("semester_id=:semester_id and arts_science<>0 and is_hide=0 ",array(':semester_id'=>$semesterId));
- //读取学年
- $schoolYear=array();
- $period = $this->getHttp('sys/school/year/period/list', 'get');
- if($period['status']==1){
- $schoolYear=$period['data'];
- }
- $data['schoolYear']=$schoolYear;
- $detail = $this->getHttp('customer/school/coach/official/detail', 'get');
- if($detail){
- //学校概况
- if(isset($detail['data']['schoolProfile']['schoolBuildYear'])){
- $data['schoolprofile']['schoolBuildYear']=$detail['data']['schoolProfile']['schoolBuildYear']; //年份
- }else{
- $data['schoolprofile']['schoolBuildYear']=''; //年份
- }
- if(isset($detail['data']['schoolProfile']['studentCount'])){
- $data['schoolprofile']['studentCount']=$detail['data']['schoolProfile']['studentCount']; //规模
- }else{
- $data['schoolprofile']['studentCount']=''; //规模
- }
- if(isset($detail['data']['schoolProfile']['artsAndScience'])){
- $data['schoolprofile']['artsAndScience']=$detail['data']['schoolProfile']['artsAndScience'];
- }else{
- $data['schoolprofile']['artsAndScience']='';
- }
- if(isset($detail['data']['schoolProfile']['bookVersion'])){
- $data['schoolprofile']['bookVersion']=$detail['data']['schoolProfile']['bookVersion'];
- }else{
- $data['schoolprofile']['bookVersion']='';
- }
- if(isset($detail['data']['schoolProfile']['schoolNature'])){
- $data['schoolprofile']['schoolNature']=$detail['data']['schoolProfile']['schoolNature']; //学校性质
- }else{
- $data['schoolprofile']['schoolNature']=''; //学校性质
- }
- if(isset($detail['data']['schoolProfile']['schoolType'])){
- $data['schoolprofile']['schoolType']=$detail['data']['schoolProfile']['schoolType']; //学校类型
- }else{
- $data['schoolprofile']['schoolType']='0'; //学校类型
- }
- if(isset($detail['data']['schoolProfile']['isMinority'])){
- $data['schoolprofile']['isMinority']=$detail['data']['schoolProfile']['isMinority']; //是否设置少数民族
- }else{
- $data['schoolprofile']['isMinority']=''; //是否设置少数民族
- }
- if(isset($detail['data']['schoolProfile']['isStaying'])){
- $data['schoolprofile']['isStaying']=$detail['data']['schoolProfile']['isStaying']; //寄宿制形式
- }else{
- $data['schoolprofile']['isStaying']=''; //寄宿制形式
- }
- //升学率
- if(isset($detail['data']['upRates'])){
- $data['schoolentrancerate'] =$detail['data']['upRates'];
- }else{
- $data['schoolentrancerate'] =array();
- }
- //规模
- if(isset($detail['data']['scaleResDTOS'])){
- $data['scale']=$detail['data']['scaleResDTOS'];
- }else{
- $data['scale']=array();
- }
- //联系方式
- if(isset($detail['data']['schoolContact']['schoolMasterName'])){
- $data['schoocontact']['schoolMasterName']=$detail['data']['schoolContact']['schoolMasterName'];
- }else{
- $data['schoocontact']['schoolMasterName']='';
- }
- if(isset($detail['data']['schoolContact']['schoolMasterMobile'])){
- $data['schoocontact']['schoolMasterMobile']=$detail['data']['schoolContact']['schoolMasterMobile'];
- }else{
- $data['schoocontact']['schoolMasterMobile']='';
- }
- if(isset($detail['data']['schoolContact']['schoolMaster2Name'])){
- $data['schoocontact']['schoolMaster2Name']=$detail['data']['schoolContact']['schoolMaster2Name'];
- }else{
- $data['schoocontact']['schoolMaster2Name']='';
- }
- if(isset($detail['data']['schoolContact']['schoolMaster2Mobile'])){
- $data['schoocontact']['schoolMaster2Mobile']=$detail['data']['schoolContact']['schoolMaster2Mobile'];
- }else{
- $data['schoocontact']['schoolMaster2Mobile']='';
- }
- if(isset($detail['data']['schoolContact']['grade1HeadName'])){
- $data['schoocontact']['grade1HeadName']=$detail['data']['schoolContact']['grade1HeadName'];
- }else{
- $data['schoocontact']['grade1HeadName']='';
- }
- if(isset($detail['data']['schoolContact']['grade1HeadMobile'])){
- $data['schoocontact']['grade1HeadMobile']=$detail['data']['schoolContact']['grade1HeadMobile'];
- }else{
- $data['schoocontact']['grade1HeadMobile']='';
- }
- if(isset($detail['data']['schoolContact']['grade2HeadName'])){
- $data['schoocontact']['grade2HeadName']=$detail['data']['schoolContact']['grade2HeadName'];
- }else{
- $data['schoocontact']['grade2HeadName']='';
- }
- if(isset($detail['data']['schoolContact']['grade2HeadMobile'])){
- $data['schoocontact']['grade2HeadMobile']=$detail['data']['schoolContact']['grade2HeadMobile'];
- }else{
- $data['schoocontact']['grade2HeadMobile']='';
- }
- if(isset($detail['data']['schoolContact']['grade3HeadName'])){
- $data['schoocontact']['grade3HeadName']=$detail['data']['schoolContact']['grade3HeadName'];
- }else{
- $data['schoocontact']['grade3HeadName']='';
- }
- if(isset($detail['data']['schoolContact']['grade3HeadMobile'])){
- $data['schoocontact']['grade3HeadMobile']=$detail['data']['schoolContact']['grade3HeadMobile'];
- }else{
- $data['schoocontact']['grade3HeadMobile']='';
- }
-
- }
- //处理文理科分班情况
- foreach ($data['grade'] as $grade){
- if($grade['arts_science']==1){
- //不分科
- }elseif($grade['arts_science']==2){
- //查询班级
- foreach ($classList as $class){
- if($class['grade']==$grade['id'] ){
- $data['arts_science'][$grade['id']][$class['arts_science']]['ids'][]=$class['class_id'];
- $data['arts_science'][$grade['id']][$class['arts_science']]['names'][]=$class['class_name'];
- }
- }
- }
- }
- //自定义学科设置
- $data['extendSubject']=BusinessSubject::model()->findAll("is_basic=0");
- //已配置自定义学科
- $extendSubjectSchool=SExtendSubject::model()->findAll();
- if($extendSubjectSchool){
- foreach ($extendSubjectSchool as $key => $val){
- $data['extendSubjectSchool'][$val['subject_id']]['subject_id']=$val['subject_id'];
- $data['extendSubjectSchool'][$val['subject_id']]['subject_name']=$val['subject_name'];
- if(SExtendSubject::model()->checkSubjectUsed($val['subject_id'])){
- $data['extendSubjectSchool'][$val['subject_id']]['used']=1;
- }else{
- $data['extendSubjectSchool'][$val['subject_id']]['used']=0;
- }
- }
- }
- $_num= '';
- $use_version = '';
- if(isset(Yii::app()->session['coachInfo']->use_version))
- {
- $use_version = Yii::app()->session['coachInfo']->use_version;
- }else
- {
- $use_version = Yii::app()->session['coachInfo']['use_version'];
- }
- if(!$use_version)
- {
- $use_version = 100;
- }
- $version_number = implode('',explode('.',$use_version));
- if(strlen($version_number)<7)
- {
- for($i=0;$i<7-strlen($version_number);$i++)
- {
- $_num.='0';
- }
- }
- $version_number=(int)$version_number.$_num;
- //获取学校的安全与隐私配置
- $schoolPrivate = new BSchoolPrivate();
- $isPrivate = $schoolPrivate->getPrivate($this->schoolId);
- $data['is_private'] = $isPrivate;
- //debug($data);
- //获取学校平板登陆权限配置
- $data['login_permission'] = $data['schoolinfo']['is_login_permission'];
- if(Yii::app()->params['section']==0){
- $this->render('add_section',$data);
- }else{
- $this->render('add2',$data);
- }
- }
- public function actionSaveSchoolPrivate(){
- if (Yii::app()->request->getIsPostRequest()){
- $is_private = Req::post('is_private');
- $model = new BSchoolPrivate();
- $result = $model->savePrivate($this->schoolId, $is_private);
- if ($result){
- returnMsg(1,'保存成功');
- }else{
- returnMsg(0,'保存失败');
- }
- }else{
- returnMsg(0,"非法请求");
- }
- }
- public function actioninsert(){
- if (Yii::app()->request->getIsPostRequest())
- {
- $card_length = Req::post("card_length");
- $card_status = Req::post("card_status");
- $_err = array();
- $business_student_data = BusinessStudent::model()->findAll('school_id=:school_id',array(':school_id'=>$this->schoolId));
- if($business_student_data)
- {
- foreach($business_student_data as $v)
- {
- if($v->school_student_card)
- {
- if(strlen($v->school_student_card)!=$card_length)
- {
- $_err[] = '学生准考证号长度存在不等于'.$card_length.'位!';
- continue;
- }
- }
- }
- BusinessSchool::model()->updateAll(array('card_length'=>$card_length,'card_status'=>$card_status),'school_id=:school_id',array(':school_id'=>$this->schoolId));
- if($_err)
- {
- Yii::app()->jump->setSuccessWait(8);
- Yii::app()->jump->success('保存成功<br>但学生准考证号长度存在不等于'.$card_length.'位,请修改学生学校准考证号<br><br>',Yii::app()->createUrl('school/add'));exit;
- }
-
- Yii::app()->jump->success('保存成功',Yii::app()->createUrl('school/add'));
- }else
- {
- Yii::app()->jump->error('此学校没有学生,请先导入学生!');
- }
- }
- }
- /**
- * 设置学校准考证号
- */
- public function actionGrade_insert()
- {
- if (Yii::app()->request->getIsPostRequest())
- {
- $_err = array();
- foreach (Yii::app()->params['grade_list'] as $id =>$val){
- if(Req::post("card_status".$id)){
- $data = $this->get_card_length($id,Req::post("card_length".$id));
- if($data){
- $_err[$id] = $data;
- }
- }
- }
- foreach (Yii::app()->params['grade_list'] as $id =>$val){
- if(isset($_POST['card_status'.$id])){
- $cardLength=Req::post("card_length".$id);
- $cardStatus=Req::post("card_status".$id);
- if(!$cardLength) $cardLength=0;
- SGrade::model()->updateAll(array('card_length'=>$cardLength,'card_status'=>$cardStatus),'id=:id',array(':id'=>$id));
- }
- }
- if($_err){
- Yii::app()->jump->setSuccessWait(8);
- Yii::app()->jump->setHeight(240);
- $str='';
- foreach ($_err as $grade =>$item){
- $str.=Yii::app()->params['grade_list'][$grade]['grade_name'].'学生准考证号长度存在不等于'.Req::post("card_length".$grade).'位,请修改学生学校准考证号';
- }
- Yii::app()->jump->error($str,Yii::app()->createUrl('school/add'));exit;
- }else{
- Yii::app()->jump->success('保存成功',Yii::app()->createUrl('school/add'));exit;
- }
- }else
- {
- Yii::app()->jump->error('不能多次提交',Yii::app()->createUrl('school/add'));exit;
- }
- }
- protected function get_card_length($grade,$card_length)
- {
- $class_data = ClassModel::model()->findAll('grade=:grade and semester_id=:semester_id',array(':grade'=>$grade,':semester_id'=>$this->semesterId));
- $class_ids = array();
- $student_ids = array();
- $_err = array();
- if($class_data)
- {
- foreach($class_data as $v)
- {
- $class_ids[$v->class_id] = $v->class_id;
- }
- $criteria = new CDbCriteria();
- $criteria->addInCondition('class_id',$class_ids);
- $criteria->addCondition('status=:status');
- $criteria->params[':status'] = 0;
- $student_class_data = SStudentClassRelation::model()->findAll($criteria);
- if($student_class_data)
- {
- foreach($student_class_data as $v)
- {
- $student_ids[$v->student_id] = $v->student_id;
- }
- unset($criteria);
- $business_student_data=$this->schoolManager->getStudentByCardLength($student_ids,$card_length);
- if($business_student_data){
- $_err[] = '学生准考证号长度存在不等于'.$card_length.'位!';
- }
- /*
- $criteria = new CDbCriteria();
- $criteria->addInCondition('student_id',$student_ids);
- $business_student_data = BusinessStudent::model()->findAll($criteria);
- if($business_student_data)
- {
- foreach($business_student_data as $v)
- {
- if($v->school_student_card)
- {
- if(strlen($v->school_student_card)!=$card_length)
- {
- $_err[] = '学生准考证号长度存在不等于'.$card_length.'位!';
- continue;
- }
- }
- }
- }
- */
- }
- }
- return $_err;
- }
- //联系人
- public function actionContact_insert()
- {
- $params=array();
- $params['schoolMasterName'] = Req::post("schoolMasterName");
- $params['schoolMasterMobile'] = Req::post("schoolMasterMobile");
- $params['schoolMaster2Name'] = Req::post("schoolMaster2Name");
- $params['schoolMaster2Mobile'] = Req::post("schoolMaster2Mobile");
- $params['grade1HeadName'] = Req::post("grade1HeadName");
- $params['grade1HeadMobile'] = Req::post("grade1HeadMobile");
- $params['grade2HeadName'] = Req::post("grade2HeadName");
- $params['grade2HeadMobile'] = Req::post("grade2HeadMobile");
- $params['grade3HeadName'] = Req::post("grade3HeadName");
- $params['grade3HeadMobile'] = Req::post("grade3HeadMobile");
- $params['schoolId']=$this->schoolId;
- $res = $this->getHttp('customer/school/coach/contact', 'put',$params);
- if ($res['status'] == 1) {
- Yii::app()->jump->success('保存成功',Yii::app()->createUrl('school/add'));
- } else {
- Yii::app()->jump->error($res['msg']);
- }
- }
- public function actionAjax_student()
- {
- $card_length = Req::post("card_length");
- $business_student_data = BusinessStudent::model()->findAll('school_id=:school_id',array(':school_id'=>$this->schoolId));
- if($business_student_data)
- {
- foreach($business_student_data as $v)
- {
- if($v->school_student_card)
- {
- if(strlen($v->school_student_card) != $card_length)
- {
- echo json_encode(array('status'=>1,'msg'=>'学生准考证号长度存在不等于'.$card_length.'位!'));exit;
- }
- }
- }
- echo json_encode(array('status'=>0,'msg'=>''));exit;
- }else
- {
- echo json_encode(array('status'=>1,'msg'=>'此学校没有学生,请先导入学生!'));exit;
- }
- }
- public function actionSetusewp()
- {
- $use_wp = Req::post("use_wp");
- if(false !== BusinessSchool::model()->updateAll(
- array('use_wp'=>$use_wp),'school_id=:sid',array(':sid'=>Yii::app()->session['coachInfo']['school_id'])))
- {
- echo json_encode(array('status'=>1,'wp'=>$use_wp));exit;
- }
- echo json_encode(array('status'=>0));exit;
- }
- /**
- * 学校概况
- */
- public function actionProfile_insert()
- {
- $profile=$_POST['profile'];
- $params=array();
- $params['schoolId']=$this->schoolId;
- $params['schoolBuildYear']=$profile['schoolBuildYear'];
- $params['schoolNature']=$profile['schoolNature'];
- $params['isMinority']=$profile['isMinority'];
- $params['isStaying']=intval($profile['isStaying']);
- // $params['studentCount']=$profile['studentCount'];
- $params['schoolType']=$profile['schoolType'];
- if(isset($profile['bookVersion'])){
- $params['bookVersion']=$profile['bookVersion'];
- }else{
- $params['bookVersion']=0;
- }
- $params['artsAndScience']=$profile['artsAndScience'];
- $upRates=array();
- if(Yii::app()->params['section']==0){
- if(isset($_POST['schoolYear']) && $_POST['schoolYear']){
- foreach ($_POST['schoolYear'] as $key => $val){
- $upRates[]=array(
- 'schoolYearId'=>$val,
- 'highSchoolRate'=>$_POST['upRate'][$key],
- 'level1Rate'=>0,
- 'level2Rate'=>0,
- 'level3Rate'=>0,
- );
- }
- }
- }else{
- if(isset($_POST['schoolYear']) && $_POST['schoolYear']){
- foreach ($_POST['schoolYear'] as $key => $val){
- $upRates[]=array(
- 'schoolYearId'=>$val,
- 'level1Rate'=>$_POST['level1Rate'][$key],
- 'level2Rate'=>$_POST['level2Rate'][$key],
- 'level3Rate'=>$_POST['level3Rate'][$key],
- 'highSchoolRate'=>0
- );
- }
- }
- }
- if($upRates){
- $params['upRates']=$upRates;
- }
- $scaleResDTOS=array();
- if(Yii::app()->params['section']==0){
- if(isset($_POST['schoolScale']) && $_POST['schoolScale']){
- foreach ($_POST['schoolScale'] as $key => $val){
- $scaleResDTOS[]=array(
- 'schoolYearId'=>$val,
- 'gradeOne'=>0,
- 'gradeTwo'=>0,
- 'gradeThree'=>0,
- 'highSchoolSix'=>$_POST['highSchoolSix'][$key],
- 'highSchoolSeven'=>$_POST['highSchoolSeven'][$key],
- 'highSchoolEight'=>$_POST['highSchoolEight'][$key],
- 'highSchoolNine'=>$_POST['highSchoolNine'][$key],
- );
- }
- }
- }else{
- if(isset($_POST['schoolScale']) && $_POST['schoolScale']){
- foreach ($_POST['schoolScale'] as $key => $val){
- $scaleResDTOS[]=array(
- 'schoolYearId'=>$val,
- 'gradeOne'=>$_POST['gradeOne'][$key],
- 'gradeTwo'=>$_POST['gradeTwo'][$key],
- 'gradeThree'=>$_POST['gradeThree'][$key],
- 'highSchoolSix'=>0,
- 'highSchoolSeven'=>0,
- 'highSchoolEight'=>0,
- 'highSchoolNine'=>0,
- );
- }
- }
- }
- if($scaleResDTOS){
- $params['scaleDTOS']=$scaleResDTOS;
- }
- $res = $this->getHttp('customer/school/coach/profile-uprate', 'put',$params);
- if ($res['status'] == 1) {
- Yii::app()->jump->success('保存成功',Yii::app()->createUrl('school/add'));
- } else {
- Yii::app()->jump->error($res['msg']);
- }
- }
- /*读取所有班级*/
- public function actionGetClass(){
- $grade_id = Req::post("grade_id"); //年级
- $title = Req::post("title");
- $type = Req::post("type");
- $selected_class_id=Req::post('selected_class_id');
- $semesterId=Yii::app()->session['session_semester_id'];
- if($selected_class_id){
- $SelectedClassArr=explode(',',$selected_class_id);
- }else{
- $SelectedClassArr=array();
- }
- $class_data = ClassModel::model()->findAll('semester_id=:semester_id and grade=:grade and is_hide=0',array(':semester_id'=>$semesterId,':grade'=>$grade_id));
- $html=' <i class="icon icon-close"></i><div class="class-modal-head">'.$title.'</div>';
- $html.='<div class="class-modal-body">';
- foreach ($class_data as $subject=>$class){
- if($SelectedClassArr && in_array((string)$class['class_id'],$SelectedClassArr,true)){
- $html.='<label><input type="checkbox" checked value="'.$class['class_id'].'" name="'.$class['class_name'].'">'.$class['class_name'].'</label>';
- }else{
- $html.='<label><input type="checkbox" value="'.$class['class_id'].'" name="'.$class['class_name'].'">'.$class['class_name'].'</label>';
- }
- }
- $html.='</div>';
- $html.='<p class="class_btn">';
- $html.='<input type="hidden" name="grade_id" value="'.$grade_id.'">';
- $html.='<input type="hidden" name="type" value="'.$type.'">';
- $html.='<button type="button" class="select_class">确定</button><button type="button" class="cancel">取消</button>';
- $html.='</p>';
- $result=array(
- 'status'=>1,
- 'html'=>$html
- );
- exit(json_encode($result));
- }
- /*保存年级班级文理分科*/
- public function actionSaveArtsAndScience(){
- $class_data=Req::post('class_data');
- $semesterId=Yii::app()->session['session_semester_id'];
- $result=array('status'=>0);
- if(!$class_data || !is_array($class_data)){
- exit(json_encode($result));
- }
- $err=array();
- $ClassModel=new SClass();
- foreach ($class_data as $key=>$val){
- if($key===0){
- continue; //年级id没有0
- }
- if($val=='close'){ //不分科
- SGrade::model()->updateAll(array('arts_science'=>1),'id=:id',array(':id'=>$key));
- $allClass=array();
- $ClassList=$ClassModel->getClassList('class_id',array("grade={$key} and semester_id={$semesterId}"));
- if($ClassList){
- foreach ($ClassList as $id){
- $allClass[]=$id['class_id'];
- }
- }
- if($allClass){
- $ClassModel->updateAll(array('arts_science'=>0),' class_id in('.implode(',',$allClass).')');
- }else{
- $err[]='没有班级数据,年级:'.$key;
- }
- }else{
- if(!is_array($val)){
- $err[]='班级数据有误,年级:'.$key;
- }
- foreach($val as $ke=>$class){
- if($ke===0){
- continue;
- }
- //查询当前已选择班级
- $oldClass=array();
- $ClassList=$ClassModel->getClassList('class_id',array("grade={$key} and arts_science={$ke} and semester_id={$semesterId}"));
- if($ClassList){
- foreach ($ClassList as $id){
- $oldClass[]=$id['class_id'];
- }
- }
- if($class){
- foreach ($class as $i=>$cid){
- if($oldClass && in_array((string)$cid,$oldClass,true)){
- unset($class[$i]);
- unset($oldClass[array_search((string)$cid,$oldClass,true)]);
- }
- }
- }
- //需要新增的
- if($class){
- $ClassModel->updateAll(array('arts_science'=>$ke),' class_id in('.implode(',',$class).')');
- }
- //需要清除状态的
- if($oldClass){
- $ClassModel->updateAll(array('arts_science'=>0),' class_id in('.implode(',',$oldClass).')');
- }
- }
- SGrade::model()->updateAll(array('arts_science'=>2),'id=:id',array(':id'=>$key));
- }
- }
- $result['status']=1;
- $result['err']=$err;
- exit(json_encode($result));
- }
- private function getHttp($url,$method,$params = array()){
- $res = http($url, $method, $this->authUsername, $params);
- $res = $this->handleRes($res);
- return $res;
- }
- /**
- * 处理接口返回的数据
- * @param $res
- * @return array
- */
- public function handleRes($res){
- $result = array(
- 'status' => 0,
- 'data' => array(),
- 'msg' => '暂无数据',
- );
- if($res){
- $res = json_decode($res,true);
- if(isset($res['errCode']) && $res['errCode'] == '00'){
- $result['status'] = 1;
- $result['data'] = isset($res['data'])?$res['data']:array();
- $result['msg'] = $res['errMsg'];
- }else{
- if(isset($res['errMsg'])){
- $result['msg'] = $res['errMsg'];
- }
- }
- }
- unset($res);
- return $result;
- }
- //加载未配置学科
- public function actionGetExtendSubjects(){
- //自定义学科设置
- $extendSubject=BusinessSubject::model()->findAll("is_basic=0 and section='".Yii::app()->params['section']."'");
- //已配置自定义学科
- $extendSubjectSchool=SExtendSubject::model()->findAll();
- $isHasSubject=array();
- if($extendSubjectSchool){
- foreach ($extendSubjectSchool as $item){
- $isHasSubject[$item->subject_id]=$item->subject_name;
- }
- }
- $html='';
- if($extendSubject){
- foreach ($extendSubject as $key=>$item){
- if(!isset($isHasSubject[$item['subject_id']])){
- $html.='<label><input type="checkbox" value="'.$item['subject_id'].'" name="extend_subject">'.$item['subject_name'].'</label>';
- }else{
- $html.='<label><input type="checkbox" disabled value="'.$item['subject_id'].'" name="extend_subject">'.$item['subject_name'].'</label>';
- }
- }
- }
- exit(json_encode(array('status'=>1,'data'=>$html)));
- }
- //保存自定义学科
- public function actionSaveExtendSubjects(){
- $subjects=Req::post('subjects');
- $result['status']=0;
- if(!$subjects || !is_array($subjects)){
- $result['msg']='请选择学科';
- exit(json_encode($result));
- }
- $extendSubject=BusinessSubject::model()->findAll("is_basic=0");
- foreach ($extendSubject as $val){
- $result[$val->subject_id]=$val->subject_name;
- }
- $insertData=array();
- foreach ($subjects as $val){
- $insertData[$val]=$result[$val];
- }
- if(SExtendSubject::model()->insertExtendSubject($insertData)){
- $result['status']=1;
- $result['msg']='操作成功';
- }
- exit(json_encode($result));
- }
- //删除自定义科目
- public function actionDelExtendSubject(){
- $subjectId=Req::post('subjectId');
- $result['status']=0;
- if(!$subjectId){
- $result['msg']='请选择学科';
- exit(json_encode($result));
- }
- //查询科目是否有教师
- if(SExtendSubject::model()->checkSubjectUsed($subjectId)){
- $result['msg']='该学科已有使用数据,不能删除';
- exit(json_encode($result));
- }
- if(SExtendSubject::model()->delExtendSubject($subjectId)){
- $result['status']=1;
- exit(json_encode($result));
- }
- //知了家校考试
- }
- //设置学生平板登录设备权限
- public function actionAjaxSettingLoginpermission()
- {
- $is_login_permission = (int)Req::post('setting_status');//0-多个设备 1-单个设备
- $result['status'] = 0;
- if (!in_array($is_login_permission, array(0, 1))) {
- $result['msg'] = '参数错误';
- exit(json_encode($result));
- }
- $schoolModel = new BusinessSchool();
- $now_permission = $schoolModel->updateLoginPermission($this->schoolId, $is_login_permission);
- require_once(Yii::app()->basePath . '/extensions/RedisLoginCtrl.php');
- foreach (range(0, RedisLoginCtrl::getRedisNum()) as $redisNun) {
- RedisLoginCtrl::getRedisObj($redisNun)->set('zsy:student_login_check:' . $this->schoolId, $now_permission);
- }
- //Yii::app()->stu_login_permission->setValue('zsy:student_login_check:' . $this->schoolId, $now_permission);
- if (!$now_permission) {
- $del_key = "zsy:school_login_key:" . $this->schoolId;
- $del_data = Yii::app()->stu_login_permission->lrange($del_key, 0, -1);
- if ($del_data) {
- foreach ($del_data as $k => $v) {
- Yii::app()->stu_login_permission->del($v);
- }
- Yii::app()->stu_login_permission->del($del_key);
- }
- }
- $result['status'] = 1;
- exit(json_encode($result));
- }
- //保存学段年级组设置
- public function actionSaveSection(){
- $gradeGroup=(int)Req::post('gradeGroup');
- $result['status']=0;
- if($gradeGroup==$this->schoolInfo['grade_group_id']){
- $result['msg']='学段设置与原设置相同';
- exit(json_encode($result));
- }
- //查询学制
- $gradeConfig = BusinessGradeConfig::model()->findAll("group_id=:sid",array(':sid'=>$gradeGroup));
- $businessRs=false;
- $transaction_conn = $this->conn->beginTransaction();
- try{
- $updateSql="update school set grade_group_id='{$gradeGroup}',grade_group_changed=1 where school_id='{$this->schoolId}'";
- $this->conn->createCommand($updateSql)->execute();
- $businessRs=true;
- }catch (\Exception $e){
- $transaction_conn->rollback();
- Yii::app()->jump->error('添加老师失败!');
- }
- if($businessRs){
- $transaction = $this->sConn->beginTransaction();
- try{
- foreach ($gradeConfig as $item){
- $check=$this->sConn->createCommand("select id from grade where id='{$item['grade_id']}'")->queryRow();
- if($check){
- $this->sConn->createCommand("update grade set grade_name='{$item['grade_name']}' where id='{$item['grade_id']}'")->execute();
- }else{
- $this->sConn->createCommand("insert into grade(`id`,`grade_name`,`card_length`,`card_status`,`arts_science`) values(".$item['grade_id'].",'".$item['grade_name']."',0,0,1)")->execute();
- }
- }
- $transaction_conn->commit();
- $transaction->commit();
- $result['status']=1;
- $result['msg']='学段设置成功';
- exit(json_encode($result));
- }catch (\Exception $e){
- $transaction->rollback();
- $transaction_conn->rollback();
- $result['msg']='学段设置失败';
- exit(json_encode($result));
- }
- }
- }
- //保存阅卷留痕设置
- public function actionMarkingSet(){
- $coordinate=(int)Req::post('coordinate');
- $updateSql="update school set marking_coordinate='{$coordinate}' where school_id='{$this->schoolId}'";
- $this->conn->createCommand($updateSql)->execute();
- Yii::app()->jump->success('保存成功',Yii::app()->createUrl('school/add'));
- }
- }
|