CheckstudentController.php 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036
  1. <?php
  2. /**
  3. * 学生管理控制器类
  4. * @author li
  5. * @date 2018-11-19 9:50:00
  6. * @company 上海风车教育有限公司.
  7. */
  8. class CheckstudentController extends Controller
  9. {
  10. // 开始
  11. public function actionIndex()
  12. {
  13. $data['is_last']=0;
  14. $data['count']=0;
  15. $last_step=StudentCheck::model()->find('last_step=1');
  16. if($last_step){
  17. $data['is_last']=1;
  18. $data['count']=$this->countRepeatData();
  19. }
  20. $this->render('check', $data);
  21. }
  22. //读取学生数据
  23. public function actionAjaxLoadData(){
  24. $result['status']=0;
  25. //读取已关联数据
  26. $sql_relation="select relation_student_id from student_relation ";
  27. $all_relation_data = $this->sConn->createCommand($sql_relation)->queryAll();
  28. $reStudentIds=array();
  29. if($all_relation_data){
  30. foreach ($all_relation_data as $item){
  31. @$ids=explode(',',$item['relation_student_id']);
  32. if($ids){
  33. foreach ($ids as $id){
  34. if($id){
  35. $reStudentIds[]=$id;
  36. }
  37. }
  38. }
  39. }
  40. $reStudentIds=array_unique($reStudentIds);
  41. }
  42. $del_sql="truncate `student_check`;";
  43. $this->sConn->createCommand($del_sql)->execute();
  44. if($reStudentIds){
  45. $sql="insert into `student_check`(SELECT `student_id`,`realname`,`school_id`,`class_id`,`id_number`,'',0,`is_outer`,0,0 from `student_info` where (id_number is null or id_number='') and student_id not in(".implode(',',$reStudentIds)."));";
  46. }else{
  47. $sql="insert into `student_check`(SELECT `student_id`,`realname`,`school_id`,`class_id`,`id_number`,'',0,`is_outer`,0,0 from `student_info` where (id_number is null or id_number='') );";
  48. }
  49. $rs=$this->sConn->createCommand($sql)->execute();
  50. if($rs){
  51. $result['status']=1;
  52. $result['data']=$rs;
  53. }
  54. exit(json_encode($result));
  55. }
  56. //判断账号异常
  57. public function actionAjaxCheckData(){
  58. ini_set('memory_limit','512M');
  59. set_time_limit(0);
  60. $result['status']=0;
  61. $result['data']=0;
  62. $student_all_data = $this->sConn->createCommand("SELECT student_id,realname FROM `student_check` `t` ")->queryAll();
  63. if($student_all_data){
  64. //去除非中文字符
  65. $updateArr=array();
  66. $preg="/[^\x{4E00}-\x{9FFF}^·]+/u";
  67. $count=0;
  68. foreach($student_all_data as $val){
  69. if(preg_match($preg,$val['realname'])){
  70. $ModifyName = preg_replace($preg, "", $val['realname']);
  71. if($ModifyName){
  72. $updateArr[$val['student_id']]=$ModifyName;
  73. $count++;
  74. }
  75. }else{
  76. $updateArr[$val['student_id']]=$val['realname'];
  77. }
  78. }
  79. //组织更新语句
  80. if($updateArr){
  81. $arrNumber=ceil(count($updateArr)/500);
  82. $Arr=array_chunk($updateArr,$arrNumber,true);
  83. $transcation = $this->sConn->beginTransaction();
  84. try {
  85. foreach ($Arr as $item){
  86. $sql='update student_check set `modify_name`= case student_id ';
  87. foreach ($item as $key=> $val){
  88. $sql.=" WHEN ".$key." THEN '".$val."' ";
  89. }
  90. $sql.=" End ";
  91. $sql.=" where modify_name='' or modify_name is null";
  92. $this->sConn->createCommand($sql)->execute();
  93. }
  94. $transcation->commit();
  95. $result['status']=1;
  96. }catch (Exception $e){
  97. $transcation->rollback();
  98. }
  99. }
  100. $result['count']=$count;
  101. }
  102. exit(json_encode($result));
  103. }
  104. //自动关联
  105. public function actionAjaxRelation(){
  106. $result['status']=0;
  107. //处理正常账号
  108. //查询同一学期名字不重复的学生且其它学期也不重复,这类学生账号是正常账号,自动关联
  109. /*
  110. $sql="SELECT count(*) as count,sc.class_id,sc.student_id,sc.modify_name,c.class_name,s.semester_id,s.semester_name,s.school_year,s.end_time FROM `student_check` sc ";
  111. $sql.="LEFT JOIN class c on sc.class_id=c.class_id ";
  112. $sql.="LEFT JOIN semester s on s.semester_id=c.semester_id ";
  113. $sql.="GROUP BY sc.modify_name,s.semester_id ";
  114. $sql.="having modify_name <> '' and class_name <> '' ";
  115. $sql.="order by s.end_time desc ;";
  116. */
  117. $sql="select count(*) as count,modify_name,semester_id,student_id from (
  118. SELECT sc.class_id,sc.student_id,sc.modify_name,sc.is_relation,c.class_name,s.semester_id,s.semester_name,s.school_year,s.end_time,sc.id_number FROM `student_check` sc
  119. LEFT JOIN class c on sc.class_id=c.class_id
  120. LEFT JOIN semester s on s.semester_id=c.semester_id
  121. LEFT JOIN student_class_relation scr on scr.student_id=sc.student_id
  122. where modify_name <> '' and (class_name <>'' or class_name is not null ) and sc.is_relation=0 and s.semester_id <>'' and scr.status=0
  123. ) t GROUP BY modify_name,semester_id ";
  124. $student_all_data = $this->sConn->createCommand($sql)->queryAll();
  125. $nameArr=array();
  126. $needRelation=array();
  127. if($student_all_data){
  128. foreach ($student_all_data as $item){
  129. $nameArr[$item['modify_name']][]=$item;
  130. }
  131. foreach ($nameArr as $val){
  132. $normal=true;
  133. foreach ($val as $v){
  134. if($v['count']>1){
  135. $normal=false; //重复数量大于1,异常数据
  136. break;
  137. }
  138. }
  139. if($normal && count($val)>1){ //同学期不重复,且多个学期存在,需要关联
  140. $needRelation[]=$val;
  141. }
  142. }
  143. $count=0;
  144. $needUpdateStudentId=array();
  145. if($needRelation){
  146. $insertSql="Replace into student_relation(`master_student_id`,`relation_student_id`) values ";
  147. $values=array();
  148. foreach ($needRelation as $val){
  149. $count+=count($val);
  150. $master_student_id=0;
  151. $relation_student_id=array();
  152. foreach ($val as $v){
  153. if(!$master_student_id) $master_student_id=$v['student_id'];
  154. $relation_student_id[]=$v['student_id'];
  155. $needUpdateStudentId[]=$v['student_id'];
  156. }
  157. if($master_student_id && $relation_student_id){
  158. $values[]="('".$master_student_id."','".implode(',',$relation_student_id)."')";
  159. }
  160. }
  161. if($values){
  162. $transcation = $this->sConn->beginTransaction();
  163. try {
  164. $insertSql.=implode(',',$values);
  165. $this->sConn->createCommand($insertSql)->execute();
  166. $updateSql="update student_check set is_relation=1 where student_id in(".implode(',',$needUpdateStudentId).")";
  167. $this->sConn->createCommand($updateSql)->execute();
  168. $transcation->commit();
  169. $result['status']=1;
  170. }catch (Exception $e){
  171. $transcation->rollback();
  172. }
  173. }
  174. }else{
  175. $result['status']=1;
  176. }
  177. $result['count']=$count;
  178. }
  179. exit(json_encode($result));
  180. }
  181. //重名数据
  182. public function actionAjaxRepeat(){
  183. $result['status']=0;
  184. //查询同一学期名字有重复的学生,这类学生账号是异常账号,需要处理
  185. $sql="select count(*) as count,modify_name,semester_id,student_id from (
  186. SELECT sc.class_id,sc.student_id,sc.modify_name,sc.is_relation,c.class_name,s.semester_id,s.semester_name,s.school_year,s.end_time,sc.id_number,sc.is_ignore FROM `student_check` sc
  187. LEFT JOIN class c on sc.class_id=c.class_id
  188. LEFT JOIN semester s on s.semester_id=c.semester_id
  189. LEFT JOIN student_class_relation scr on scr.student_id=sc.student_id
  190. where modify_name <> '' and (class_name <>'' or class_name is not null ) and sc.is_relation=0 and s.semester_id <>'' and scr.status=0 and sc.is_ignore=0
  191. ) t GROUP BY modify_name,semester_id having count>1 ";
  192. $student_all_data = $this->sConn->createCommand($sql)->queryAll();
  193. if(!$student_all_data){
  194. $result['status']=1;
  195. $result['count']=0;
  196. }else{
  197. $nameArr=array();
  198. foreach ($student_all_data as $val){
  199. $nameArr[$val['modify_name']][]=$val;
  200. }
  201. $result['status']=1;
  202. $result['count']=count($nameArr);
  203. }
  204. //已检测到最后一步,做标记
  205. $sql_u=StudentCheck::model()->find();
  206. $sql_u->last_step=1;
  207. $sql_u->save();
  208. exit(json_encode($result));
  209. }
  210. private function countRepeatData(){
  211. //查询同一学期名字有重复的学生,这类学生账号是异常账号,需要处理
  212. $sql="select count(*) as count,modify_name,semester_id from (";
  213. $sql.="SELECT sc.class_id,sc.student_id,sc.modify_name,sc.is_relation,c.class_name,s.semester_id,s.semester_name,s.school_year,s.end_time,sc.id_number,sc.is_ignore FROM `student_check` sc ";
  214. $sql.="LEFT JOIN class c on sc.class_id=c.class_id ";
  215. $sql.="LEFT JOIN semester s on s.semester_id=c.semester_id ";
  216. $sql.="LEFT JOIN student_class_relation scr on scr.student_id=sc.student_id ";
  217. $sql.=" where modify_name <> '' and (class_name <>'' or class_name is not null ) and sc.is_relation=0 and s.semester_id <>'' and scr.status=0 and sc.is_ignore=0 ";
  218. $sql.=" ) t ";
  219. $sql.="GROUP BY modify_name,semester_id ";
  220. $sql.="having count>1 ";
  221. $student_all_data = $this->sConn->createCommand($sql)->queryAll();
  222. if(!$student_all_data){
  223. return 0;
  224. }else{
  225. $nameArr=array();
  226. foreach ($student_all_data as $val){
  227. $nameArr[$val['modify_name']][]=$val;
  228. }
  229. return count($nameArr);
  230. }
  231. }
  232. //完成保存处理结果
  233. public function actionAjaxUpdateRealName(){
  234. $result['status']=0;
  235. $sql=" update student_info si,student_check sc set si.realname=sc.modify_name,si.id_number=sc.id_number where si.student_id=sc.student_id and modify_name is not null ";
  236. $this->sConn->createCommand($sql)->execute();
  237. $del_sql="truncate `student_check`;";
  238. $this->sConn->createCommand($del_sql)->execute();
  239. $result['status']=1;
  240. if(Yii::app()->params['handle_log_on_off'])
  241. {
  242. writeFileLog(jsonEncode(array(
  243. "exam_group_id" => 0,
  244. "operate_project" => 'zsyas2',
  245. "school_id" => $this->schoolId,
  246. "title" => '检测学生',
  247. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  248. "operate_method" => $this->action,
  249. "operate_url" => $this->getRoute(),
  250. "operate_sql" =>'',
  251. "operate_param" =>'',
  252. "date"=>date('Y-m-d H:i:j')
  253. )));
  254. }
  255. exit(json_encode($result));
  256. }
  257. //处理重名
  258. public function actionHandleData(){
  259. $page=Req::post('page');
  260. $name_like=Req::post('name');
  261. if(!$page) $page=1;
  262. //查询同一学期名字有重复的学生,这类学生账号是异常账号,需要处理
  263. $sql="select count(*) as count,modify_name from (";
  264. $sql.="SELECT sc.class_id,sc.student_id,sc.modify_name,sc.is_relation,c.class_name,s.semester_id,s.semester_name,s.school_year,s.end_time,sc.id_number,sc.is_ignore FROM `student_check` sc ";
  265. $sql.="LEFT JOIN class c on sc.class_id=c.class_id ";
  266. $sql.="LEFT JOIN semester s on s.semester_id=c.semester_id ";
  267. $sql.="LEFT JOIN student_class_relation scr on scr.student_id=sc.student_id ";
  268. $sql.=" where modify_name <> '' and (class_name <>'' or class_name is not null ) and sc.is_relation=0 and s.semester_id <>'' and scr.status=0 and sc.is_ignore=0 ";
  269. if($name_like){
  270. $sql.=" and modify_name like '%".$name_like."%' ";
  271. }
  272. $sql.=" ) t ";
  273. $sql.="GROUP BY modify_name ";
  274. $sql.="having count>1 ";
  275. $sql.="order by count desc ;";
  276. $nameArr=array();
  277. $student_all_data = $this->sConn->createCommand($sql)->queryAll();
  278. if($student_all_data){
  279. foreach ($student_all_data as $val){
  280. $nameArr[$val['modify_name']]=$val;
  281. }
  282. }
  283. $nameArr=array_values($nameArr);
  284. $pageSize=10;
  285. $offset=($page-1)*$pageSize;
  286. $total=count($nameArr);
  287. $data['total_page']=ceil($total/$pageSize);
  288. $data['name_group']=array_slice($nameArr,$offset,$pageSize);
  289. $data['page']=$page;
  290. //debug($nameArr);
  291. if(Yii::app()->request->isAjaxRequest){
  292. $result['status']=1;
  293. $result['data']=$data['name_group'];
  294. $result['total_page']=$data['total_page'];
  295. exit(json_encode($result));
  296. }else{
  297. $this->render('handle', $data);
  298. }
  299. }
  300. //查询要处理的一组学生
  301. public function actionShowRepeatStudent(){
  302. $name=Req::post('name');
  303. $sql="SELECT sc.realname,sc.class_id,sc.student_id,sc.modify_name,sc.is_relation,sc.is_outer,sc.id_number,c.class_name,s.semester_id,s.semester_name,s.school_year,s.end_time,sc.is_ignore FROM `student_check` sc ";
  304. $sql.="LEFT JOIN class c on sc.class_id=c.class_id ";
  305. $sql.="LEFT JOIN semester s on s.semester_id=c.semester_id ";
  306. $sql.=" where modify_name='".$name."' and (class_name <>'' or class_name is not null ) and sc.is_relation=0 and s.semester_id <>'' and sc.is_ignore=0 ";
  307. $sql.="order by end_time desc ;";
  308. $nameArr=array();
  309. $_allStudent = $this->sConn->createCommand($sql)->queryAll();
  310. $studentData=array();
  311. $businessData=array();
  312. $semester=array();
  313. $studentId=array();
  314. $html='';
  315. if($_allStudent){
  316. foreach ($_allStudent as $val){
  317. $val['serial_number']=0;
  318. $val['userno']=0;
  319. //班级信息
  320. $sql_class_relation="select * from student_class_relation where student_id='".$val['student_id']."' and status=0 ";
  321. $student_class_realtion=$this->sConn->createCommand($sql_class_relation)->queryRow();
  322. if($student_class_realtion){
  323. $val['serial_number']=$student_class_realtion['serial_number'];
  324. $val['userno']=$student_class_realtion['userno'];
  325. }else{
  326. continue;
  327. }
  328. //查询副号
  329. $sql_fuhao="select * from student_relation where find_in_set('".$val['student_id']."',relation_student_id)";
  330. $student_fuhao=$this->sConn->createCommand($sql_fuhao)->queryRow();
  331. $val['fuhao']=0;
  332. if($student_fuhao){
  333. if($val['student_id']!=$student_fuhao['master_student_id']){
  334. continue;
  335. }else{
  336. $fuhao_arr=explode(',',$student_fuhao['relation_student_id']);
  337. $val['fuhao']=count($fuhao_arr)-1;
  338. }
  339. }
  340. $studentData[$val['semester_id']][]=$val;
  341. $semester[$val['semester_id']]=$val['semester_name'];
  342. $studentId[]=$val['student_id'];
  343. }
  344. $i=1;
  345. $currSemester = $this->schoolManager->getCurrSemester();
  346. $smid=$currSemester['semester_id'];
  347. foreach ($semester as $key=> $val){
  348. $semesterStatus='非当前学期';
  349. if($smid==$key){
  350. $semesterStatus='当前学期';
  351. }
  352. $html.='<div class="handel-term-list">';
  353. if($smid==$key){
  354. $html.='<div class="term-name fw">'.$val.'</div>';
  355. }else{
  356. $html.='<div class="term-name fw">'.$val.'<span class="green-font pointer" semester="'.$key.'">忽略</span></div>';
  357. }
  358. $html.='<div class="relative flex">';
  359. $html.='<img src="/images/prev-arrow.png" alt="" class="prev-arrow arrow-img pointer">';
  360. $html.='<div class="term-card-layout flex-one" >';
  361. $html.='<ul class="term-card-detail">';
  362. if(isset($studentData[$key])){
  363. // debug($studentData[$key]);
  364. foreach ($studentData[$key] as $item){
  365. $isZj='是';
  366. if($item['is_outer']==1){
  367. $isZj='否';
  368. }
  369. //查询business
  370. $b_student_data= $this->conn->createCommand("select username,student_card,school_student_card,zhixue_student_card from `student` where student_id='".$item['student_id']."'")->queryRow();
  371. if($b_student_data){
  372. $businessData[$item['student_id']]=$b_student_data;
  373. }
  374. $html.='<li class="term-card-list" id="'.$item['student_id'].'" draggable="true" >';
  375. $html.='<div class="padding-layout">';
  376. $html.='<div class="card-lis-data flex">';
  377. $html.='<span class="card-list-menu gray-font">姓名</span>';
  378. $html.='<span class="card-list-msg flex-one">'.$item['modify_name'].'(原'.$item['realname'].')</span>';
  379. $html.='</div>';
  380. $html.='<div class="card-lis-data flex">';
  381. $html.='<span class="card-list-menu gray-font">班级</span>';
  382. $html.='<span class="card-list-msg flex-one">'.$item['class_name'].'</span>';
  383. $html.='</div>';
  384. $html.='<div class="hide-list">';
  385. $html.='<div class="card-lis-data flex">';
  386. $html.='<span class="card-list-menu gray-font">学期</span>';
  387. $html.='<span class="card-list-msg flex-one">'.$val.'</span>';
  388. $html.='</div>';
  389. $html.='<div class="card-lis-data flex">';
  390. $html.='<span class="card-list-menu gray-font">学期状态</span>';
  391. $html.='<span class="card-list-msg flex-one">'.$semesterStatus.'</span>';
  392. $html.='</div>';
  393. $html.='<div class="card-lis-data flex">';
  394. $html.='<span class="card-list-menu gray-font">班级序号</span>';
  395. $html.='<span class="card-list-msg flex-one">'.$item['serial_number'].'</span>';
  396. $html.='</div>';
  397. $html.='<div class="card-lis-data flex">';
  398. $html.='<span class="card-list-menu gray-font">学号</span>';
  399. $html.='<span class="card-list-msg flex-one">'.$item['userno'].'</span>';
  400. $html.='</div>';
  401. $html.='<div class="card-lis-data flex">';
  402. $html.='<span class="card-list-menu gray-font">登录账号</span>';
  403. if(isset($businessData[$item['student_id']])){
  404. $html.='<span class="card-list-msg flex-one">'.$businessData[$item['student_id']]['username'].'</span>';
  405. }else{
  406. $html.='<span class="card-list-msg flex-one"></span>';
  407. }
  408. $html.='</div>';
  409. $html.='<div class="card-lis-data flex">';
  410. $html.='<span class="card-list-menu gray-font">系统准考证号</span>';
  411. if(isset($businessData[$item['student_id']])){
  412. $html.='<span class="card-list-msg flex-one">'.$businessData[$item['student_id']]['student_card'].'</span>';
  413. }else{
  414. $html.='<span class="card-list-msg flex-one"></span>';
  415. }
  416. $html.='</div>';
  417. $html.='<div class="card-lis-data flex">';
  418. $html.='<span class="card-list-menu gray-font">学校准考证号</span>';
  419. if(isset($businessData[$item['student_id']])){
  420. $html.='<span class="card-list-msg flex-one">'.$businessData[$item['student_id']]['school_student_card'].'</span>';
  421. }else{
  422. $html.='<span class="card-list-msg flex-one"></span>';
  423. }
  424. $html.='</div>';
  425. $html.='<div class="card-lis-data flex">';
  426. $html.='<span class="card-list-menu gray-font">智学网考号</span>';
  427. if(isset($businessData[$item['student_id']])){
  428. $html.='<span class="card-list-msg flex-one">'.$businessData[$item['student_id']]['zhixue_student_card'].'</span>';
  429. }else{
  430. $html.='<span class="card-list-msg flex-one"></span>';
  431. }
  432. $html.='</div>';
  433. $html.='<div class="card-lis-data flex">';
  434. $html.='<span class="card-list-menu gray-font">身份证号</span>';
  435. $html.='<span class="card-list-msg flex-one"><img src="/images/edit.png" alt="" draggable="false" class="edit-icon"><input data="'.$item['student_id'].'" type="text" value="'.$item['id_number'].'" class="edit-self-no"></span>';
  436. $html.='</div>';
  437. $html.='<div class="card-lis-data flex">';
  438. $html.='<span class="card-list-menu gray-font">是否为在籍生</span>';
  439. $html.='<span class="card-list-msg flex-one">'.$isZj.'</span>';
  440. $html.='</div>';
  441. $html.='<div class="card-lis-data flex">';
  442. $html.='<span class="card-list-menu gray-font">历史考试成绩</span>';
  443. $html.='<span rel="'.$item['student_id'].'" class="card-list-msg flex-one browse-history green-font">查看</span>';
  444. $html.='</div>';
  445. $html.='<div class="card-lis-data flex">';
  446. $html.='<span class="card-list-menu gray-font">副号</span>';
  447. $html.='<span rel="'.$item['student_id'].'" class="card-list-msg flex-one green-font pointer fuhao-lock">'.$item['fuhao'].'</span>';
  448. $html.='</div>';
  449. $html.='</div>';
  450. $html.='<span class="toggle-opt-btn green-font pointer">展开</span>';
  451. $html.='</div>';
  452. $html.='</li>';
  453. $i++;
  454. }
  455. }
  456. $html.='</ul>';
  457. $html.='</div>';
  458. $html.='<img src="/images/next-arrow.png" alt="" class="next-arrow arrow-img pointer">';
  459. $html.='</div>';
  460. $html.='</div>';
  461. }
  462. }
  463. $result['data']=$html;
  464. $result['status']=1;
  465. exit(json_encode($result));
  466. }
  467. //保存身份证
  468. public function actionSaveIdNumber(){
  469. $student_id=Req::post('student_id');
  470. $id_number=Req::post('id_number');
  471. $result['status']=0;
  472. if(!$student_id || !$id_number){
  473. exit(json_encode($result));
  474. }
  475. //判断系统中是否存在
  476. if($this->schoolManager->checkStudentIdNumber($id_number)){
  477. $result['status']=0;
  478. $result['msg']='系统中已存在相同身份证,请检查后重新确认';
  479. exit(json_encode($result));
  480. }
  481. //判断表格中是否存在
  482. $sql="select student_id from student_check where id_number='".$id_number."' ";
  483. $data=$this->sConn->createCommand($sql)->queryRow();
  484. if($data){
  485. $result['msg']='已存在相同身份证,请检查后重新确认';
  486. exit(json_encode($result));
  487. }
  488. $info = StudentCheck::model()->find('student_id=:stid',array(':stid'=>$student_id));
  489. if(!$info){
  490. $result['msg']='学生不存在';
  491. exit(json_encode($result));
  492. }
  493. $info->id_number=$id_number;
  494. if($info->save()){
  495. $result['status']=1;
  496. exit(json_encode($result));
  497. }
  498. }
  499. //查询副号
  500. public function actionGetSlaves(){
  501. $student_id=Req::post('student_id');
  502. $result['status']=0;
  503. if(!$student_id ){
  504. exit(json_encode($result));
  505. }
  506. $sql="select * from student_relation where find_in_set('".$student_id."',relation_student_id) limit 1 ";
  507. $_allStudent = $this->sConn->createCommand($sql)->queryRow();
  508. if($_allStudent && isset($_allStudent['relation_student_id'])){
  509. $studentIds=explode(',',$_allStudent['relation_student_id']);
  510. unset($studentIds[array_search($student_id,$studentIds)]);
  511. //查询
  512. $sql="SELECT sc.realname,sc.class_id,sc.student_id,sc.modify_name,sc.is_relation,sc.is_outer,sc.id_number,c.class_name,s.semester_id,s.semester_name,s.school_year,s.end_time,scr.serial_number,scr.userno,scr.status FROM `student_check` sc ";
  513. $sql.="LEFT JOIN class c on sc.class_id=c.class_id ";
  514. $sql.="LEFT JOIN semester s on s.semester_id=c.semester_id ";
  515. $sql.="LEFT JOIN student_class_relation scr on scr.student_id=sc.student_id ";
  516. $sql.=" where sc.student_id in(".implode(',',$studentIds).") and scr.status=0 ";
  517. $sql.="order by end_time desc ;";
  518. $nameArr=array();
  519. $_allStudent = $this->sConn->createCommand($sql)->queryAll();
  520. $studentData=array();
  521. $businessData=array();
  522. $semester=array();
  523. $studentId=array();
  524. if($_allStudent){
  525. foreach ($_allStudent as $val){
  526. $studentId[]=$val['student_id'];
  527. //查询副号
  528. }
  529. //查询business
  530. $criteria = new CDbCriteria();
  531. $b_student = array();
  532. $criteria->addInCondition('student_id',$studentId);
  533. $b_student_data = BusinessStudent::model()->findAll($criteria);
  534. if($b_student_data){
  535. foreach($b_student_data as $v)
  536. {
  537. $businessData[$v->student_id]=array(
  538. 'username'=>$v->username,
  539. 'student_card'=>$v->student_card,
  540. 'school_student_card'=>$v->school_student_card,
  541. 'zhixue_student_card'=>$v->zhixue_student_card,
  542. );
  543. }
  544. }
  545. $html='';
  546. $i=1;
  547. $smid = safe_replace(Yii::app()->request->getParam('semesterId'));
  548. foreach ($_allStudent as $item){
  549. $isZj='是';
  550. if($item['is_outer']==1){
  551. $isZj='否';
  552. }
  553. $semesterStatus='非当前学期';
  554. if($smid==$item['semester_id']){
  555. $semesterStatus='当前学期';
  556. }
  557. $html.='<li class="countermark-list">';
  558. $html.='<div class="card-lis-data flex">';
  559. $html.='<span class="card-list-menu gray-font">姓名</span>';
  560. $html.='<span class="card-list-msg flex-one">'.$item['modify_name'].'(原'.$item['realname'].')</span>';
  561. $html.='</div>';
  562. $html.='<div class="card-lis-data flex">';
  563. $html.='<span class="card-list-menu gray-font">班级</span>';
  564. $html.='<span class="card-list-msg flex-one">'.$item['class_name'].'</span>';
  565. $html.='</div>';
  566. $html.='<div class="card-lis-data flex">';
  567. $html.='<span class="card-list-menu gray-font">学期</span>';
  568. $html.='<span class="card-list-msg flex-one">'.$item['semester_name'].'</span>';
  569. $html.='</div>';
  570. $html.='<div class="card-lis-data flex">';
  571. $html.='<span class="card-list-menu gray-font">学期状态</span>';
  572. $html.='<span class="card-list-msg flex-one">'.$semesterStatus.'</span>';
  573. $html.='</div>';
  574. $html.='<div class="card-lis-data flex">';
  575. $html.='<span class="card-list-menu gray-font">班级序号</span>';
  576. $html.='<span class="card-list-msg flex-one">'.$item['serial_number'].'</span>';
  577. $html.='</div>';
  578. $html.='<div class="card-lis-data flex">';
  579. $html.='<span class="card-list-menu gray-font">学号</span>';
  580. $html.='<span class="card-list-msg flex-one">'.$item['userno'].'</span>';
  581. $html.='</div>';
  582. $html.='<div class="card-lis-data flex">';
  583. $html.='<span class="card-list-menu gray-font">登录账号</span>';
  584. if(isset($businessData[$item['student_id']])){
  585. $html.='<span class="card-list-msg flex-one">'.$businessData[$item['student_id']]['username'].'</span>';
  586. }else{
  587. $html.='<span class="card-list-msg flex-one"></span>';
  588. }
  589. $html.='</div>';
  590. $html.='<div class="card-lis-data flex">';
  591. $html.='<span class="card-list-menu gray-font">系统准考证号</span>';
  592. if(isset($businessData[$item['student_id']])){
  593. $html.='<span class="card-list-msg flex-one">'.$businessData[$item['student_id']]['student_card'].'</span>';
  594. }else{
  595. $html.='<span class="card-list-msg flex-one"></span>';
  596. }
  597. $html.='</div>';
  598. $html.='<div class="card-lis-data flex">';
  599. $html.='<span class="card-list-menu gray-font">学校准考证号</span>';
  600. if(isset($businessData[$item['student_id']])){
  601. $html.='<span class="card-list-msg flex-one">'.$businessData[$item['student_id']]['school_student_card'].'</span>';
  602. }else{
  603. $html.='<span class="card-list-msg flex-one"></span>';
  604. }
  605. $html.='</div>';
  606. $html.='<div class="card-lis-data flex">';
  607. $html.='<span class="card-list-menu gray-font">智学网考号</span>';
  608. if(isset($businessData[$item['student_id']])){
  609. $html.='<span class="card-list-msg flex-one">'.$businessData[$item['student_id']]['zhixue_student_card'].'</span>';
  610. }else{
  611. $html.='<span class="card-list-msg flex-one"></span>';
  612. }
  613. $html.='</div>';
  614. $html.='<div class="card-lis-data flex">';
  615. $html.='<span class="card-list-menu gray-font">身份证号</span>';
  616. $html.='<span class="card-list-msg flex-one">'.$item['id_number'].'</span>';
  617. $html.='</div>';
  618. $html.='<div class="card-lis-data flex">';
  619. $html.='<span class="card-list-menu gray-font">是否为在籍生</span>';
  620. $html.='<span class="card-list-msg flex-one">'.$isZj.'</span>';
  621. $html.='</div>';
  622. $html.='<span rel="'.$item['student_id'].'" data="'.$item['modify_name'].'" class="relieve-relate green-font pointer">解除关联</span>';
  623. $html.='</li>';
  624. $i++;
  625. }
  626. }
  627. }
  628. $result['data']=$html;
  629. $result['status']=1;
  630. exit(json_encode($result));
  631. }
  632. //学生历史成绩
  633. public function actionGetHistoryScore(){
  634. $student_id=Req::post('student_id');
  635. $result['status']=0;
  636. if(!$student_id ){
  637. exit(json_encode($result));
  638. }
  639. $Sql="SELECT scoring,spr.class_id,spr.exam_id,e.tpl_data,e.exam_group_id,e.name FROM `student_paper_relation` spr ";
  640. $Sql.="join exam e on spr.exam_id=e.exam_id ";
  641. $Sql.=" where student_id='".$student_id."' and e.status=1 order by e.create_time desc limit 10";
  642. $All_Exam=$this->sConn->createCommand($Sql)->queryAll();
  643. $list=array();
  644. if($All_Exam){
  645. $result['status']=1;
  646. foreach ($All_Exam as $val){
  647. $class_id=$val['class_id'];
  648. $exam_id=$val['exam_id'];
  649. $exam_date='';
  650. if(isset($val['tpl_data']) && $tpl_data=json_decode($val['tpl_data'],true)){
  651. $exam_date=$tpl_data['examDate'];
  652. }
  653. //班级平均分
  654. $sql_c="SELECT AVG(scoring) as avg FROM `student_paper_relation` where exam_id='.$exam_id.' ";
  655. $class_avg = $this->sConn->createCommand($sql_c)->queryRow();
  656. //年级平均分
  657. $sql_g="SELECT AVG(scoring) as avg from student_paper_relation where exam_id in( SELECT exam_id from exam where exam_group_id =".$val['exam_group_id'].")";
  658. $grade_avg = $this->sConn->createCommand($sql_g)->queryRow();
  659. //班级排名
  660. $sql_cr="SELECT student_id FROM `student_paper_relation` where exam_id='".$exam_id."' order by scoring desc";
  661. $class_all_score = $this->sConn->createCommand($sql_cr)->queryAll();
  662. $class_rank=0;
  663. if($class_all_score){
  664. foreach ($class_all_score as $key=> $item){
  665. if($item['student_id']==$student_id){
  666. $class_rank=($key+1);
  667. break;
  668. }
  669. }
  670. }
  671. //年级排名
  672. $sql_gr="SELECT student_id from student_paper_relation where exam_id in( SELECT exam_id from exam where exam_group_id =".$val['exam_group_id'].") order by scoring desc";
  673. $grade_all_data = $this->sConn->createCommand($sql_gr)->queryAll();
  674. $grade_rank=0;
  675. if($grade_all_data){
  676. foreach ($grade_all_data as $key=>$item){
  677. if($item['student_id']==$student_id){
  678. $grade_rank=($key+1);
  679. break;
  680. }
  681. }
  682. }
  683. $list[]=array(
  684. 'score'=>$val['scoring'],
  685. 'exam_name'=>$val['name'],
  686. 'exam_date'=>$exam_date,
  687. 'class_avg'=>number_format($class_avg['avg'],2),
  688. 'grade_avg'=>number_format($grade_avg['avg'],2),
  689. 'class_rank'=>$class_rank,
  690. 'grade_rank'=>$grade_rank
  691. );
  692. }
  693. $result['data']=$list;
  694. }
  695. exit(json_encode($result));
  696. }
  697. //手动关联账号
  698. public function actionRelationHand(){
  699. $startStudentId=Req::post('startCardId'); //辅号
  700. $endStudentId=Req::post('endCardId'); //主账号
  701. $result['status']=0;
  702. $result['number']=0;
  703. $result['msg']='合并失败';
  704. if(!$startStudentId || !$endStudentId){
  705. $result['msg']='参数不正确';
  706. exit(json_encode($result));
  707. }
  708. //查询身份证号
  709. $masterStudent=$this->sConn->createCommand("select id_number from student_check where student_id='".$endStudentId."'")->queryRow();
  710. $slavesStudent=$this->sConn->createCommand("select id_number from student_check where student_id='".$startStudentId."'")->queryRow();
  711. if(!$masterStudent || !$slavesStudent){
  712. $result['msg']='参数不正确';
  713. exit(json_encode($result));
  714. }
  715. $updateStudentCheck='';
  716. if(!$masterStudent['id_number'] && !$slavesStudent['id_number']){
  717. $result['msg']='关联学生缺少身份证号';
  718. exit(json_encode($result));
  719. }
  720. if(!$masterStudent['id_number'] && $slavesStudent['id_number']){
  721. $updateStudentCheck="update student_check set id_number='".$slavesStudent['id_number']."' where student_id='".$endStudentId."'";
  722. }elseif($masterStudent['id_number'] && !$slavesStudent['id_number']){
  723. $updateStudentCheck="update student_check set id_number='".$masterStudent['id_number']."' where student_id='".$startStudentId."'";
  724. }elseif($masterStudent['id_number']!=$slavesStudent['id_number']){
  725. $result['msg']='身份证号不匹配!';
  726. exit(json_encode($result));
  727. }
  728. //查询被拖动账号有没有关联记录
  729. $sql_s="select * from student_relation where find_in_set('".$startStudentId."',relation_student_id);";
  730. $slaves_relation = $this->sConn->createCommand($sql_s)->queryRow();
  731. //主账号有没有关联记录
  732. $sql_m="select * from student_relation where find_in_set('".$endStudentId."',relation_student_id);";
  733. $master_Relation = $this->sConn->createCommand($sql_m)->queryRow();
  734. if($slaves_relation){
  735. if($master_Relation){//主账号有关联
  736. if($master_Relation['master_student_id']!=$slaves_relation['master_student_id']){
  737. $m_relation_student_id=explode(',',$master_Relation['relation_student_id']);
  738. $s_relation_student_id=explode(',',$slaves_relation['relation_student_id']);
  739. $relation_student_id=array_unique(array_merge($m_relation_student_id,$s_relation_student_id));
  740. $sql_u="update student_relation set relation_student_id='".implode(',',$relation_student_id)."' where master_student_id='".$master_Relation['master_student_id']."';";
  741. $result['number']=count($relation_student_id)-1;
  742. }
  743. }else{ //主账号无关联
  744. $relation_student_id=explode(',',$slaves_relation['relation_student_id']);
  745. if(!in_array((string)$endStudentId,$relation_student_id,true)){
  746. $relation_student_id[]=$endStudentId;
  747. $sql_u="update student_relation set master_student_id='".$endStudentId."',relation_student_id='".implode(',',$relation_student_id)."' where master_student_id='".$slaves_relation['master_student_id']."';";
  748. $result['number']=count($relation_student_id)-1;
  749. }
  750. }
  751. }else{ //辅号无关联记录
  752. if($master_Relation){ //主号有关联记录
  753. $m_relation_student_id=explode(',',$master_Relation['relation_student_id']);
  754. if(!in_array((string)$startStudentId,$m_relation_student_id,true)){
  755. $m_relation_student_id[]=$startStudentId;
  756. $sql_u="update student_relation set relation_student_id='".implode(',',$m_relation_student_id)."' where master_student_id='".$master_Relation['master_student_id']."';";
  757. $result['number']=count($m_relation_student_id)-1;
  758. }
  759. }else{//主号无关联记录
  760. $relation_student_id=array($startStudentId,$endStudentId);
  761. $sql_u="insert into student_relation(`master_student_id`,`relation_student_id`) values ('".$endStudentId."','".implode(',',$relation_student_id)."');";
  762. $result['number']=1;
  763. }
  764. }
  765. if(isset($sql_u)){
  766. $this->sConn->createCommand($sql_u)->execute();
  767. if($updateStudentCheck){
  768. $this->sConn->createCommand($updateStudentCheck)->execute();
  769. }
  770. $result['status']=1;
  771. }
  772. exit(json_encode($result));
  773. }
  774. //解除关联
  775. public function actionCancelRelation(){
  776. $student_id=Req::post('student_id');
  777. $result['status']=0;
  778. if(!$student_id){
  779. exit(json_encode($result));
  780. }
  781. //查询被拖动账号有没有关联记录
  782. $sql_s="select * from student_relation where find_in_set('".$student_id."',relation_student_id);";
  783. $slaves_relation = $this->sConn->createCommand($sql_s)->queryRow();
  784. if(!$slaves_relation){
  785. $result['msg']='无关联记录';
  786. exit(json_encode($result));
  787. }
  788. $relation_student_id=explode(',',$slaves_relation['relation_student_id']);
  789. if(in_array((string)$student_id,$relation_student_id,true)){
  790. unset($relation_student_id[array_search($student_id,$relation_student_id)]);
  791. if(count($relation_student_id)<2){
  792. $sql_u="delete from student_relation where master_student_id='".$slaves_relation['master_student_id']."'";
  793. if($this->sConn->createCommand($sql_u)->execute()){
  794. $result['status']=1;
  795. $sql="update student_check set is_relation=0 where student_id='".$student_id."' or student_id='".$slaves_relation['master_student_id']."' ";
  796. $this->sConn->createCommand($sql)->execute();
  797. }
  798. }else{
  799. $sql_u="update student_relation set relation_student_id='".implode(',',$relation_student_id)."' where master_student_id='".$slaves_relation['master_student_id']."'";
  800. if($this->sConn->createCommand($sql_u)->execute()){
  801. $result['status']=1;
  802. }
  803. }
  804. }
  805. exit(json_encode($result));
  806. }
  807. //检查
  808. public function actionCheckHandle(){
  809. $name=Req::post('name');
  810. $result['status']=0;
  811. $sql="SELECT sc.realname,sc.class_id,sc.student_id,sc.modify_name,sc.is_relation,sc.is_outer,sc.id_number,c.class_name,s.semester_id,s.semester_name,s.school_year,s.end_time,sc.is_ignore FROM `student_check` sc ";
  812. $sql.="LEFT JOIN class c on sc.class_id=c.class_id ";
  813. $sql.="LEFT JOIN semester s on s.semester_id=c.semester_id ";
  814. $sql.="LEFT JOIN student_class_relation scr on scr.student_id=sc.student_id ";
  815. $sql.=" where modify_name='".$name."' and (class_name <>'' or class_name is not null ) and sc.is_relation=0 and s.semester_id <>'' and scr.status=0 and sc.is_ignore=0 ";
  816. $sql.="order by end_time desc ;";
  817. $nameArr=array();
  818. $_allStudent = $this->sConn->createCommand($sql)->queryAll();
  819. if(!$_allStudent){
  820. //没有未处理学生,表示这一组已处理完毕
  821. $result['status']=1;
  822. }else{
  823. $studentIds=array();
  824. //检查身份证号
  825. foreach ($_allStudent as $key=> $val){
  826. if($val['id_number']){
  827. $studentIds[]=$val['student_id'];
  828. unset($_allStudent[$key]);
  829. }else{
  830. //查检关联
  831. $sql_r="select * from student_relation where find_in_set('".$val['student_id']."',relation_student_id)";
  832. $Relation = $this->sConn->createCommand($sql_r)->queryRow();
  833. if($Relation){
  834. $studentIds[]=$val['student_id'];
  835. unset($_allStudent[$key]);
  836. }
  837. }
  838. }
  839. if(!empty($_allStudent)){
  840. if(count($_allStudent)==1){
  841. $result['status']=1; //处理完毕
  842. }else{
  843. $result['status']=2; //还需要继续处理
  844. }
  845. }else{
  846. $result['status']=1; //处理完毕
  847. }
  848. if($studentIds){
  849. //处理完毕,标记
  850. $sql_u="update `student_check` set is_relation=1 where student_id in(".implode(',',$studentIds).")";
  851. $this->sConn->createCommand($sql_u)->execute();
  852. }
  853. }
  854. exit(json_encode($result));
  855. }
  856. //放弃检测
  857. public function actionGiveUp(){
  858. $result['status']=0;
  859. $del_sql="truncate `student_check`;";
  860. $this->sConn->createCommand($del_sql)->execute();
  861. $result['status']=1;
  862. exit(json_encode($result));
  863. }
  864. public function actionTest(){
  865. $data=array();
  866. $this->render('test', $data);
  867. }
  868. //忽略功能
  869. public function actionIgnore(){
  870. $result['status']=0;
  871. $name=Req::post('name');
  872. $semester=Req::post('semester');
  873. $sql="SELECT sc.student_id FROM `student_check` sc ";
  874. $sql.="LEFT JOIN class c on sc.class_id=c.class_id ";
  875. $sql.="LEFT JOIN semester s on s.semester_id=c.semester_id ";
  876. $sql.=" where modify_name='".$name."' and (class_name <>'' or class_name is not null ) and sc.is_relation=0 and s.semester_id ='".$semester."' ";
  877. $data = $this->sConn->createCommand($sql)->queryAll();
  878. $studentIds=array();
  879. if($data){
  880. foreach ($data as $val){
  881. $studentIds[]=$val['student_id'];
  882. }
  883. }
  884. if($studentIds){
  885. $rs= $this->sConn->createCommand("update `student_check` set is_ignore=1 where student_id in(".implode(',',$studentIds).")")->execute();
  886. if($rs){
  887. $result['status']=1;
  888. }
  889. }
  890. exit(json_encode($result));
  891. }
  892. }