SchoolController.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898
  1. <?php
  2. /**
  3. * 学校管理控制器类
  4. * @author 李凯磊
  5. * @date 2016-08-31 10:50:00
  6. * @company 上海风车教育有限公司.
  7. */
  8. class SchoolController extends Controller{
  9. private $errors;
  10. public function actionadd(){
  11. $data['schoolinfo'] = BusinessSchool::model()->find("school_id=:sid",array(':sid'=>Yii::app()->session['coachInfo']['school_id']));
  12. //查询学段
  13. $data['gradeGroup'] = BusinessGradeGroup::model()->findAll("section=:sid",array(':sid'=>$data['schoolinfo']['section']));
  14. //查询学制
  15. $data['gradeConfig'] = BusinessGradeConfig::model()->findAll();
  16. $gradeArr=array();
  17. foreach ($data['gradeConfig'] as $datum){
  18. $gradeArr[$datum['group_id']][$datum['grade_id']]=$datum['grade_name'];
  19. }
  20. $data['gradeConfig'] = $gradeArr;
  21. $realGradeArr=array();
  22. $grade = SGrade::model()->findAll();
  23. foreach ($grade as $item){
  24. if(isset($gradeArr[$data['schoolinfo']['grade_group_id']][$item->id])){
  25. $realGradeArr[]=$item;
  26. }
  27. }
  28. $data['grade']=$realGradeArr;
  29. $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']})");
  30. $semesterId = Yii::app()->session['session_semester_id'];
  31. $classList = SClass::model()->findAll("semester_id=:semester_id and arts_science<>0 and is_hide=0 ",array(':semester_id'=>$semesterId));
  32. //读取学年
  33. $schoolYear=array();
  34. $period = $this->getHttp('sys/school/year/period/list', 'get');
  35. if($period['status']==1){
  36. $schoolYear=$period['data'];
  37. }
  38. $data['schoolYear']=$schoolYear;
  39. $detail = $this->getHttp('customer/school/coach/official/detail', 'get');
  40. if($detail){
  41. //学校概况
  42. if(isset($detail['data']['schoolProfile']['schoolBuildYear'])){
  43. $data['schoolprofile']['schoolBuildYear']=$detail['data']['schoolProfile']['schoolBuildYear']; //年份
  44. }else{
  45. $data['schoolprofile']['schoolBuildYear']=''; //年份
  46. }
  47. if(isset($detail['data']['schoolProfile']['studentCount'])){
  48. $data['schoolprofile']['studentCount']=$detail['data']['schoolProfile']['studentCount']; //规模
  49. }else{
  50. $data['schoolprofile']['studentCount']=''; //规模
  51. }
  52. if(isset($detail['data']['schoolProfile']['artsAndScience'])){
  53. $data['schoolprofile']['artsAndScience']=$detail['data']['schoolProfile']['artsAndScience'];
  54. }else{
  55. $data['schoolprofile']['artsAndScience']='';
  56. }
  57. if(isset($detail['data']['schoolProfile']['bookVersion'])){
  58. $data['schoolprofile']['bookVersion']=$detail['data']['schoolProfile']['bookVersion'];
  59. }else{
  60. $data['schoolprofile']['bookVersion']='';
  61. }
  62. if(isset($detail['data']['schoolProfile']['schoolNature'])){
  63. $data['schoolprofile']['schoolNature']=$detail['data']['schoolProfile']['schoolNature']; //学校性质
  64. }else{
  65. $data['schoolprofile']['schoolNature']=''; //学校性质
  66. }
  67. if(isset($detail['data']['schoolProfile']['schoolType'])){
  68. $data['schoolprofile']['schoolType']=$detail['data']['schoolProfile']['schoolType']; //学校类型
  69. }else{
  70. $data['schoolprofile']['schoolType']='0'; //学校类型
  71. }
  72. if(isset($detail['data']['schoolProfile']['isMinority'])){
  73. $data['schoolprofile']['isMinority']=$detail['data']['schoolProfile']['isMinority']; //是否设置少数民族
  74. }else{
  75. $data['schoolprofile']['isMinority']=''; //是否设置少数民族
  76. }
  77. if(isset($detail['data']['schoolProfile']['isStaying'])){
  78. $data['schoolprofile']['isStaying']=$detail['data']['schoolProfile']['isStaying']; //寄宿制形式
  79. }else{
  80. $data['schoolprofile']['isStaying']=''; //寄宿制形式
  81. }
  82. //升学率
  83. if(isset($detail['data']['upRates'])){
  84. $data['schoolentrancerate'] =$detail['data']['upRates'];
  85. }else{
  86. $data['schoolentrancerate'] =array();
  87. }
  88. //规模
  89. if(isset($detail['data']['scaleResDTOS'])){
  90. $data['scale']=$detail['data']['scaleResDTOS'];
  91. }else{
  92. $data['scale']=array();
  93. }
  94. //联系方式
  95. if(isset($detail['data']['schoolContact']['schoolMasterName'])){
  96. $data['schoocontact']['schoolMasterName']=$detail['data']['schoolContact']['schoolMasterName'];
  97. }else{
  98. $data['schoocontact']['schoolMasterName']='';
  99. }
  100. if(isset($detail['data']['schoolContact']['schoolMasterMobile'])){
  101. $data['schoocontact']['schoolMasterMobile']=$detail['data']['schoolContact']['schoolMasterMobile'];
  102. }else{
  103. $data['schoocontact']['schoolMasterMobile']='';
  104. }
  105. if(isset($detail['data']['schoolContact']['schoolMaster2Name'])){
  106. $data['schoocontact']['schoolMaster2Name']=$detail['data']['schoolContact']['schoolMaster2Name'];
  107. }else{
  108. $data['schoocontact']['schoolMaster2Name']='';
  109. }
  110. if(isset($detail['data']['schoolContact']['schoolMaster2Mobile'])){
  111. $data['schoocontact']['schoolMaster2Mobile']=$detail['data']['schoolContact']['schoolMaster2Mobile'];
  112. }else{
  113. $data['schoocontact']['schoolMaster2Mobile']='';
  114. }
  115. if(isset($detail['data']['schoolContact']['grade1HeadName'])){
  116. $data['schoocontact']['grade1HeadName']=$detail['data']['schoolContact']['grade1HeadName'];
  117. }else{
  118. $data['schoocontact']['grade1HeadName']='';
  119. }
  120. if(isset($detail['data']['schoolContact']['grade1HeadMobile'])){
  121. $data['schoocontact']['grade1HeadMobile']=$detail['data']['schoolContact']['grade1HeadMobile'];
  122. }else{
  123. $data['schoocontact']['grade1HeadMobile']='';
  124. }
  125. if(isset($detail['data']['schoolContact']['grade2HeadName'])){
  126. $data['schoocontact']['grade2HeadName']=$detail['data']['schoolContact']['grade2HeadName'];
  127. }else{
  128. $data['schoocontact']['grade2HeadName']='';
  129. }
  130. if(isset($detail['data']['schoolContact']['grade2HeadMobile'])){
  131. $data['schoocontact']['grade2HeadMobile']=$detail['data']['schoolContact']['grade2HeadMobile'];
  132. }else{
  133. $data['schoocontact']['grade2HeadMobile']='';
  134. }
  135. if(isset($detail['data']['schoolContact']['grade3HeadName'])){
  136. $data['schoocontact']['grade3HeadName']=$detail['data']['schoolContact']['grade3HeadName'];
  137. }else{
  138. $data['schoocontact']['grade3HeadName']='';
  139. }
  140. if(isset($detail['data']['schoolContact']['grade3HeadMobile'])){
  141. $data['schoocontact']['grade3HeadMobile']=$detail['data']['schoolContact']['grade3HeadMobile'];
  142. }else{
  143. $data['schoocontact']['grade3HeadMobile']='';
  144. }
  145. }
  146. //处理文理科分班情况
  147. foreach ($data['grade'] as $grade){
  148. if($grade['arts_science']==1){
  149. //不分科
  150. }elseif($grade['arts_science']==2){
  151. //查询班级
  152. foreach ($classList as $class){
  153. if($class['grade']==$grade['id'] ){
  154. $data['arts_science'][$grade['id']][$class['arts_science']]['ids'][]=$class['class_id'];
  155. $data['arts_science'][$grade['id']][$class['arts_science']]['names'][]=$class['class_name'];
  156. }
  157. }
  158. }
  159. }
  160. //自定义学科设置
  161. $data['extendSubject']=BusinessSubject::model()->findAll("is_basic=0");
  162. //已配置自定义学科
  163. $extendSubjectSchool=SExtendSubject::model()->findAll();
  164. if($extendSubjectSchool){
  165. foreach ($extendSubjectSchool as $key => $val){
  166. $data['extendSubjectSchool'][$val['subject_id']]['subject_id']=$val['subject_id'];
  167. $data['extendSubjectSchool'][$val['subject_id']]['subject_name']=$val['subject_name'];
  168. if(SExtendSubject::model()->checkSubjectUsed($val['subject_id'])){
  169. $data['extendSubjectSchool'][$val['subject_id']]['used']=1;
  170. }else{
  171. $data['extendSubjectSchool'][$val['subject_id']]['used']=0;
  172. }
  173. }
  174. }
  175. $_num= '';
  176. $use_version = '';
  177. if(isset(Yii::app()->session['coachInfo']->use_version))
  178. {
  179. $use_version = Yii::app()->session['coachInfo']->use_version;
  180. }else
  181. {
  182. $use_version = Yii::app()->session['coachInfo']['use_version'];
  183. }
  184. if(!$use_version)
  185. {
  186. $use_version = 100;
  187. }
  188. $version_number = implode('',explode('.',$use_version));
  189. if(strlen($version_number)<7)
  190. {
  191. for($i=0;$i<7-strlen($version_number);$i++)
  192. {
  193. $_num.='0';
  194. }
  195. }
  196. $version_number=(int)$version_number.$_num;
  197. //获取学校的安全与隐私配置
  198. $schoolPrivate = new BSchoolPrivate();
  199. $isPrivate = $schoolPrivate->getPrivate($this->schoolId);
  200. $data['is_private'] = $isPrivate;
  201. //debug($data);
  202. //获取学校平板登陆权限配置
  203. $data['login_permission'] = $data['schoolinfo']['is_login_permission'];
  204. if(Yii::app()->params['section']==0){
  205. $this->render('add_section',$data);
  206. }else{
  207. $this->render('add2',$data);
  208. }
  209. }
  210. public function actionSaveSchoolPrivate(){
  211. if (Yii::app()->request->getIsPostRequest()){
  212. $is_private = Req::post('is_private');
  213. $model = new BSchoolPrivate();
  214. $result = $model->savePrivate($this->schoolId, $is_private);
  215. if ($result){
  216. returnMsg(1,'保存成功');
  217. }else{
  218. returnMsg(0,'保存失败');
  219. }
  220. }else{
  221. returnMsg(0,"非法请求");
  222. }
  223. }
  224. public function actioninsert(){
  225. if (Yii::app()->request->getIsPostRequest())
  226. {
  227. $card_length = Req::post("card_length");
  228. $card_status = Req::post("card_status");
  229. $_err = array();
  230. $business_student_data = BusinessStudent::model()->findAll('school_id=:school_id',array(':school_id'=>$this->schoolId));
  231. if($business_student_data)
  232. {
  233. foreach($business_student_data as $v)
  234. {
  235. if($v->school_student_card)
  236. {
  237. if(strlen($v->school_student_card)!=$card_length)
  238. {
  239. $_err[] = '学生准考证号长度存在不等于'.$card_length.'位!';
  240. continue;
  241. }
  242. }
  243. }
  244. BusinessSchool::model()->updateAll(array('card_length'=>$card_length,'card_status'=>$card_status),'school_id=:school_id',array(':school_id'=>$this->schoolId));
  245. if($_err)
  246. {
  247. Yii::app()->jump->setSuccessWait(8);
  248. Yii::app()->jump->success('保存成功<br>但学生准考证号长度存在不等于'.$card_length.'位,请修改学生学校准考证号<br><br>',Yii::app()->createUrl('school/add'));exit;
  249. }
  250. Yii::app()->jump->success('保存成功',Yii::app()->createUrl('school/add'));
  251. }else
  252. {
  253. Yii::app()->jump->error('此学校没有学生,请先导入学生!');
  254. }
  255. }
  256. }
  257. /**
  258. * 设置学校准考证号
  259. */
  260. public function actionGrade_insert()
  261. {
  262. if (Yii::app()->request->getIsPostRequest())
  263. {
  264. $_err = array();
  265. foreach (Yii::app()->params['grade_list'] as $id =>$val){
  266. if(Req::post("card_status".$id)){
  267. $data = $this->get_card_length($id,Req::post("card_length".$id));
  268. if($data){
  269. $_err[$id] = $data;
  270. }
  271. }
  272. }
  273. foreach (Yii::app()->params['grade_list'] as $id =>$val){
  274. if(isset($_POST['card_status'.$id])){
  275. $cardLength=Req::post("card_length".$id);
  276. $cardStatus=Req::post("card_status".$id);
  277. if(!$cardLength) $cardLength=0;
  278. SGrade::model()->updateAll(array('card_length'=>$cardLength,'card_status'=>$cardStatus),'id=:id',array(':id'=>$id));
  279. }
  280. }
  281. if($_err){
  282. Yii::app()->jump->setSuccessWait(8);
  283. Yii::app()->jump->setHeight(240);
  284. $str='';
  285. foreach ($_err as $grade =>$item){
  286. $str.=Yii::app()->params['grade_list'][$grade]['grade_name'].'学生准考证号长度存在不等于'.Req::post("card_length".$grade).'位,请修改学生学校准考证号';
  287. }
  288. Yii::app()->jump->error($str,Yii::app()->createUrl('school/add'));exit;
  289. }else{
  290. Yii::app()->jump->success('保存成功',Yii::app()->createUrl('school/add'));exit;
  291. }
  292. }else
  293. {
  294. Yii::app()->jump->error('不能多次提交',Yii::app()->createUrl('school/add'));exit;
  295. }
  296. }
  297. protected function get_card_length($grade,$card_length)
  298. {
  299. $class_data = ClassModel::model()->findAll('grade=:grade and semester_id=:semester_id',array(':grade'=>$grade,':semester_id'=>$this->semesterId));
  300. $class_ids = array();
  301. $student_ids = array();
  302. $_err = array();
  303. if($class_data)
  304. {
  305. foreach($class_data as $v)
  306. {
  307. $class_ids[$v->class_id] = $v->class_id;
  308. }
  309. $criteria = new CDbCriteria();
  310. $criteria->addInCondition('class_id',$class_ids);
  311. $criteria->addCondition('status=:status');
  312. $criteria->params[':status'] = 0;
  313. $student_class_data = SStudentClassRelation::model()->findAll($criteria);
  314. if($student_class_data)
  315. {
  316. foreach($student_class_data as $v)
  317. {
  318. $student_ids[$v->student_id] = $v->student_id;
  319. }
  320. unset($criteria);
  321. $business_student_data=$this->schoolManager->getStudentByCardLength($student_ids,$card_length);
  322. if($business_student_data){
  323. $_err[] = '学生准考证号长度存在不等于'.$card_length.'位!';
  324. }
  325. /*
  326. $criteria = new CDbCriteria();
  327. $criteria->addInCondition('student_id',$student_ids);
  328. $business_student_data = BusinessStudent::model()->findAll($criteria);
  329. if($business_student_data)
  330. {
  331. foreach($business_student_data as $v)
  332. {
  333. if($v->school_student_card)
  334. {
  335. if(strlen($v->school_student_card)!=$card_length)
  336. {
  337. $_err[] = '学生准考证号长度存在不等于'.$card_length.'位!';
  338. continue;
  339. }
  340. }
  341. }
  342. }
  343. */
  344. }
  345. }
  346. return $_err;
  347. }
  348. //联系人
  349. public function actionContact_insert()
  350. {
  351. $params=array();
  352. $params['schoolMasterName'] = Req::post("schoolMasterName");
  353. $params['schoolMasterMobile'] = Req::post("schoolMasterMobile");
  354. $params['schoolMaster2Name'] = Req::post("schoolMaster2Name");
  355. $params['schoolMaster2Mobile'] = Req::post("schoolMaster2Mobile");
  356. $params['grade1HeadName'] = Req::post("grade1HeadName");
  357. $params['grade1HeadMobile'] = Req::post("grade1HeadMobile");
  358. $params['grade2HeadName'] = Req::post("grade2HeadName");
  359. $params['grade2HeadMobile'] = Req::post("grade2HeadMobile");
  360. $params['grade3HeadName'] = Req::post("grade3HeadName");
  361. $params['grade3HeadMobile'] = Req::post("grade3HeadMobile");
  362. $params['schoolId']=$this->schoolId;
  363. $res = $this->getHttp('customer/school/coach/contact', 'put',$params);
  364. if ($res['status'] == 1) {
  365. Yii::app()->jump->success('保存成功',Yii::app()->createUrl('school/add'));
  366. } else {
  367. Yii::app()->jump->error($res['msg']);
  368. }
  369. }
  370. public function actionAjax_student()
  371. {
  372. $card_length = Req::post("card_length");
  373. $business_student_data = BusinessStudent::model()->findAll('school_id=:school_id',array(':school_id'=>$this->schoolId));
  374. if($business_student_data)
  375. {
  376. foreach($business_student_data as $v)
  377. {
  378. if($v->school_student_card)
  379. {
  380. if(strlen($v->school_student_card) != $card_length)
  381. {
  382. echo json_encode(array('status'=>1,'msg'=>'学生准考证号长度存在不等于'.$card_length.'位!'));exit;
  383. }
  384. }
  385. }
  386. echo json_encode(array('status'=>0,'msg'=>''));exit;
  387. }else
  388. {
  389. echo json_encode(array('status'=>1,'msg'=>'此学校没有学生,请先导入学生!'));exit;
  390. }
  391. }
  392. public function actionSetusewp()
  393. {
  394. $use_wp = Req::post("use_wp");
  395. if(false !== BusinessSchool::model()->updateAll(
  396. array('use_wp'=>$use_wp),'school_id=:sid',array(':sid'=>Yii::app()->session['coachInfo']['school_id'])))
  397. {
  398. echo json_encode(array('status'=>1,'wp'=>$use_wp));exit;
  399. }
  400. echo json_encode(array('status'=>0));exit;
  401. }
  402. /**
  403. * 学校概况
  404. */
  405. public function actionProfile_insert()
  406. {
  407. $profile=$_POST['profile'];
  408. $params=array();
  409. $params['schoolId']=$this->schoolId;
  410. $params['schoolBuildYear']=$profile['schoolBuildYear'];
  411. $params['schoolNature']=$profile['schoolNature'];
  412. $params['isMinority']=$profile['isMinority'];
  413. $params['isStaying']=intval($profile['isStaying']);
  414. // $params['studentCount']=$profile['studentCount'];
  415. $params['schoolType']=$profile['schoolType'];
  416. if(isset($profile['bookVersion'])){
  417. $params['bookVersion']=$profile['bookVersion'];
  418. }else{
  419. $params['bookVersion']=0;
  420. }
  421. $params['artsAndScience']=$profile['artsAndScience'];
  422. $upRates=array();
  423. if(Yii::app()->params['section']==0){
  424. if(isset($_POST['schoolYear']) && $_POST['schoolYear']){
  425. foreach ($_POST['schoolYear'] as $key => $val){
  426. $upRates[]=array(
  427. 'schoolYearId'=>$val,
  428. 'highSchoolRate'=>$_POST['upRate'][$key],
  429. 'level1Rate'=>0,
  430. 'level2Rate'=>0,
  431. 'level3Rate'=>0,
  432. );
  433. }
  434. }
  435. }else{
  436. if(isset($_POST['schoolYear']) && $_POST['schoolYear']){
  437. foreach ($_POST['schoolYear'] as $key => $val){
  438. $upRates[]=array(
  439. 'schoolYearId'=>$val,
  440. 'level1Rate'=>$_POST['level1Rate'][$key],
  441. 'level2Rate'=>$_POST['level2Rate'][$key],
  442. 'level3Rate'=>$_POST['level3Rate'][$key],
  443. 'highSchoolRate'=>0
  444. );
  445. }
  446. }
  447. }
  448. if($upRates){
  449. $params['upRates']=$upRates;
  450. }
  451. $scaleResDTOS=array();
  452. if(Yii::app()->params['section']==0){
  453. if(isset($_POST['schoolScale']) && $_POST['schoolScale']){
  454. foreach ($_POST['schoolScale'] as $key => $val){
  455. $scaleResDTOS[]=array(
  456. 'schoolYearId'=>$val,
  457. 'gradeOne'=>0,
  458. 'gradeTwo'=>0,
  459. 'gradeThree'=>0,
  460. 'highSchoolSix'=>$_POST['highSchoolSix'][$key],
  461. 'highSchoolSeven'=>$_POST['highSchoolSeven'][$key],
  462. 'highSchoolEight'=>$_POST['highSchoolEight'][$key],
  463. 'highSchoolNine'=>$_POST['highSchoolNine'][$key],
  464. );
  465. }
  466. }
  467. }else{
  468. if(isset($_POST['schoolScale']) && $_POST['schoolScale']){
  469. foreach ($_POST['schoolScale'] as $key => $val){
  470. $scaleResDTOS[]=array(
  471. 'schoolYearId'=>$val,
  472. 'gradeOne'=>$_POST['gradeOne'][$key],
  473. 'gradeTwo'=>$_POST['gradeTwo'][$key],
  474. 'gradeThree'=>$_POST['gradeThree'][$key],
  475. 'highSchoolSix'=>0,
  476. 'highSchoolSeven'=>0,
  477. 'highSchoolEight'=>0,
  478. 'highSchoolNine'=>0,
  479. );
  480. }
  481. }
  482. }
  483. if($scaleResDTOS){
  484. $params['scaleDTOS']=$scaleResDTOS;
  485. }
  486. $res = $this->getHttp('customer/school/coach/profile-uprate', 'put',$params);
  487. if ($res['status'] == 1) {
  488. Yii::app()->jump->success('保存成功',Yii::app()->createUrl('school/add'));
  489. } else {
  490. Yii::app()->jump->error($res['msg']);
  491. }
  492. }
  493. /*读取所有班级*/
  494. public function actionGetClass(){
  495. $grade_id = Req::post("grade_id"); //年级
  496. $title = Req::post("title");
  497. $type = Req::post("type");
  498. $selected_class_id=Req::post('selected_class_id');
  499. $semesterId=Yii::app()->session['session_semester_id'];
  500. if($selected_class_id){
  501. $SelectedClassArr=explode(',',$selected_class_id);
  502. }else{
  503. $SelectedClassArr=array();
  504. }
  505. $class_data = ClassModel::model()->findAll('semester_id=:semester_id and grade=:grade and is_hide=0',array(':semester_id'=>$semesterId,':grade'=>$grade_id));
  506. $html=' <i class="icon icon-close"></i><div class="class-modal-head">'.$title.'</div>';
  507. $html.='<div class="class-modal-body">';
  508. foreach ($class_data as $subject=>$class){
  509. if($SelectedClassArr && in_array((string)$class['class_id'],$SelectedClassArr,true)){
  510. $html.='<label><input type="checkbox" checked value="'.$class['class_id'].'" name="'.$class['class_name'].'">'.$class['class_name'].'</label>';
  511. }else{
  512. $html.='<label><input type="checkbox" value="'.$class['class_id'].'" name="'.$class['class_name'].'">'.$class['class_name'].'</label>';
  513. }
  514. }
  515. $html.='</div>';
  516. $html.='<p class="class_btn">';
  517. $html.='<input type="hidden" name="grade_id" value="'.$grade_id.'">';
  518. $html.='<input type="hidden" name="type" value="'.$type.'">';
  519. $html.='<button type="button" class="select_class">确定</button><button type="button" class="cancel">取消</button>';
  520. $html.='</p>';
  521. $result=array(
  522. 'status'=>1,
  523. 'html'=>$html
  524. );
  525. exit(json_encode($result));
  526. }
  527. /*保存年级班级文理分科*/
  528. public function actionSaveArtsAndScience(){
  529. $class_data=Req::post('class_data');
  530. $semesterId=Yii::app()->session['session_semester_id'];
  531. $result=array('status'=>0);
  532. if(!$class_data || !is_array($class_data)){
  533. exit(json_encode($result));
  534. }
  535. $err=array();
  536. $ClassModel=new SClass();
  537. foreach ($class_data as $key=>$val){
  538. if($key===0){
  539. continue; //年级id没有0
  540. }
  541. if($val=='close'){ //不分科
  542. SGrade::model()->updateAll(array('arts_science'=>1),'id=:id',array(':id'=>$key));
  543. $allClass=array();
  544. $ClassList=$ClassModel->getClassList('class_id',array("grade={$key} and semester_id={$semesterId}"));
  545. if($ClassList){
  546. foreach ($ClassList as $id){
  547. $allClass[]=$id['class_id'];
  548. }
  549. }
  550. if($allClass){
  551. $ClassModel->updateAll(array('arts_science'=>0),' class_id in('.implode(',',$allClass).')');
  552. }else{
  553. $err[]='没有班级数据,年级:'.$key;
  554. }
  555. }else{
  556. if(!is_array($val)){
  557. $err[]='班级数据有误,年级:'.$key;
  558. }
  559. foreach($val as $ke=>$class){
  560. if($ke===0){
  561. continue;
  562. }
  563. //查询当前已选择班级
  564. $oldClass=array();
  565. $ClassList=$ClassModel->getClassList('class_id',array("grade={$key} and arts_science={$ke} and semester_id={$semesterId}"));
  566. if($ClassList){
  567. foreach ($ClassList as $id){
  568. $oldClass[]=$id['class_id'];
  569. }
  570. }
  571. if($class){
  572. foreach ($class as $i=>$cid){
  573. if($oldClass && in_array((string)$cid,$oldClass,true)){
  574. unset($class[$i]);
  575. unset($oldClass[array_search((string)$cid,$oldClass,true)]);
  576. }
  577. }
  578. }
  579. //需要新增的
  580. if($class){
  581. $ClassModel->updateAll(array('arts_science'=>$ke),' class_id in('.implode(',',$class).')');
  582. }
  583. //需要清除状态的
  584. if($oldClass){
  585. $ClassModel->updateAll(array('arts_science'=>0),' class_id in('.implode(',',$oldClass).')');
  586. }
  587. }
  588. SGrade::model()->updateAll(array('arts_science'=>2),'id=:id',array(':id'=>$key));
  589. }
  590. }
  591. $result['status']=1;
  592. $result['err']=$err;
  593. exit(json_encode($result));
  594. }
  595. private function getHttp($url,$method,$params = array()){
  596. $res = http($url, $method, $this->authUsername, $params);
  597. $res = $this->handleRes($res);
  598. return $res;
  599. }
  600. /**
  601. * 处理接口返回的数据
  602. * @param $res
  603. * @return array
  604. */
  605. public function handleRes($res){
  606. $result = array(
  607. 'status' => 0,
  608. 'data' => array(),
  609. 'msg' => '暂无数据',
  610. );
  611. if($res){
  612. $res = json_decode($res,true);
  613. if(isset($res['errCode']) && $res['errCode'] == '00'){
  614. $result['status'] = 1;
  615. $result['data'] = isset($res['data'])?$res['data']:array();
  616. $result['msg'] = $res['errMsg'];
  617. }else{
  618. if(isset($res['errMsg'])){
  619. $result['msg'] = $res['errMsg'];
  620. }
  621. }
  622. }
  623. unset($res);
  624. return $result;
  625. }
  626. //加载未配置学科
  627. public function actionGetExtendSubjects(){
  628. //自定义学科设置
  629. $extendSubject=BusinessSubject::model()->findAll("is_basic=0 and section='".Yii::app()->params['section']."'");
  630. //已配置自定义学科
  631. $extendSubjectSchool=SExtendSubject::model()->findAll();
  632. $isHasSubject=array();
  633. if($extendSubjectSchool){
  634. foreach ($extendSubjectSchool as $item){
  635. $isHasSubject[$item->subject_id]=$item->subject_name;
  636. }
  637. }
  638. $html='';
  639. if($extendSubject){
  640. foreach ($extendSubject as $key=>$item){
  641. if(!isset($isHasSubject[$item['subject_id']])){
  642. $html.='<label><input type="checkbox" value="'.$item['subject_id'].'" name="extend_subject">'.$item['subject_name'].'</label>';
  643. }else{
  644. $html.='<label><input type="checkbox" disabled value="'.$item['subject_id'].'" name="extend_subject">'.$item['subject_name'].'</label>';
  645. }
  646. }
  647. }
  648. exit(json_encode(array('status'=>1,'data'=>$html)));
  649. }
  650. //保存自定义学科
  651. public function actionSaveExtendSubjects(){
  652. $subjects=Req::post('subjects');
  653. $result['status']=0;
  654. if(!$subjects || !is_array($subjects)){
  655. $result['msg']='请选择学科';
  656. exit(json_encode($result));
  657. }
  658. $extendSubject=BusinessSubject::model()->findAll("is_basic=0");
  659. foreach ($extendSubject as $val){
  660. $result[$val->subject_id]=$val->subject_name;
  661. }
  662. $insertData=array();
  663. foreach ($subjects as $val){
  664. $insertData[$val]=$result[$val];
  665. }
  666. if(SExtendSubject::model()->insertExtendSubject($insertData)){
  667. $result['status']=1;
  668. $result['msg']='操作成功';
  669. }
  670. exit(json_encode($result));
  671. }
  672. //删除自定义科目
  673. public function actionDelExtendSubject(){
  674. $subjectId=Req::post('subjectId');
  675. $result['status']=0;
  676. if(!$subjectId){
  677. $result['msg']='请选择学科';
  678. exit(json_encode($result));
  679. }
  680. //查询科目是否有教师
  681. if(SExtendSubject::model()->checkSubjectUsed($subjectId)){
  682. $result['msg']='该学科已有使用数据,不能删除';
  683. exit(json_encode($result));
  684. }
  685. if(SExtendSubject::model()->delExtendSubject($subjectId)){
  686. $result['status']=1;
  687. exit(json_encode($result));
  688. }
  689. //知了家校考试
  690. }
  691. //设置学生平板登录设备权限
  692. public function actionAjaxSettingLoginpermission()
  693. {
  694. $is_login_permission = (int)Req::post('setting_status');//0-多个设备 1-单个设备
  695. $result['status'] = 0;
  696. if (!in_array($is_login_permission, array(0, 1))) {
  697. $result['msg'] = '参数错误';
  698. exit(json_encode($result));
  699. }
  700. $schoolModel = new BusinessSchool();
  701. $now_permission = $schoolModel->updateLoginPermission($this->schoolId, $is_login_permission);
  702. require_once(Yii::app()->basePath . '/extensions/RedisLoginCtrl.php');
  703. foreach (range(0, RedisLoginCtrl::getRedisNum()) as $redisNun) {
  704. RedisLoginCtrl::getRedisObj($redisNun)->set('zsy:student_login_check:' . $this->schoolId, $now_permission);
  705. }
  706. //Yii::app()->stu_login_permission->setValue('zsy:student_login_check:' . $this->schoolId, $now_permission);
  707. if (!$now_permission) {
  708. $del_key = "zsy:school_login_key:" . $this->schoolId;
  709. $del_data = Yii::app()->stu_login_permission->lrange($del_key, 0, -1);
  710. if ($del_data) {
  711. foreach ($del_data as $k => $v) {
  712. Yii::app()->stu_login_permission->del($v);
  713. }
  714. Yii::app()->stu_login_permission->del($del_key);
  715. }
  716. }
  717. $result['status'] = 1;
  718. exit(json_encode($result));
  719. }
  720. //保存学段年级组设置
  721. public function actionSaveSection(){
  722. $gradeGroup=(int)Req::post('gradeGroup');
  723. $result['status']=0;
  724. if($gradeGroup==$this->schoolInfo['grade_group_id']){
  725. $result['msg']='学段设置与原设置相同';
  726. exit(json_encode($result));
  727. }
  728. //查询学制
  729. $gradeConfig = BusinessGradeConfig::model()->findAll("group_id=:sid",array(':sid'=>$gradeGroup));
  730. $businessRs=false;
  731. $transaction_conn = $this->conn->beginTransaction();
  732. try{
  733. $updateSql="update school set grade_group_id='{$gradeGroup}',grade_group_changed=1 where school_id='{$this->schoolId}'";
  734. $this->conn->createCommand($updateSql)->execute();
  735. $businessRs=true;
  736. }catch (\Exception $e){
  737. $transaction_conn->rollback();
  738. Yii::app()->jump->error('添加老师失败!');
  739. }
  740. if($businessRs){
  741. $transaction = $this->sConn->beginTransaction();
  742. try{
  743. foreach ($gradeConfig as $item){
  744. $check=$this->sConn->createCommand("select id from grade where id='{$item['grade_id']}'")->queryRow();
  745. if($check){
  746. $this->sConn->createCommand("update grade set grade_name='{$item['grade_name']}' where id='{$item['grade_id']}'")->execute();
  747. }else{
  748. $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();
  749. }
  750. }
  751. $transaction_conn->commit();
  752. $transaction->commit();
  753. $result['status']=1;
  754. $result['msg']='学段设置成功';
  755. exit(json_encode($result));
  756. }catch (\Exception $e){
  757. $transaction->rollback();
  758. $transaction_conn->rollback();
  759. $result['msg']='学段设置失败';
  760. exit(json_encode($result));
  761. }
  762. }
  763. }
  764. //保存阅卷留痕设置
  765. public function actionMarkingSet(){
  766. $coordinate=(int)Req::post('coordinate');
  767. $updateSql="update school set marking_coordinate='{$coordinate}' where school_id='{$this->schoolId}'";
  768. $this->conn->createCommand($updateSql)->execute();
  769. Yii::app()->jump->success('保存成功',Yii::app()->createUrl('school/add'));
  770. }
  771. }