ParentController.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. <?php
  2. /**
  3. * 班级管理控制器类
  4. * @author jiangfei
  5. * @date 2015-09-22 10:50:00
  6. * @company 上海风车教育有限公司.
  7. */
  8. class ParentController extends Controller{
  9. // 首页
  10. public function actionIndex(){
  11. $data = array();
  12. $realname = Req::get("realname");
  13. $grade_id = Req::get("grade_id");
  14. $arts_science = Req::get("arts_science");
  15. $_teachers = array();
  16. // 获取所有学期
  17. $criteria = new CDbCriteria;
  18. $criteria->limit = 10;
  19. $criteria->order = "create_time desc";
  20. $allSemester = Semester::model()->findAll($criteria);
  21. $smid = safe_replace(Yii::app()->request->getParam('semesterId'));
  22. if(empty($smid)){
  23. $semeseter_id = $this->semesterId;
  24. }
  25. else{
  26. $semeseter_id = $smid;
  27. }
  28. $semesterId = $semeseter_id;
  29. // 判断是否教员组长
  30. if($semesterId){
  31. if($grade_id)
  32. {
  33. $con[] = "seme.semester_id = '{$semesterId}'";
  34. $con[] = "c.grade=".$grade_id;
  35. }else
  36. {
  37. $con[] = "seme.semester_id = '{$semesterId}'";
  38. }
  39. if($realname)
  40. {
  41. $_class_ids = $this->schoolManager->getTeachersByteacherName($realname);
  42. if($_class_ids)
  43. {
  44. $con[] = "c.class_id in (".implode(',',$_class_ids).")";
  45. }else
  46. {
  47. $con[] = "c.class_id in (0)";
  48. }
  49. }
  50. if($arts_science){
  51. $con[] = "c.arts_science=".$arts_science;
  52. }
  53. $con[] = " c.is_hide=0 ";
  54. $rs = $this->schoolManager->getClassesDetailListre($con,9);
  55. }
  56. if($rs["rs"]){
  57. foreach($rs["rs"] as $key => $class){
  58. $students=$this->schoolManager->getStudentIdByClassId($class['class_id']);
  59. if($students){
  60. $rs['rs'][$key]['student_count']=count($students);
  61. $rs['rs'][$key]['student_bind_count']=$this->schoolManager->countBindStudentIds($students,$this->schoolId);
  62. }else{
  63. $rs['rs'][$key]['student_count']=0;
  64. $rs['rs'][$key]['student_bind_count']=0;
  65. }
  66. }
  67. }
  68. $currSemester = $this->schoolManager->getCurrSemester();
  69. $data["grade_id"] = $grade_id;
  70. $data["arts_science"] = $arts_science;
  71. $data["realname"] = $realname;
  72. $data["currSemester"] = $currSemester;
  73. $data['yearsList'] = $rs["rs"];
  74. $data['pages'] = $rs["pager"];
  75. $data['page_total'] = $rs["pager"]->rowsCount;
  76. $data['semeseter_id'] = $semeseter_id;
  77. $data["semesters"] = $allSemester;
  78. $data["semesterId"] = $semesterId;
  79. $data["thisSemester"] = $this->schoolManager->getSemester($semesterId);
  80. $this->render('index',$data);
  81. }
  82. public function actionView(){
  83. $get_id = safe_replace(Yii::app()->request->getQuery('cid'));
  84. if (empty($get_id)) {
  85. Yii::app()->jump->error('无法访问!');
  86. }
  87. $class_info=$this->schoolManager->getClass($get_id);
  88. if(!$class_info){
  89. Yii::app()->jump->error('无法访问!');
  90. }
  91. $get_list = $this->schoolManager->getClassStudentsList($get_id);
  92. $teachers = $this->schoolManager->getTeachersByClassesIds(array($get_id));
  93. $subject=array();
  94. $subjectTid=array();
  95. $class_bzr='';
  96. $class_bzr_id='';
  97. $studentIds=array();
  98. $bzr_subject=0;
  99. //班主任
  100. if($class_info['teacher_id']){
  101. $class_bzr_id=$class_info['teacher_id'];
  102. $class_bzr=Teacher::model()->getTeacherName($class_bzr_id);
  103. }
  104. if($teachers){
  105. foreach ($teachers as $val){
  106. $subject[$val['subjects']]=$val['teacher_name'];
  107. $subjectTid[$val['subjects']]=$val['teacher_id'];
  108. }
  109. }
  110. /*
  111. if($bzr_subject && !isset($subject[$bzr_subject])){
  112. $subject[$bzr_subject]=$class_bzr;
  113. $subjectTid[$bzr_subject]=$class_bzr_id;
  114. }
  115. */
  116. foreach ($get_list['rs'] as $val){
  117. $studentIds[]=$val['student_id'];
  118. }
  119. $parentRole=array('0'=>'爸爸','1'=>'妈妈','2'=>'爷爷','3'=>'奶奶','4'=>'叔叔','5'=>'阿姨','6'=>'家长','7'=>'本人','8'=>'其他');
  120. $parents=$this->schoolManager->getParentByStudentIds($studentIds,$this->schoolId);
  121. foreach ($get_list['rs'] as $key => $val){
  122. if(isset($parents[$val['student_id']])){
  123. foreach ($parents[$val['student_id']] as $k => $v){
  124. if(isset($parentRole[$v['type']])){
  125. $parents[$val['student_id']][$k]['type']=$parentRole[$v['type']];
  126. }else{
  127. $parents[$val['student_id']][$k]['type']='';
  128. }
  129. }
  130. $get_list['rs'][$key]['parents']=$parents[$val['student_id']];
  131. $get_list['rs'][$key]['is_bind']=1;
  132. }else{
  133. $get_list['rs'][$key]['is_bind']=0;
  134. }
  135. }
  136. $allSubject=Yii::app()->params['subjectId'];
  137. unset($allSubject[6]);
  138. unset($allSubject[51]);
  139. unset($allSubject[18]);
  140. unset($allSubject[19]);
  141. $data["allSubject"] = $allSubject;
  142. $data["students"] = $get_list;
  143. $data['pages'] = $get_list['pager'];
  144. $data['page_total'] = $get_list['pager']->rowsCount;
  145. $data["cid"] = $get_id;
  146. $data['class_name'] = $class_info['class_name'];
  147. $data['class_bzr'] = $class_bzr;
  148. $data['subject_teacher'] = $subject;
  149. $data['subject_tid'] = $subjectTid;
  150. $data['class_bzr_id'] = $class_bzr_id;
  151. $this->render('view',$data);
  152. }
  153. //解绑功能
  154. public function actionUnbind(){
  155. $parent_id = safe_replace(Yii::app()->request->getParam('parent_id'));
  156. $student_id = safe_replace(Yii::app()->request->getParam('student_id'));
  157. $result['status']=0;
  158. if(!$parent_id){
  159. exit(json_encode($result));
  160. }
  161. if($this->schoolManager->UnbindZl($parent_id,$student_id,$this->schoolId)){
  162. $result['status']=1;
  163. }
  164. exit(json_encode($result));
  165. }
  166. //加载teacher
  167. public function actionLoadTeacher(){
  168. $keyword = safe_replace(Yii::app()->request->getParam('keyword'));
  169. $subject = safe_replace(Yii::app()->request->getParam('subject'));
  170. $class_id = safe_replace(Yii::app()->request->getParam('class_id'));
  171. $result['status']=0;
  172. if(!$keyword){
  173. exit(json_encode($result));
  174. }
  175. $data=$this->schoolManager->loadTeacher($keyword,$subject);
  176. if($data){
  177. foreach ($data as $key => $v){
  178. if(isset(Yii::app()->params['subjectId'][$v['subjects']])){
  179. $data[$key]['subject_name']=Yii::app()->params['subjectId'][$v['subjects']];
  180. }else{
  181. $data[$key]['subject_name']='';
  182. }
  183. }
  184. }
  185. $result['data']=$data;
  186. $result['status']=1;
  187. exit(json_encode($result));
  188. }
  189. //保存班级教师信息
  190. public function actionSaveClassTeacher(){
  191. $cid = safe_replace(Yii::app()->request->getParam('cid'));
  192. $main_teacher = safe_replace(Yii::app()->request->getParam('main_teacher'));
  193. $teacher_subject = Yii::app()->request->getParam('teacher_subject');
  194. $result['status']=0;
  195. if(!$cid){
  196. exit(json_encode($result));
  197. }
  198. $insertSql="insert into teacher_class_relation(`class_id`,`teacher_id`,`semester_id`,`hxb_ing`,`is_bzr`) values ";
  199. $insertValues=array();
  200. if($teacher_subject){
  201. $teacherIds=$teacher_subject;
  202. $teachers=$this->schoolManager->getTeachersByTeacherIds($teacherIds);
  203. if(!$teachers){
  204. exit(json_encode($result));
  205. }
  206. $checkSubject=array();
  207. foreach ($teachers as $v){
  208. if(isset($checkSubject[$v['subjects']])){
  209. $result['msg']='同一科目只能设置一位教师';
  210. exit(json_encode($result));
  211. }else{
  212. $checkSubject[$v['subjects']]=$v;
  213. }
  214. }
  215. unset($checkSubject);
  216. unset($teachers);
  217. foreach ($teacher_subject as $key=>$val){
  218. if($val){
  219. $insertValues[]="('".$cid."','".$val."','".$this->semesterId."',0,0)";
  220. }
  221. }
  222. }
  223. if($insertValues){
  224. $transcation = $this->sConn->beginTransaction();
  225. try {
  226. $deleteSql="delete from teacher_class_relation where class_id='".$cid."'";
  227. $this->sConn->createCommand($deleteSql)->execute();
  228. $insertSql.=implode(',',$insertValues);
  229. $this->sConn->createCommand($insertSql)->execute();
  230. //更新班主任
  231. if( $main_teacher){
  232. $this->sConn->createCommand("update class set teacher_id='".$main_teacher."' where class_id='".$cid."'")->execute();
  233. }
  234. $transcation->commit();
  235. $result['status']=1;
  236. }catch (Exception $e){
  237. $result['status']=0;
  238. $transcation->rollback();
  239. }
  240. }else{
  241. $result['msg']='必须保留一位任教老师';
  242. $result['status']=0;
  243. }
  244. exit(json_encode($result));
  245. }
  246. //下载excel
  247. public function actionDownloadExcel(){
  248. $rs = $this->schoolManager->getClasses('ALL',array('class_id desc'));
  249. $objPHPExcel = new PHPExcel();
  250. $objPHPExcel->getProperties()->setCreator("ctos")
  251. ->setLastModifiedBy("ctos")
  252. ->setTitle("班级信息")
  253. ->setSubject("班级信息")
  254. ->setDescription("班级信息")
  255. ->setKeywords("excel")
  256. ->setCategory("result file");
  257. $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(20);
  258. $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(30);
  259. $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(10);
  260. $letters = array('E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
  261. $allSubject=Yii::app()->params['subjectId'];
  262. unset($allSubject[3]);
  263. unset($allSubject[51]);
  264. unset($allSubject[18]);
  265. unset($allSubject[19]);
  266. // $commandStr="$objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', '班级')->setCellValue('B1', '学期')->setCellValue('C1', '年级') ->setCellValue('D1', '班主任')";
  267. // foreach ($allSubject as $key =>$val){
  268. // $column=$ExcelToSubject[$key].'1';
  269. // $commandStr.=" ->setCellValue('".$column."', '".$val."')";
  270. // }
  271. // $commandStr.=";";
  272. // debug($commandStr);
  273. // eval($commandStr);
  274. $objPHPExcel->setActiveSheetIndex(0)
  275. ->setCellValue('A1', '班级')
  276. ->setCellValue('B1', '学期')
  277. ->setCellValue('C1', '年级')
  278. ->setCellValue('D1', '班主任');
  279. $i=0;
  280. foreach ($allSubject as $key =>$val){
  281. $column=$letters[$i].'1';
  282. $objPHPExcel->getActiveSheet(0)->setCellValue($column,$val);
  283. $i++;
  284. }
  285. $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
  286. $criteria = new CDbCriteria;
  287. $criteria->limit = 1;
  288. $criteria->order = "create_time desc";
  289. $criteria->condition = " semester_id={$this->semesterId}";
  290. $semester = Semester::model()->find($criteria);
  291. $semName = $semester->semester_name;
  292. $gradeNameArr = array(1=>'高一',2=>'高二',3=>'高三');
  293. $i = 1;
  294. foreach($rs as $v)
  295. {
  296. $grade = isset(Yii::app()->params['grade_list'][$v['grade']]) ? Yii::app()->params['grade_list'][$v['grade']]['grade_name'] : '';
  297. $i = $i + 1;
  298. $objPHPExcel->getActiveSheet(0)->setCellValue('A' . $i, $v['class_name']);
  299. $objPHPExcel->getActiveSheet(0)->setCellValue('B' . $i, $semName);
  300. $objPHPExcel->getActiveSheet(0)->setCellValue('C' . $i, $grade);
  301. $objPHPExcel->getActiveSheet(0)->setCellValue('D' . $i, '');
  302. $subjectOrder=0;
  303. foreach ($allSubject as $key =>$val){
  304. $column=$letters[$subjectOrder].$i;
  305. $subjectOrder++;
  306. $objPHPExcel->getActiveSheet(0)->setCellValue($column, '');
  307. }
  308. //
  309. // $objPHPExcel->getActiveSheet(0)->setCellValue('E' . $i, '');
  310. // $objPHPExcel->getActiveSheet(0)->setCellValue('F' . $i, '');
  311. // $objPHPExcel->getActiveSheet(0)->setCellValue('G' . $i, '');
  312. // $objPHPExcel->getActiveSheet(0)->setCellValue('H' . $i, '');
  313. // $objPHPExcel->getActiveSheet(0)->setCellValue('I' . $i, '');
  314. // $objPHPExcel->getActiveSheet(0)->setCellValue('J' . $i, '');
  315. // $objPHPExcel->getActiveSheet(0)->setCellValue('K' . $i, '');
  316. // $objPHPExcel->getActiveSheet(0)->setCellValue('L' . $i, '');
  317. // $objPHPExcel->getActiveSheet(0)->setCellValue('M' . $i, '');
  318. // $objPHPExcel->getActiveSheet(0)->setCellValue('N' . $i, '');
  319. }
  320. $objPHPExcel->getActiveSheet()->setTitle('家校管理班级信息');
  321. $objPHPExcel->setActiveSheetIndex(0);
  322. ob_end_clean(); // Added by me
  323. header("Accept-Ranges:bytes");
  324. header('Content-Type:application/vnd.ms-excel');
  325. header("Content-type:application/vnd.ms-excel;charset=UTF-8");
  326. header('Content-Disposition:attachment;filename="家校管理班级信息.xls"');
  327. header('Cache-Control:max-age=0');
  328. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  329. $objWriter->save('php://output');
  330. exit;
  331. }
  332. //导入班主任信息
  333. public function actionImport(){
  334. ini_set ('memory_limit', '300M');
  335. if(!$_FILES){
  336. Yii::app()->jump->error('文件大小超过范围');
  337. }else {
  338. if (!isset($_FILES['file']) || !isset($_FILES['file']['size']) || $_FILES['file']['size'] > 5242880) {
  339. Yii::app()->jump->error('文件大小超过范围');
  340. }
  341. }
  342. $uploader = new Uploader("upload/tmpDir/UploadClassesStudentsList/{$this->schoolId}/");
  343. $uploader->allowTypes = array("xls","xlsx");
  344. $uploader->fieldsMappings = array("exname" => array(0 => $this->schoolId));
  345. $file = $uploader->act();
  346. $file = Arr::current(Arr::current($file));
  347. if (!$file || !isset($file["error"]))
  348. Yii::app()->jump->error('请上传的Excel!');
  349. if ($file["error"] != 0) {
  350. switch ($file["error"]) {
  351. case 2001:
  352. Yii::app()->jump->error('文件类型不符');
  353. break;
  354. case 2002:
  355. Yii::app()->jump->error('文件大小超出允许范围');
  356. break;
  357. default:
  358. Yii::app()->jump->error('上传失败');
  359. break;
  360. }
  361. }
  362. $inputFileName = $file["src"];
  363. // 导入PHPExcel类
  364. Yii::import('application.extensions.*');
  365. require_once('phpexcel/PHPExcel/IOFactory.php');
  366. try{
  367. $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
  368. $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
  369. //FIXME 2019-12-02
  370. @unlink($file["src"]);
  371. }catch (Exception $e){
  372. //FIXME 2019-12-02
  373. @unlink($file["src"]);
  374. Yii::app()->jump->error('Excel格式不正确:'.$e->getMessage());
  375. }
  376. if(!$sheetData)
  377. {
  378. Yii::app()->jump->error('请正确的Excel!');
  379. }
  380. unset($objPHPExcel);
  381. $letters = array('E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','AA','AB','AC','AD','AE','AF','AG','AH','AI','AJ','AK','AL','AM');
  382. $allSubject=Yii::app()->params['subjectId'];
  383. unset($allSubject[3]);
  384. unset($allSubject[51]);
  385. unset($allSubject[18]);
  386. unset($allSubject[19]);
  387. //模板校验
  388. $excelTemp = array('A'=>'班级','B'=>'学期','C'=>'年级','D'=>'班主任');
  389. $subjectExcel=array();
  390. $subjectOrder=0;
  391. foreach ($allSubject as $key =>$val){
  392. $subjectExcel[$letters[$subjectOrder]]=$val;
  393. $subjectOrder++;
  394. }
  395. $excelTemp=array_merge($excelTemp,$subjectExcel);
  396. if(count($excelTemp) != count($sheetData[1])){
  397. Yii::app()->jump->error('导入的excel格式与模版不一致,请重新上传');
  398. }
  399. foreach($excelTemp as $key=>$temp){
  400. if(!(isset($sheetData[1][$key]) && $sheetData[1][$key] == trim($temp))){
  401. Yii::app()->jump->error('导入的excel格式与模版不一致,请重新上传');
  402. }
  403. }
  404. unset($sheetData[1]);
  405. if(!$sheetData)
  406. {
  407. Yii::app()->jump->error('请输入数据');
  408. }
  409. $updateSql = '';
  410. $cls = array();
  411. foreach($sheetData as $sheet){
  412. $cls[] = $sheet['A'];
  413. }
  414. //班级信息
  415. $className = array_unique($cls);
  416. $classNameIdRel = ClassModel::model()->getClassByName($className);
  417. $classArr = array_keys($classNameIdRel);
  418. $teacherSheet = array_keys($subjectExcel);
  419. $nameArr = array();
  420. foreach($sheetData as $sheet){
  421. foreach($teacherSheet as $ts){
  422. if(isset($sheet[$ts]) && $sheet[$ts]) $nameArr[] = $this->myTrim($sheet[$ts]);
  423. }
  424. }
  425. //查询是否存在重名老师
  426. $teacherInfo = Teacher::model()->getNameCount(array_unique($nameArr));
  427. $teacherSub = Teacher::model()->getTeacherSub();
  428. if(empty($teacherInfo)){
  429. Yii::app()->jump->error('教师信息为空或填写错误');
  430. }
  431. $teacherArr = $teacherInfo['info'];
  432. $nameIdRel = array_flip($teacherArr);
  433. $same = $teacherInfo['same'];
  434. $phoneInfo = BusinessTeacher::model()->getTeacherInfo($this->schoolId,true);
  435. $insertValues = $updateClassIds = array();
  436. $delSql = '';
  437. foreach (Yii::app()->params['grade_config'] as $param){
  438. $gradeArr[]=$param['grade_name'];
  439. }
  440. $semName = Semester::model()->getSemesterName($this->semesterId);
  441. foreach ($sheetData as $val){
  442. $classValues = array();
  443. $className = trim($val['A']);
  444. if(empty($className)){
  445. Yii::app()->jump->error('班级名称不能为空');
  446. }
  447. if(!in_array($className,$classArr)){
  448. Yii::app()->jump->error($className.'班级不存在');
  449. }
  450. $classId = $classNameIdRel[$className];
  451. $sem = trim($val['B']);
  452. if(empty($sem)){
  453. Yii::app()->jump->error('学期不能为空');
  454. }elseif($semName != $sem){
  455. Yii::app()->jump->error('当前学期信息有误');
  456. }
  457. $grade = trim($val['C']);
  458. if(empty($grade)){
  459. Yii::app()->jump->error('年级不能为空');
  460. }elseif(!in_array($grade,$gradeArr)){
  461. Yii::app()->jump->error($grade.'年级不存在');
  462. }
  463. $val['D'] = $this->myTrim($val['D']);
  464. $origin = $name = trim($val['D']);
  465. preg_match('/\d+/',$name,$match);
  466. $name = trim(preg_replace('/\d+/','',$name));
  467. if($name){
  468. if(!in_array($name,$teacherArr)){
  469. Yii::app()->jump->error("您上传的教师姓名有误,请重新上传</br>{$className}-班主任-$origin");
  470. }
  471. if(in_array($name,$same)){
  472. if(!empty($match)){
  473. $phonNum = $match[0];
  474. if(isset($phoneInfo[$phonNum])) $chargeTeacherId = $phoneInfo[$phonNum];
  475. else Yii::app()->jump->error($phonNum.'后四位手机号匹配不到老师');
  476. }else{
  477. Yii::app()->jump->error('有多个'.$name.'老师,请在姓名后面添加手机号后四位');
  478. }
  479. }else{
  480. $chargeTeacherId = $nameIdRel[$name];
  481. }
  482. $updateSql .= "UPDATE class SET teacher_id='".$chargeTeacherId."' where class_id='".$classId."';";
  483. }
  484. foreach ($subjectExcel as $key => $item){
  485. $classValues[] = $this->nameHandle($val[$key],$teacherArr,$same,$phoneInfo,$nameIdRel,$classId,$teacherSub,$item,$delSql,$className);
  486. }
  487. // $classValues[] = $this->nameHandle($val['E'],$teacherArr,$same,$phoneInfo,$nameIdRel,$classId,$teacherSub,$excelTemp['E'],$delSql,$className);
  488. // $classValues[] = $this->nameHandle($val['F'],$teacherArr,$same,$phoneInfo,$nameIdRel,$classId,$teacherSub,$excelTemp['F'],$delSql,$className);
  489. // $classValues[] = $this->nameHandle($val['G'],$teacherArr,$same,$phoneInfo,$nameIdRel,$classId,$teacherSub,$excelTemp['G'],$delSql,$className);
  490. // $classValues[] = $this->nameHandle($val['H'],$teacherArr,$same,$phoneInfo,$nameIdRel,$classId,$teacherSub,$excelTemp['H'],$delSql,$className);
  491. // $classValues[] = $this->nameHandle($val['I'],$teacherArr,$same,$phoneInfo,$nameIdRel,$classId,$teacherSub,$excelTemp['I'],$delSql,$className);
  492. // $classValues[] = $this->nameHandle($val['J'],$teacherArr,$same,$phoneInfo,$nameIdRel,$classId,$teacherSub,$excelTemp['J'],$delSql,$className);
  493. // $classValues[] = $this->nameHandle($val['K'],$teacherArr,$same,$phoneInfo,$nameIdRel,$classId,$teacherSub,$excelTemp['K'],$delSql,$className);
  494. // $classValues[] = $this->nameHandle($val['L'],$teacherArr,$same,$phoneInfo,$nameIdRel,$classId,$teacherSub,$excelTemp['L'],$delSql,$className);
  495. // $classValues[] = $this->nameHandle($val['M'],$teacherArr,$same,$phoneInfo,$nameIdRel,$classId,$teacherSub,$excelTemp['M'],$delSql,$className);
  496. // $classValues[] = $this->nameHandle($val['N'],$teacherArr,$same,$phoneInfo,$nameIdRel,$classId,$teacherSub,$excelTemp['N'],$delSql,$className);
  497. $classValues = array_filter($classValues);
  498. if(!empty($classValues)){
  499. $insertValues = array_merge($insertValues,$classValues);
  500. $updateClassIds[] = $classId;
  501. }
  502. }
  503. if(($insertValues && $updateClassIds) || $updateSql){
  504. $transcation = $this->sConn->beginTransaction();
  505. $insertSql="insert into teacher_class_relation(`class_id`,`teacher_id`,`semester_id`,`hxb_ing`,`is_bzr`) values ";
  506. try {
  507. if($delSql){
  508. $this->sConn->createCommand($delSql)->execute();
  509. }
  510. if($insertValues){
  511. $insertSql.=implode(',',$insertValues);
  512. $this->sConn->createCommand($insertSql)->execute();
  513. }
  514. //更新班主任
  515. if( $updateSql){
  516. $this->sConn->createCommand($updateSql)->execute();
  517. }
  518. $transcation->commit();
  519. Yii::app()->jump->error('家校批量上传成功!',$this->createUrl('/parent/index'));
  520. }catch (Exception $e){
  521. Yii::app()->jump->error('家校批量上传失败!');
  522. }
  523. }else{
  524. Yii::app()->jump->error('请输入数据!');
  525. }
  526. }
  527. public function actionExcelInfo(){
  528. $this->render('excelinfo',array());
  529. }
  530. protected function nameHandle($name,$teacherArr,$same,$phoneInfo,$nameIdRel,$classId,$subArr,$sub,&$del,$className){
  531. $subjectArr=Yii::app()->params['subjectId'];
  532. unset($subjectArr[3]);
  533. unset($subjectArr[51]);
  534. unset($subjectArr[18]);
  535. unset($subjectArr[19]);
  536. $name = $this->myTrim($name);
  537. $origin = $name = trim($name);
  538. if(empty($name) && $name !== '0') return '';
  539. preg_match('/\d+/',$name,$match);
  540. $name = trim(preg_replace('/\d+/','',$name));
  541. if(!in_array($name,$teacherArr)){
  542. Yii::app()->jump->error("您上传的教师姓名有误,请重新上传</br>{$className}-{$sub}-$origin");
  543. }
  544. if(in_array($name,$same)){
  545. if(!empty($match)){
  546. $phonNum = $match[0];
  547. if(isset($phoneInfo[$phonNum])) $teacherId = $phoneInfo[$phonNum];
  548. else Yii::app()->jump->error($phonNum.'后四位手机号匹配不到老师');
  549. }else{
  550. Yii::app()->jump->error('有多个'.$name.'老师,请在姓名后面添加手机号后四位');
  551. }
  552. }else{
  553. $teacherId = $nameIdRel[$name];
  554. }
  555. if(isset($subjectArr[$subArr[$teacherId]]) && $subjectArr[$subArr[$teacherId]] != $sub){
  556. Yii::app()->jump->error("您上传的教师与任教学科不符,请重新上传</br>$name:上传{$sub},任课".$subjectArr[$subArr[$teacherId]]);
  557. }
  558. $sql = "SELECT tcr.* FROM teacher_class_relation tcr INNER JOIN teacher t ON tcr.teacher_id=t.teacher_id WHERE subjects=".$subArr[$teacherId]." AND class_id={$classId}";
  559. $relation = TeacherToClass::model()->getTeacher($sql);
  560. if(!empty($relation)){
  561. $del .= "DELETE FROM teacher_class_relation WHERE teacher_id={$relation['teacher_id']} AND class_id={$classId} AND semester_id=".$this->semesterId.';';
  562. }
  563. return "('".$classId."','".$teacherId."','".$this->semesterId."',0,0)";
  564. }
  565. protected function myTrim($str)
  566. {
  567. $search = array(" "," ","\n","\r","\t");
  568. $replace = array("","","","","");
  569. return str_replace($search, $replace, $str);
  570. }
  571. //当天绑定日志
  572. public function actionBindCodeLog(){
  573. $cid =safe_replace(Yii::app()->request->getParam('cid'));
  574. $time=date('Y-m-d 00:00:00',time());
  575. $criteria = new CDbCriteria();
  576. $criteria->addCondition('create_time>:time');
  577. $criteria->addCondition('clazz_id=:cid');
  578. $criteria->params[':time'] = $time;
  579. $criteria->params[':cid'] = $cid;
  580. $criteria->order = 'create_time desc';
  581. $dataLog=SStudentBindCodeLog::model()->findAll($criteria);
  582. $data=array();
  583. if($dataLog){
  584. foreach ($dataLog as $item){
  585. $student=SStudentInfo::model()->find("student_id=:sid",array(':sid'=>$item['student_id']));
  586. $mobile=substr_replace($item['mobile'],'****',3,4);
  587. $data[]=array(
  588. 'time'=>date('H:i:s',strtotime($item['create_time'])),
  589. 'student_name'=>$student['realname'],
  590. 'mobile'=>$mobile,
  591. 'code'=>$item['bind_code']
  592. );
  593. }
  594. }
  595. $result['status']=1;
  596. $result['data']=$data;
  597. exit(jsonEncode($result));
  598. }
  599. }