ZhiliaoController.php 88 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177
  1. <?php
  2. /**
  3. * 家校考试管理控制器类
  4. * @author li
  5. * @date 2019-04-17 10:50:00
  6. * @company 上海风车教育有限公司.
  7. */
  8. class ZhiliaoController extends Controller{
  9. // 首页
  10. public function actionIndex(){
  11. Url::clean();
  12. $Grade=intval(Req::get('grade'));
  13. $Class=Req::get('classId');
  14. $Page=intval(Req::get('page'));
  15. $Display=intval(Req::get('display'));
  16. $coach_id = $this->coachId;
  17. $semester_id = $this->semesterId;
  18. $PageLimit=9;
  19. if(!$Page) $Page=1;
  20. $ZlExamGroup=new ZlExamGroup();
  21. $result=$ZlExamGroup->getList($Grade,$Class,$semester_id,$Page,$PageLimit,$Display);
  22. $ZlStudentExamRelation=new ZlStudentExamRelation();
  23. $ZlStudentExamRs=new ZlStudentExamRs();
  24. if($result['data']){
  25. foreach($result['data'] as $key=>$val){
  26. $tpl_data=json_decode($val['zl_tpl_data'],true);
  27. $result['data'][$key]['classCount']=$tpl_data['classCount'];
  28. $result['data'][$key]['subjectCount']=count($tpl_data['items']);
  29. $subjectArr=array();
  30. foreach ($tpl_data['items'] as $sid=>$c){
  31. $subjectArr[]= Yii::app()->params['subjectId'][$sid];
  32. }
  33. $result['data'][$key]['subjects']=$subjectArr;
  34. //上传进度
  35. $allStudent=$ZlStudentExamRelation->getCountStudentByExamGroupId($val['zl_exam_group_id']);
  36. $allStudentRs=$ZlStudentExamRs->getCountStudentRsByExamGroupId($val['zl_exam_group_id']);
  37. $result['data'][$key]['progress']=$allStudentRs.'/'.$allStudent;
  38. if($allStudentRs){
  39. $result['data'][$key]['status']=1;
  40. }else{
  41. $result['data'][$key]['status']=0;
  42. }
  43. }
  44. }
  45. // debug($result);
  46. $printType = '2';
  47. $printTypeData = 0;
  48. $viewData=array(
  49. 'pageTotal' =>$result['pageTotal'],
  50. 'dataList' =>$result['data'],
  51. 'page' =>$Page,
  52. 'grade' =>$Grade,
  53. 'class' =>$Class,
  54. 'display' =>$Display,
  55. 'totalCount' =>$result['totalCount'],
  56. 'printType' =>$printType
  57. );
  58. //$HeadInfo=$this->getHeadInfo();
  59. // $viewData=array_merge($viewData,$HeadInfo);
  60. $this->render('index',$viewData);
  61. }
  62. public function actionEdit(){
  63. $viewData=array();
  64. $viewData=array(
  65. 'printType'=>'zl'
  66. );
  67. if(isset(Yii::app()->params['subjectId']) && Yii::app()->params['subjectId']){
  68. $viewData['subject']=Yii::app()->params['subjectId'];
  69. unset($viewData['subject'][3]);
  70. unset($viewData['subject'][51]);
  71. unset($viewData['subject'][20]);
  72. }
  73. $exam_group_id = Req::get("exam_group_id");
  74. if($exam_group_id){
  75. //读取考试信息
  76. $ZlExamGroup=new ZlExamGroup();
  77. $ZlStudentExamRs=new ZlStudentExamRs();
  78. $studentRs=$ZlStudentExamRs->getCountStudentRsByExamGroupId($exam_group_id);
  79. if($studentRs){
  80. Yii::app()->jump->error('已上传成绩,不能编辑考试!');
  81. }
  82. $examData=$ZlExamGroup->getExamByExamGroupId($exam_group_id);
  83. $examView=array();
  84. $tplData=array();
  85. foreach ($examData as $val){
  86. if(!$tplData){
  87. $tplData=json_decode($val['zl_tpl_data'],true);
  88. $examView['items']=$tplData['items'];
  89. //$examView['examDate']=$tplData['examDate'];
  90. }
  91. $examView['zl_exam_name']=$val['zl_exam_name'];
  92. $examView['zl_exam_type']=$val['zl_exam_type'];
  93. $examView['examDate']=date('Y-m-d',$val['zl_exam_date']);
  94. $examView['classes'][$val['zl_class_id']]=ClassModel::model()->getClassName($val['zl_class_id']);
  95. $examView['grade']=$val['zl_grade'];
  96. }
  97. $viewData['exam']=$examView;
  98. $viewData['exam_group_id']=$exam_group_id;
  99. }
  100. $this->render('thirdview',$viewData);
  101. }
  102. public function actionAjaxchangeclasses()
  103. {
  104. $result = array();
  105. $error = array();
  106. $class_arr_select=array();
  107. if (Yii::app()->request->getIsPostRequest()){
  108. $selectedClassId=Req::post('selectedClassId');
  109. $semester_id = $this->semesterId;
  110. if($selectedClassId){
  111. $anotherSelectClass=ClassModel ::model()->getClassArrayByIds($selectedClassId);
  112. $i = 0;
  113. if($anotherSelectClass){
  114. foreach ($anotherSelectClass as $cas){
  115. $class_arr_select[$i]['class_id'] = $cas['class_id'];
  116. $class_arr_select[$i]['class_name'] = $cas['class_name'];
  117. $class_arr_select[$i]['grade'] = $cas['grade'];
  118. $i++;
  119. $class_arr_select_ids[] = $cas['class_id'];
  120. }
  121. }
  122. }
  123. $class_arr_select_ids_str = "";
  124. if(isset($class_arr_select_ids) && $class_arr_select_ids){
  125. foreach($class_arr_select_ids as $v){
  126. $class_arr_select_ids_str.=$v.",";
  127. }
  128. $class_arr_select_ids_str=substr($class_arr_select_ids_str,0,-1);
  129. }
  130. $class_arr_noselect_data = ClassModel ::model()->getNoSelectclasses($semester_id,$class_arr_select_ids_str);
  131. $class_arr_noselect =array();
  132. $j = 0;
  133. if($class_arr_noselect_data){
  134. foreach($class_arr_noselect_data as $cans){
  135. $class_arr_noselect[$j]['class_id'] = $cans->class_id;
  136. $class_arr_noselect[$j]['class_name'] = $cans->class_name;
  137. $class_arr_noselect[$j]['grade'] = $cans->grade;
  138. $j++;
  139. }
  140. }
  141. $result['class_arr_select'] = $class_arr_select;
  142. $result['class_arr_noselect'] = $class_arr_noselect;
  143. }else{
  144. $error[] = "错误的来源";
  145. }
  146. header('Content-Type: application/json');
  147. if($error){
  148. echo json_encode(array('status' => 0, 'error'=> implode('<br/>', $error)));exit;
  149. }else{
  150. echo json_encode($result);exit;
  151. }
  152. }
  153. public function actionCreateexam(){
  154. $error = array();
  155. $examName = Req::post("examName");
  156. $type = (int)Req::post("type");
  157. $classIds = Req::post("classIds");
  158. $subjects = Req::post("subjects");
  159. $examDate = Req::post("examDate");
  160. $grade = Req::post("grade");
  161. $ExamGroupId = Req::post("exam_group_id");
  162. if(empty($classIds)){
  163. $error[] = '请指定考试班级';
  164. }else{
  165. $classIds = explode(',',substr($classIds,0,-1));
  166. }
  167. if(empty($examName)){
  168. $error[] = '请设置考试名称';
  169. }
  170. if ($type <= 0 || $type > 8) {
  171. $error[] = '考试类型错误';
  172. }
  173. if(empty($subjects)){
  174. $error[] = '请选择科目';
  175. }
  176. if(empty($examDate)){
  177. $error[] = '请指定考试时间';
  178. }
  179. if((time()-strtotime($examDate))>86400*90){
  180. $error[] = '考试时间不正确';
  181. }
  182. if($error){
  183. Yii::app()->jump->error(implode(',',$error));
  184. }else{
  185. //解析科目分数
  186. $tplData=array();
  187. $tplData['name']=$examName;
  188. // $tplData['examDate']=$examDate;
  189. $tplData['classCount']=count($classIds);
  190. $subject_ids=array();
  191. $subjectArr=explode(',',$subjects);
  192. if($subjectArr){
  193. $total_score=0;
  194. foreach ($subjectArr as $value){
  195. $subject_score=explode('///',$value);
  196. $tplData['items'][$subject_score[0]]=$subject_score[1];
  197. $total_score+=$subject_score[1];
  198. $subject_ids[]=$subject_score[0];
  199. }
  200. $tplData['scores']=$total_score;
  201. }
  202. $time = time();
  203. $transaction = $this->sConn->beginTransaction();
  204. try{
  205. if($ExamGroupId){
  206. $this->sConn->createCommand("delete from `zl_exam_group` where zl_exam_group_id='".$ExamGroupId."'")->execute();
  207. $this->sConn->createCommand("delete from `zl_exam` where zl_exam_group_id='".$ExamGroupId."'")->execute();
  208. $this->sConn->createCommand("delete from `zl_student_exam_relation` where zl_exam_group_id='".$ExamGroupId."'")->execute();
  209. $newExamGroupId = $ExamGroupId;
  210. }else{
  211. // $newExamGroupId = $this->schoolManager->UUID_SHORT();
  212. $newExamGroupId=getUniqueId($this->schoolId);
  213. }
  214. $sql = "insert into `zl_exam_group` (`zl_exam_group_id`,`zl_exam_name`,`zl_exam_type`,`zl_grade`,`zl_exam_date`,`zl_create_time`,`zl_is_display`,`zl_semester_id`) "
  215. . "values (".$newExamGroupId.",'".$examName."',".$type.",'".$grade."','".strtotime($examDate)."',".time().",0,'".$this->semesterId."')";
  216. $this->sConn->createCommand($sql)->execute();
  217. foreach($classIds as $classId){
  218. //$newExamId = $this->schoolManager->UUID_SHORT();
  219. $newExamId=getUniqueId($this->schoolId);
  220. $sql = "select g.card_length,g.card_status FROM grade g LEFT JOIN class c on g.id = c.grade where c.class_id = $classId";
  221. $cardData = $this->sConn->createCommand($sql)->queryRow();
  222. if($cardData['card_status']==0){
  223. $cardData['card_length'] = 8;
  224. if($this->schoolId >999){
  225. $cardData['card_length'] = 9;
  226. }
  227. }
  228. $this->sConn->createCommand()->insert('zl_exam',array(
  229. 'zl_exam_id' => $newExamId,
  230. 'zl_exam_group_id' => $newExamGroupId,
  231. 'zl_semester_id' => $this->semesterId,
  232. 'zl_subject_ids' => implode(',',$subject_ids),
  233. 'create_time' => $time,
  234. 'zl_tpl_data' => jsonEncode($tplData),
  235. 'zl_class_id' => $classId,
  236. ));
  237. $studentIds = SStudentClassRelation::model()->getStudentIdsByClassId_Status_0($classId);
  238. $studentIds_0 = BusinessStudent::model()->keepStudentsStatus_0($studentIds);
  239. $BStudentCards = BusinessStudent::model()->getCardsByStudentIds($studentIds_0);
  240. if($studentIds_0){
  241. foreach ($studentIds_0 as $studentId) {
  242. $this->sConn->createCommand()->insert('zl_student_exam_relation', array(
  243. 'zl_student_id' => $studentId,
  244. 'zl_exam_group_id' => $newExamGroupId,
  245. 'zl_exam_id' => $newExamId,
  246. 'zl_semester_id' => $this->semesterId,
  247. 'zl_class_id' => $classId,
  248. 'zl_student_card' => (isset($BStudentCards[0]) && isset($BStudentCards[0][$studentId]) ? $BStudentCards[0][$studentId] : 0),
  249. 'zl_school_student_card' => (isset($BStudentCards[1]) && isset($BStudentCards[1][$studentId]) ? $BStudentCards[1][$studentId] : ''),
  250. ));
  251. }
  252. }
  253. }
  254. $transaction->commit();
  255. }catch(Exception $e){
  256. $transaction->rollBack();
  257. if (YII_ENV == 'production') {
  258. $error[] = '系统错误[SQL]';
  259. } else {
  260. $error[] = $e->getMessage();
  261. }
  262. }
  263. }
  264. if(!$error){
  265. $this->redirect($this->createUrl('zhiliao/index'));
  266. }else{
  267. Yii::app()->jump->error(implode(',',$error));
  268. }
  269. }
  270. public function actionExam_list()
  271. {
  272. $exam_group_id = Req::get("exam_group_id");
  273. if($exam_group_id>0)
  274. {
  275. $classId = Req::get("classId");
  276. $condition = array();
  277. if($classId)
  278. $condition[] = "e.zl_class_id = '{$classId}'";
  279. $condition[] = "eg.zl_exam_group_id = '{$exam_group_id}'";
  280. // $classes = $this->schoolManager->getSemesterClasses($this->semesterId);
  281. $classes=ClassModel::model()->getClassBySemester($this->semesterId);
  282. if(!$classes)
  283. {
  284. Yii::app()->jump->error('本学期尚未建班级!');
  285. }
  286. $_classes = array();
  287. foreach($classes as $v)
  288. {
  289. $_classes[$v['class_id']][$v['class_id']] = $v;
  290. }
  291. $resultList = $this->schoolManager->getZlExamList($condition);
  292. $subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId);
  293. $data['printList'] = $resultList['rs'];
  294. $data["classes"] = $_classes;
  295. $data['pages'] = $resultList['pager'];
  296. $data['page_total'] = $resultList['pager']->rowsCount;
  297. $data["classId"] = $classId;
  298. $data["exam_group_id"] = $exam_group_id;
  299. $data["subject"] = $subject_exam_data;
  300. $this->render('exam_list',$data);
  301. }
  302. }
  303. //删除全部未考试学生
  304. public function actionDelExamStudentAll()
  305. {
  306. $exam_group_id = Req::post('exam_group_id');
  307. if(!$exam_group_id)
  308. {
  309. echo json_encode(array('status'=>0));exit;
  310. }
  311. $ZlStudentExamRelation=new ZlStudentExamRelation();
  312. $student_data =$ZlStudentExamRelation->getCountStudentByExamGroupId($exam_group_id);
  313. if(!$student_data){
  314. echo json_encode(array('status'=>2));exit;
  315. }
  316. if($ZlStudentExamRelation->delStudentPaperByExamIds($exam_group_id))
  317. {
  318. //操作日志
  319. if(Yii::app()->params['handle_log_on_off'])
  320. {
  321. writeFileLog(jsonEncode(array(
  322. "exam_group_id" =>$exam_group_id,
  323. "operate_project" => 'zsyas2',
  324. "school_id" => $this->schoolId,
  325. "title" => '清空本次考试的学生(家校考试)',
  326. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  327. "operate_method" => $this->action,
  328. "operate_url" => $this->getRoute(),
  329. "operate_sql" => json_encode(array('delete'=>array(
  330. 'student_paper_relation'=>array('exam_group_id'=>$exam_group_id)))),
  331. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  332. "date"=>date('Y-m-d H:i:s')
  333. )));
  334. }
  335. echo json_encode(array('status'=>1));exit;
  336. }
  337. echo json_encode(array('status'=>0));exit;
  338. }
  339. //上传成绩
  340. public function actionUpload(){
  341. $exam_group_id = Req::get("exam_group_id");
  342. $sql="select * from import_score_temp where exam_group_id<>'".$exam_group_id."' and exam_type=1 limit 1";
  343. $anotherData=$this->sConn->createCommand($sql)->queryRow();
  344. if($anotherData){
  345. Yii::app()->jump->error('请先处理完成其它考试上传成绩数据,再上传新的考试');
  346. }
  347. $sql="select * from import_score_temp where exam_group_id='".$exam_group_id."' and exam_type=1 limit 1";
  348. $Data=$this->sConn->createCommand($sql)->queryRow();
  349. if($Data){
  350. //跳转检测页
  351. $this->redirect(Yii::app()->createUrl('zhiliao/check_excel'));
  352. }
  353. $printType = '2';
  354. $viewData=array(
  355. 'printType' =>$printType,
  356. 'examGroupId' =>$exam_group_id
  357. );
  358. $this->render('upload',$viewData);
  359. }
  360. //新版导入成绩,导入表格
  361. public function actionImportStore(){
  362. ini_set ('memory_limit', '300M');
  363. if(!$_FILES){
  364. Yii::app()->jump->error('文件大小超过范围');
  365. }else{
  366. if(!isset($_FILES['exname']) || !isset($_FILES['exname']['size']) || $_FILES['exname']['size'] > 5242880){
  367. Yii::app()->jump->error('文件大小超过范围');
  368. }
  369. }
  370. if (Yii::app()->request->getIsPostRequest()) {
  371. $exam_group_id=Req::post('exam_group_id');
  372. if(!$exam_group_id)
  373. {
  374. Yii::app()->jump->error('请选择考试信息');
  375. }
  376. $uploader = new Uploader("upload/tmpDir/zhiliao_chengji/{$this->schoolId}/");
  377. $uploader->allowTypes = array("xls","xlsx");
  378. $uploader->fieldsMappings = array("exname" => array(0 => $this->schoolId . date('Ymdhis', time())));
  379. $file = $uploader->act();
  380. $file = Arr::current(Arr::current($file));
  381. if (!$file || !isset($file["error"]))
  382. Yii::app()->jump->error('请上传的Excel!');
  383. if ($file["error"] != 0) {
  384. switch ($file["error"]) {
  385. case 2001:
  386. Yii::app()->jump->error('文件类型不符');
  387. break;
  388. case 2002:
  389. Yii::app()->jump->error('文件大小超出允许范围');
  390. break;
  391. default:
  392. Yii::app()->jump->error('上传失败');
  393. break;
  394. }
  395. }
  396. $inputFileName = $file["src"];
  397. // 导入PHPExcel类
  398. Yii::import('application.extensions.*');
  399. require_once('phpexcel/PHPExcel/IOFactory.php');
  400. try{
  401. $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
  402. $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
  403. //FIXME 2019-12-02
  404. @unlink($file["src"]);
  405. }catch (Exception $e){
  406. //FIXME 2019-12-02
  407. @unlink($file["src"]);
  408. Yii::app()->jump->error('Excel格式不正确:'.$e->getMessage());
  409. }
  410. if(!$sheetData)
  411. {
  412. Yii::app()->jump->error('请正确的Excel!');
  413. }
  414. unset($objPHPExcel);
  415. unset($sheetData[1]);
  416. if(!$sheetData)
  417. {
  418. Yii::app()->jump->error('请输入学生成绩数据');
  419. }
  420. $ZlExam=new ZlExam();
  421. $exam_group_data = $ZlExam->getExamByExamGroupId($exam_group_id);
  422. //debug($exam_group_data);
  423. $total_score=0;
  424. //表格科目对应
  425. $letters = array('C','D','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');
  426. $allSubject=Yii::app()->params['subjectId'];
  427. unset($allSubject[3]);
  428. unset($allSubject[20]);
  429. unset($allSubject[51]);
  430. $subjectExcel=array();
  431. $subjectOrder=0;
  432. foreach ($allSubject as $key =>$val){
  433. $subjectExcel[$letters[$subjectOrder]]=$key;
  434. $subjectOrder++;
  435. }
  436. $zlSubjectIds=array(); //考试科目
  437. if($exam_group_data) {
  438. $zl_subject_ids=$exam_group_data[0]['zl_subject_ids'];
  439. $zlSubjectIds=explode(',',$zl_subject_ids);
  440. }
  441. $insertSql="insert into import_score_temp(`student_name`,`class_name`,`check_field_value`,`score_data`,`exam_group_id`,`check_field`,`renew`,`exam_type`) values";
  442. $valuesArray=array();
  443. foreach ($sheetData as $val){
  444. if(!isset($val['A']) || !isset($val['B']) ){
  445. continue;
  446. }
  447. $topic_score= array_merge(array(),array_slice($val,2));
  448. foreach ($topic_score as $k=>$v){
  449. if(!empty($v) && (!is_numeric($v) || floatval($v)<0)){
  450. Yii::app()->jump->error('分数必须是数值类型且》=0');
  451. }
  452. //验证科目
  453. if(isset($v) && !empty($zlSubjectIds) && in_array($subjectExcel[$k],$zlSubjectIds)){
  454. unset($zlSubjectIds[array_search($subjectExcel[$k],$zlSubjectIds)]);
  455. }
  456. }
  457. $valuesArray[]="('".$val['A']."','".$val['B']."','','".json_encode($topic_score)."','".$exam_group_id."','student_name','0',1)";
  458. }
  459. if(!empty($zlSubjectIds)){
  460. $errSubjects=array();
  461. foreach ($zlSubjectIds as $subjectId){
  462. $errSubjects[]=Yii::app()->params['subjectId'][$subjectId];
  463. }
  464. Yii::app()->jump->error('分数设置不正确,科目:【'.implode(',',$errSubjects).'】没有提交分数');
  465. }
  466. if($valuesArray){
  467. //$delSql="truncate table import_score_temp;";
  468. $delSql="delete from import_score_temp where exam_type=1;";
  469. $this->sConn->createCommand($delSql)->execute();
  470. $insertSql.=implode(',',$valuesArray);
  471. $this->sConn->createCommand($insertSql)->execute();
  472. $this->redirect(Yii::app()->createUrl('zhiliao/check_excel'));
  473. }else{
  474. Yii::app()->jump->error('没有发现学生成绩数据');
  475. }
  476. Yii::app()->jump->error('导入失败');
  477. }
  478. }
  479. //导入数据检测页
  480. public function actionCheck_Excel(){
  481. $sql="select * from import_score_temp where exam_type=1 limit 1";
  482. $data=$this->sConn->createCommand($sql)->queryRow();
  483. $data['check_field_name']='学生姓名';
  484. $data['need_check_name']=1;
  485. $this->render('check',$data);
  486. }
  487. //检测格式
  488. public function actionCheck_field_first(){
  489. $result['status']=0;
  490. $sql="select * from import_score_temp where exam_type=1";
  491. $All_Data=$this->sConn->createCommand($sql)->queryAll();
  492. if(!$All_Data){
  493. exit(json_encode($result));
  494. }
  495. $data=$All_Data[0];
  496. $check_field=$data['check_field'];
  497. $score_data=json_decode($data['score_data'],true);
  498. $exam_group_id=$data['exam_group_id'];
  499. if(!$score_data){
  500. $result['msg']='数据不完整';
  501. exit(json_encode($result));
  502. }
  503. //检测题量
  504. $ZlExam=new ZlExam();
  505. $exam_group_data = $ZlExam->getExamByExamGroupId($data['exam_group_id']);
  506. //debug($exam_group_data);
  507. $total_score=0;
  508. //表格科目对应
  509. $letters = array('C','D','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');
  510. $allSubject=Yii::app()->params['subjectId'];
  511. unset($allSubject[3]);
  512. unset($allSubject[51]);
  513. unset($allSubject[20]);
  514. $subjectExcel=array();
  515. $subjectOrder=0;
  516. foreach ($allSubject as $key =>$val){
  517. $subjectExcel[$letters[$subjectOrder]]=$key;
  518. $subjectOrder++;
  519. }
  520. if($exam_group_data) {
  521. $tpl_data=json_decode($exam_group_data[0]['zl_tpl_data'],true);
  522. if(!$tpl_data) {
  523. $result['msg']='考试数据错误';
  524. exit(json_encode($result));
  525. }
  526. $subjectScores=$tpl_data['items'];
  527. //检测试题数据
  528. foreach($All_Data as $key=> $val){
  529. $topic_score=json_decode($val['score_data'],true);
  530. $uploadSubjectCount=0;
  531. foreach($topic_score as $order => $v){
  532. if(!empty($v) && (!is_numeric($v) || floatval($v)<0)){
  533. $result['msg']='试题分数必须是数值类型:'.$val['student_name'];
  534. exit(json_encode($result));
  535. }
  536. if(isset($v)==true){
  537. $uploadSubjectCount++;
  538. if(isset($subjectExcel[$order])){
  539. if(isset($subjectScores[$subjectExcel[$order]])){
  540. if($v>$subjectScores[$subjectExcel[$order]]){
  541. $result['msg']=$val['student_name'].':科目:'.(Yii::app()->params['subjectId'][$subjectExcel[$order]]).'分数和考试设置分数不一致,提交分数:'.$v."试卷设置分数:".$subjectScores[$subjectExcel[$order]];
  542. exit(json_encode($result));
  543. }
  544. }else{
  545. $result['msg']=$val['student_name'].':科目:'.(Yii::app()->params['subjectId'][$subjectExcel[$order]]).'考试设置中未设置';
  546. exit(json_encode($result));
  547. }
  548. }else{
  549. $result['msg']='Excel格式不正确';
  550. exit(json_encode($result));
  551. }
  552. }
  553. }
  554. /*
  555. if($uploadSubjectCount!=count($subjectScores)){
  556. $result['msg']='上传科目数量和考试设置不一致';
  557. exit(json_encode($result));
  558. }
  559. */
  560. }
  561. $result['msg']='检测完成';
  562. $result['status']=1;
  563. }else{
  564. $result['msg']='未发现对应考试';
  565. exit(json_encode($result));
  566. }
  567. exit(json_encode($result));
  568. }
  569. //重新上传
  570. public function actionGiveup(){
  571. // $delSql="truncate table import_score_temp;";
  572. $delSql="delete from import_score_temp where exam_type=1;";
  573. $this->sConn->createCommand($delSql)->execute();
  574. $result['status']=1;
  575. exit(json_encode($result));
  576. }
  577. //检测姓名
  578. public function actionCheck_student_name(){
  579. ini_set('memory_limit','512M');
  580. set_time_limit(0);
  581. $result['status']=0;
  582. $result['data']=0;
  583. $student_all_data = $this->sConn->createCommand("SELECT id,student_name FROM `import_score_temp` `t` where exam_type=1")->queryAll();
  584. if($student_all_data){
  585. //去除非中文字符
  586. $updateArr=array();
  587. $preg="/[^\x{4E00}-\x{9FFF}^·]+/u";
  588. $count=0;
  589. foreach($student_all_data as $val){
  590. if(preg_match($preg,$val['student_name'])){
  591. $ModifyName = preg_replace($preg, "", $val['student_name']);
  592. if($ModifyName){
  593. $updateArr[$val['id']]=$ModifyName;
  594. $count++;
  595. }
  596. }else{
  597. $updateArr[$val['id']]=$val['student_name'];
  598. }
  599. }
  600. //组织更新语句
  601. if($updateArr){
  602. $arrNumber=ceil(count($updateArr)/500);
  603. $Arr=array_chunk($updateArr,$arrNumber,true);
  604. $transcation = $this->sConn->beginTransaction();
  605. try {
  606. foreach ($Arr as $item){
  607. $sql='update import_score_temp set `check_field_value`= case id ';
  608. foreach ($item as $key=> $val){
  609. $sql.=" WHEN ".$key." THEN '".$val."' ";
  610. }
  611. $sql.=" End ";
  612. $sql.=" where check_field_value='' or check_field_value is null and exam_type=1";
  613. $this->sConn->createCommand($sql)->execute();
  614. }
  615. $transcation->commit();
  616. $result['status']=1;
  617. }catch (Exception $e){
  618. $transcation->rollback();
  619. }
  620. }
  621. $result['count']=$count;
  622. }
  623. exit(json_encode($result));
  624. }
  625. //匹配信息
  626. public function actionMatching(){
  627. $noExistent=0; //不存在
  628. $repeat=0; //重复(组)
  629. $success=0; //匹配成功
  630. $scoreWrong=0; //成绩不正确
  631. $result['status']=0;
  632. $sql="select * from import_score_temp where exam_type=1 limit 1";
  633. $data=$this->sConn->createCommand($sql)->queryRow();
  634. if(!$data){
  635. exit(json_encode($result));
  636. }
  637. $check_field=$data['check_field'];
  638. $exam_group_id=$data['exam_group_id'];
  639. $classArr=array();
  640. $classIds=array();
  641. $check_data_group=array(); //检查字段对应临时表id
  642. $update_temp_data=array(); //更新临时表数据
  643. $student_card=array(); //学生id,准考证号对应数据
  644. $tpl_data=array();
  645. $updateSql=array();
  646. $ZlExam=new ZlExam();
  647. $exam_group_data=$ZlExam->getExamByExamGroupId($exam_group_id);
  648. $paperIds=array();
  649. if($exam_group_data){
  650. foreach ($exam_group_data as $v){
  651. if(!$tpl_data && isset($v['zl_tpl_data'])){
  652. $tpl_data=json_decode($v['zl_tpl_data'],true);
  653. }
  654. $classIds[]=$v['zl_class_id'];
  655. $examIds[]=$v['zl_exam_id'];
  656. }
  657. }
  658. //统计已经匹配成功的数据
  659. $success_student_data = $this->sConn->createCommand("SELECT id,student_name,check_field,exam_group_id,score_data,check_field_value FROM `import_score_temp` `t` where student_id is not null and student_id<>0 and exam_type=1")->queryAll();
  660. if($success_student_data){
  661. $success=count($success_student_data);
  662. }
  663. $check_field_val_arr=array();
  664. $student_all_data = $this->sConn->createCommand("SELECT id,student_name,check_field,exam_group_id,score_data,check_field_value FROM `import_score_temp` `t` where student_id is null or student_id=0 and exam_type=1 ")->queryAll();
  665. if(!$student_all_data){
  666. $result['repeat']=0;
  667. $result['success']=$success;
  668. $result['noExistent']=0;
  669. $result['status']=1;
  670. exit(json_encode($result));
  671. }
  672. foreach ($student_all_data as $val){
  673. //验证学生分数
  674. $check_field_val_arr[]="'".$val['check_field_value']."'";
  675. $check_data_group[$val['check_field_value']]=$val['id'];
  676. }
  677. //处理重复数据
  678. $repeat_group_data=array();
  679. $search_value_arr=array();
  680. foreach ($check_field_val_arr as $value){
  681. $repeat_group_data[$value][]=$value;
  682. }
  683. foreach ($repeat_group_data as $key=>$val){
  684. if(count($val)>1){
  685. $repeat++;
  686. $modify_name=str_replace("'",'',$key);
  687. $updateSql[]="update import_score_temp set is_repeat=1 where check_field_value='".$modify_name."' and (student_id is null or student_id=0) and exam_type=1";
  688. }else{
  689. $search_value_arr[]=$val[0];
  690. }
  691. }
  692. if($search_value_arr){
  693. $student_info=array();
  694. $sql="select si.student_id,si.realname from student_info si join zl_student_exam_relation spr on si.student_id = spr.zl_student_id where realname in(".implode(',',$search_value_arr).") and zl_exam_id in(".implode(',',$examIds).")";
  695. $student_info=$this->sConn->createCommand($sql)->queryAll();
  696. if(!$student_info){
  697. $noExistent=count($search_value_arr);
  698. $result['repeat']=$repeat;
  699. $result['success']=$success;
  700. $result['noExistent']=$noExistent;
  701. $result['status']=1;
  702. }else{
  703. $result['status']=1;
  704. //过滤掉已被删除的学生
  705. foreach ($student_info as $key=>$value){
  706. $sql_class_relation="select * from student_class_relation where student_id='".$value['student_id']."' and status=0 ";
  707. $student_class_realtion=$this->sConn->createCommand($sql_class_relation)->queryRow();
  708. if(!$student_class_realtion){
  709. unset($student_info[$key]);
  710. }
  711. }
  712. $nameArr=array();
  713. foreach ($student_info as $item){
  714. $preg="/[^\x{4E00}-\x{9FFF}^·]+/u";
  715. $ModifyName = preg_replace($preg, "", $item['realname']);
  716. $nameArr[$ModifyName][]=$item;
  717. }
  718. $noExistent=count($search_value_arr)-count($nameArr);
  719. if($noExistent<0) $noExistent=0;
  720. $result['noExistent']=$noExistent;
  721. foreach ($nameArr as $key=>$value){
  722. if(count($value)>1){
  723. $repeat++;
  724. $updateSql[]="update import_score_temp set is_repeat=1 where check_field_value='".$key."' and (student_id is null or student_id=0) and exam_type=1";
  725. }else{
  726. $success++;
  727. if(isset($check_data_group[$key])){
  728. $update_temp_data[$check_data_group[$key]]=$value[0]['student_id'];
  729. }
  730. }
  731. }
  732. $result['repeat']=$repeat;
  733. $result['success']=$success;
  734. }
  735. }else{
  736. $result['repeat']=$repeat;
  737. $result['success']=$success;
  738. $result['noExistent']=0;
  739. $result['status']=1;
  740. }
  741. //更新检测成功的数据
  742. if($update_temp_data || $updateSql){
  743. $transcation = $this->sConn->beginTransaction();
  744. try {
  745. if($update_temp_data) {
  746. if ($check_field == 'student_name') {
  747. $sql = 'update import_score_temp set `student_id`= case id ';
  748. } else {
  749. $sql = 'update import_score_temp set `student_id`= case id ';
  750. }
  751. foreach ($update_temp_data as $key => $val) {
  752. $sql .= " WHEN " . $key . " THEN '" . $val . "' ";
  753. }
  754. $sql .= " End ";
  755. $sql .= " where (student_id='' or student_id is null) and exam_type=1";
  756. $this->sConn->createCommand($sql)->execute();
  757. }
  758. if($updateSql){
  759. foreach ($updateSql as $query){
  760. $this->sConn->createCommand($query)->execute();
  761. }
  762. }
  763. $transcation->commit();
  764. $result['status']=1;
  765. }catch (Exception $e){
  766. $result['status']=0;
  767. $transcation->rollback();
  768. }
  769. }
  770. exit(json_encode($result));
  771. }
  772. //处理重复学生
  773. public function actionHandle_repeat(){
  774. $page=Req::post('page');
  775. $name_like=Req::post('name');
  776. if(!$page) $page=1;
  777. $pageSize=10;
  778. $offset=($page-1)*$pageSize;
  779. $sql="select * from import_score_temp where exam_type=1 limit 1";
  780. $checkData=$this->sConn->createCommand($sql)->queryRow();
  781. $check_field=$checkData['check_field'];
  782. $sql="select count(*) as count,check_field_value,check_field from import_score_temp where is_repeat=1 and exam_type=1 group by check_field_value ";
  783. if($name_like){
  784. $sql.=" having check_field_value='".$name_like."'";
  785. }
  786. $sql.="order by count desc";
  787. $all_data=$this->sConn->createCommand($sql)->queryAll();
  788. if(!$all_data){
  789. $this->redirect(Yii::app()->createUrl('zhiliao/check_excel'));
  790. }
  791. $repeat=array();
  792. $total=count($all_data);
  793. $data['total_page']=ceil($total/$pageSize);
  794. $data['name_group']=array_slice($all_data,$offset,$pageSize);
  795. $data['page']=$page;
  796. if(Yii::app()->request->isAjaxRequest){
  797. $result['status']=1;
  798. $result['data']=$data['name_group'];
  799. $result['total_page']=$data['total_page'];
  800. exit(json_encode($result));
  801. }else{
  802. $this->render('handle', $data);
  803. }
  804. }
  805. //根据名称加载重名学生
  806. public function actionShowrepeatstudent(){
  807. $name=Req::post('name');
  808. $fileName=array(
  809. 'student_name'=>'学生姓名',
  810. 'userno'=>'学号',
  811. 'student_card'=>'准考证号',
  812. 'school_student_card'=>'学校准考证号',
  813. 'zhixue_student_card'=>'智学网考证号',
  814. 'id_number'=>'身份证号',
  815. 'student_phone'=>'手机号'
  816. );
  817. //扩展字段
  818. $studentExtend=$this->schoolManager->getStudentExtend();
  819. if($studentExtend){
  820. foreach ($studentExtend as $key=> $value){
  821. $fileName[$key]=$value['field_mean'];
  822. }
  823. }
  824. //表格科目对应
  825. $letters = array('C','D','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');
  826. $allSubject=Yii::app()->params['subjectId'];
  827. unset($allSubject[3]);
  828. unset($allSubject[51]);
  829. unset($allSubject[20]);
  830. $ExcelToSubject=array();
  831. $subjectOrder=0;
  832. foreach ($allSubject as $key =>$val){
  833. $ExcelToSubject[$letters[$subjectOrder]]=$key;
  834. $subjectOrder++;
  835. }
  836. $classIds=array();
  837. $sql="select * from import_score_temp where check_field_value='".$name."' and ( student_id is null or student_id =0) and exam_type=1";
  838. $nameArr=array();
  839. $systemStudent=array();
  840. $numberToId=array();
  841. $excel_data = $this->sConn->createCommand($sql)->queryAll();
  842. if($excel_data){
  843. $topic_score=json_decode($excel_data[0]['score_data'],true);
  844. $check_field=$excel_data[0]['check_field'];
  845. $excel_html='<table class="table table-striped table-bordered table-hover dataTable no-footer DTTT_selectable">';
  846. $excel_html.='<tr>';
  847. $excel_html.='<th>序号</th>';
  848. $excel_html.='<th>姓名</th>';
  849. $excel_html.='<th>班级</th>';
  850. // $scoreArr=array_slice($topic_score,2);
  851. foreach($topic_score as $f=>$v){
  852. $excel_html.='<th>'.Yii::app()->params['subjectId'][$ExcelToSubject[$f]].'</th>';
  853. }
  854. $excel_html.='</tr>';
  855. $i=1;
  856. foreach($excel_data as $val){
  857. $topic_score=json_decode($val['score_data'],true);
  858. $numberToId[$i]=$val['id'];
  859. $excel_html.='<tr>';
  860. $excel_html.='<td>'.$i.'</td>';
  861. $excel_html.='<td>'.$val['check_field_value'].'(原'.$val['student_name'].')</td>';
  862. $excel_html.='<td>'.$val['class_name'].'</td>';
  863. foreach($topic_score as $v){
  864. $excel_html.='<td>'.$v.'</td>';
  865. }
  866. $excel_html.='</tr>';
  867. $i++;
  868. }
  869. $excel_html.='</table>';
  870. $ZlExam=new ZlExam();
  871. $exam_group_data=$ZlExam->getExamByExamGroupId($excel_data[0]['exam_group_id']);
  872. $classIds=array();
  873. $examIds=array();
  874. if($exam_group_data){
  875. foreach ($exam_group_data as $v){
  876. $classIds[]=$v['zl_class_id'];
  877. $examIds[]=$v['zl_exam_id'];
  878. }
  879. }
  880. $_allStudent=array();
  881. $check_field='realname';
  882. $sys_sql="SELECT sc.realname,sc.id_number,sc.class_id,sc.student_id,sc.is_outer,sc.id_number,c.class_name,s.semester_id,s.semester_name,s.school_year,s.end_time,sc.field_1,sc.field_2,sc.field_3,sc.field_4,sc.field_5 FROM `student_info` sc ";
  883. $sys_sql.="LEFT JOIN class c on sc.class_id=c.class_id ";
  884. $sys_sql.="LEFT JOIN semester s on s.semester_id=c.semester_id ";
  885. $sys_sql.="LEFT JOIN zl_student_exam_relation spr on sc.student_id = spr.zl_student_id ";
  886. $sys_sql.=" where `".$check_field."` = '".$name."' and spr.zl_exam_id in(".implode(',',$examIds).") and s.semester_id <>'' ";
  887. $sys_sql.="order by end_time desc ;";
  888. $_allStudent = $this->sConn->createCommand($sys_sql)->queryAll();
  889. $nameArr=array();
  890. $studentData=array();
  891. $businessData=array();
  892. $semester=array();
  893. $studentId=array();
  894. $html='';
  895. if($_allStudent){
  896. foreach ($_allStudent as $val){
  897. $val['serial_number']=0;
  898. $val['userno']=0;
  899. //班级信息
  900. $sql_class_relation="select * from student_class_relation where student_id='".$val['student_id']."' and status=0 ";
  901. $student_class_realtion=$this->sConn->createCommand($sql_class_relation)->queryRow();
  902. if($student_class_realtion){
  903. $val['serial_number']=$student_class_realtion['serial_number'];
  904. $val['userno']=$student_class_realtion['userno'];
  905. }else{
  906. continue;
  907. }
  908. //查询副号
  909. $sql_fuhao="select * from student_relation where find_in_set('".$val['student_id']."',relation_student_id)";
  910. $student_fuhao=$this->sConn->createCommand($sql_fuhao)->queryRow();
  911. $val['fuhao']=0;
  912. if($student_fuhao){
  913. if($val['student_id']!=$student_fuhao['master_student_id']){
  914. continue;
  915. }else{
  916. $fuhao_arr=explode(',',$student_fuhao['relation_student_id']);
  917. $val['fuhao']=count($fuhao_arr)-1;
  918. }
  919. }
  920. $studentData[$val['semester_id']][]=$val;
  921. $semester[$val['semester_id']]=$val['semester_name'];
  922. $studentId[]=$val['student_id'];
  923. }
  924. //查询business
  925. $criteria = new CDbCriteria();
  926. $b_student = array();
  927. $criteria->addInCondition('student_id',$studentId);
  928. $b_student_data = BusinessStudent::model()->findAll($criteria);
  929. if($b_student_data){
  930. foreach($b_student_data as $v)
  931. {
  932. $businessData[$v->student_id]=array(
  933. 'username'=>$v->username,
  934. 'student_card'=>$v->student_card,
  935. 'school_student_card'=>$v->school_student_card,
  936. 'zhixue_student_card'=>$v->zhixue_student_card,
  937. );
  938. }
  939. }
  940. $i=1;
  941. $currSemester = $this->schoolManager->getCurrSemester();
  942. $smid=$currSemester['semester_id'];
  943. foreach ($semester as $key=> $val){
  944. $semesterStatus='非当前学期';
  945. if($smid==$key){
  946. $semesterStatus='当前学期';
  947. }
  948. $html.='<div class="handel-term-list">';
  949. $html.='<div class="term-name fw"></div>';
  950. $html.='<div class="relative flex">';
  951. $html.='<img src="/images/prev-arrow.png" alt="" class="prev-arrow arrow-img pointer">';
  952. $html.='<div class="term-card-layout flex-one" >';
  953. $html.='<ul class="term-card-detail">';
  954. if(isset($studentData[$key])){
  955. // debug($studentData[$key]);
  956. foreach ($studentData[$key] as $item){
  957. $isZj='是';
  958. if($item['is_outer']==1){
  959. $isZj='否';
  960. }
  961. $html.='<li class="term-card-list" id="'.$item['student_id'].'" draggable="true" >';
  962. $html.='<div class="padding-layout">';
  963. $html.='<div class="card-lis-data flex">';
  964. $html.='<div class="card_select">';
  965. $html.='<select class="nToId"><option value="0">请选择序号</option>';
  966. foreach ($numberToId as $number=>$Id){
  967. $html.='<option value="'.$Id.'">'.$number.'</option>';
  968. }
  969. $html.='</select>';
  970. $html.='</div>';
  971. $html.='</div>';
  972. $html.='<div class="card-lis-data flex">';
  973. $html.='<span class="card-list-menu gray-font">姓名</span>';
  974. $html.='<span class="card-list-msg flex-one">'.$item['realname'].'</span>';
  975. $html.='</div>';
  976. $html.='<div class="card-lis-data flex">';
  977. $html.='<span class="card-list-menu gray-font">班级</span>';
  978. $html.='<span class="card-list-msg flex-one">'.$item['class_name'].'</span>';
  979. $html.='</div>';
  980. $html.='<div class="hide-list">';
  981. $html.='<div class="card-lis-data flex">';
  982. $html.='<span class="card-list-menu gray-font">学期</span>';
  983. $html.='<span class="card-list-msg flex-one">'.$val.'</span>';
  984. $html.='</div>';
  985. $html.='<div class="card-lis-data flex">';
  986. $html.='<span class="card-list-menu gray-font">学期状态</span>';
  987. $html.='<span class="card-list-msg flex-one">'.$semesterStatus.'</span>';
  988. $html.='</div>';
  989. $html.='<div class="card-lis-data flex">';
  990. $html.='<span class="card-list-menu gray-font">班级序号</span>';
  991. $html.='<span class="card-list-msg flex-one">'.$item['serial_number'].'</span>';
  992. $html.='</div>';
  993. $html.='<div class="card-lis-data flex">';
  994. $html.='<span class="card-list-menu gray-font">学号</span>';
  995. $html.='<span class="card-list-msg flex-one">'.$item['userno'].'</span>';
  996. $html.='</div>';
  997. $html.='<div class="card-lis-data flex">';
  998. $html.='<span class="card-list-menu gray-font">登录账号</span>';
  999. if(isset($businessData[$item['student_id']])){
  1000. $html.='<span class="card-list-msg flex-one">'.$businessData[$item['student_id']]['username'].'</span>';
  1001. }else{
  1002. $html.='<span class="card-list-msg flex-one"></span>';
  1003. }
  1004. $html.='</div>';
  1005. $html.='<div class="card-lis-data flex">';
  1006. $html.='<span class="card-list-menu gray-font">系统准考证号</span>';
  1007. if(isset($businessData[$item['student_id']])){
  1008. $html.='<span class="card-list-msg flex-one">'.$businessData[$item['student_id']]['student_card'].'</span>';
  1009. }else{
  1010. $html.='<span class="card-list-msg flex-one"></span>';
  1011. }
  1012. $html.='</div>';
  1013. $html.='<div class="card-lis-data flex">';
  1014. $html.='<span class="card-list-menu gray-font">学校准考证号</span>';
  1015. if(isset($businessData[$item['student_id']])){
  1016. $html.='<span class="card-list-msg flex-one">'.$businessData[$item['student_id']]['school_student_card'].'</span>';
  1017. }else{
  1018. $html.='<span class="card-list-msg flex-one"></span>';
  1019. }
  1020. $html.='</div>';
  1021. $html.='<div class="card-lis-data flex">';
  1022. $html.='<span class="card-list-menu gray-font">智学网考号</span>';
  1023. if(isset($businessData[$item['student_id']])){
  1024. $html.='<span class="card-list-msg flex-one">'.$businessData[$item['student_id']]['zhixue_student_card'].'</span>';
  1025. }else{
  1026. $html.='<span class="card-list-msg flex-one"></span>';
  1027. }
  1028. $html.='</div>';
  1029. $html.='<div class="card-lis-data flex">';
  1030. $html.='<span class="card-list-menu gray-font">身份证号</span>';
  1031. $html.='<span class="card-list-msg flex-one">'.$item['id_number'].'</span>';
  1032. $html.='</div>';
  1033. $html.='<div class="card-lis-data flex">';
  1034. $html.='<span class="card-list-menu gray-font">是否为在籍生</span>';
  1035. $html.='<span class="card-list-msg flex-one">'.$isZj.'</span>';
  1036. $html.='</div>';
  1037. $html.='<div class="card-lis-data flex">';
  1038. $html.='<span class="card-list-menu gray-font">历史考试成绩</span>';
  1039. $html.='<span rel="'.$item['student_id'].'" class="card-list-msg flex-one browse-history green-font">查看</span>';
  1040. $html.='</div>';
  1041. $html.='<div class="card-lis-data flex">';
  1042. $html.='<span class="card-list-menu gray-font">副号</span>';
  1043. $html.='<span rel="'.$item['student_id'].'" class="card-list-msg flex-one green-font pointer fuhao-lock">'.$item['fuhao'].'</span>';
  1044. $html.='</div>';
  1045. $html.='</div>';
  1046. $html.='<span class="toggle-opt-btn green-font pointer">展开</span>';
  1047. $html.='</div>';
  1048. $html.='</li>';
  1049. $i++;
  1050. }
  1051. }
  1052. $html.='</ul>';
  1053. $html.='</div>';
  1054. $html.='<img src="/images/next-arrow.png" alt="" class="next-arrow arrow-img pointer">';
  1055. $html.='</div>';
  1056. $html.='</div>';
  1057. }
  1058. }
  1059. }
  1060. $result['html']=$html;
  1061. $result['excel_html']=$excel_html;
  1062. $result['status']=1;
  1063. exit(json_encode($result));
  1064. }
  1065. //绑定学生id
  1066. public function actionBinding(){
  1067. $str=Req::post('str');
  1068. $result['status']=0;
  1069. if(!$str || !is_array($str)){
  1070. exit(json_encode($result));
  1071. }
  1072. $studentIds=array();
  1073. $tempIds=array();
  1074. foreach($str as $val){
  1075. @$nToId=explode('///',$val);
  1076. if(isset($nToId[0])){
  1077. if(in_array((string)$nToId[0],$studentIds,true)){
  1078. $result['msg']='不能学生重复选择';
  1079. exit(json_encode($result));
  1080. }else{
  1081. $studentIds[]=(string)$nToId[0];
  1082. }
  1083. }
  1084. if(isset($nToId[1])){
  1085. if(in_array((string)$nToId[1],$tempIds,true)){
  1086. $result['msg']='不能学生重复选择';
  1087. exit(json_encode($result));
  1088. }else{
  1089. $tempIds[]=(string)$nToId[1];
  1090. }
  1091. }
  1092. }
  1093. $updateSql=array();
  1094. foreach($str as $val){
  1095. @$nToId=explode('///',$val);
  1096. if(isset($nToId[0]) && isset($nToId[1])){
  1097. //判断学生id是否已关联过
  1098. $related=$this->sConn->createCommand("select id from import_score_temp where student_id='".$nToId[0]."' and exam_type=1 limit 1")->queryRow();
  1099. if($related){
  1100. $result['msg']='学生已经被关联,请重新检查';
  1101. exit(json_encode($result));
  1102. }
  1103. $updateSql[]="update import_score_temp set student_id='".$nToId[0]."',is_repeat=0 where id='".$nToId[1]."' and exam_type=1";
  1104. }
  1105. }
  1106. if($updateSql){
  1107. foreach($updateSql as $query){
  1108. $this->sConn->createCommand($query)->execute();
  1109. }
  1110. $result['status']=1;
  1111. }
  1112. exit(json_encode($result));
  1113. }
  1114. //处理不存在学生
  1115. public function actionHandle_existent(){
  1116. $fileName=array(
  1117. 'student_name'=>'学生姓名',
  1118. 'userno'=>'学号',
  1119. 'student_card'=>'准考证号',
  1120. 'school_student_card'=>'学校准考证号',
  1121. 'zhixue_student_card'=>'智学网考证号',
  1122. 'id_number'=>'身份证号',
  1123. 'student_phone'=>'手机号'
  1124. );
  1125. //扩展字段
  1126. $studentExtend=$this->schoolManager->getStudentExtend();
  1127. if($studentExtend){
  1128. foreach ($studentExtend as $key=> $value){
  1129. $fileName[$key]=$value['field_mean'];
  1130. }
  1131. }
  1132. //查询不存在的数据
  1133. $sql="select * from import_score_temp where is_repeat=0 and (student_id is null or student_id =0) and exam_type=1 ";
  1134. $all_data=$this->sConn->createCommand($sql)->queryAll();
  1135. if($all_data){
  1136. $data['check_field']=$all_data[0]['check_field'];
  1137. }else{
  1138. $data['check_field']='';
  1139. }
  1140. $data['list']=$all_data;
  1141. $data['fieldName']=$fileName;
  1142. $this->render('handle_existent',$data);
  1143. }
  1144. //修改不存在的学生数据
  1145. public function actionChange_value(){
  1146. $id=Req::post('id');
  1147. $value=Req::post('value');
  1148. $result['status']=0;
  1149. if(!$id || !$value){
  1150. $result['msg']='参数不正确';
  1151. exit(json_encode($result));
  1152. }
  1153. $sql="select student_name,class_name,check_field_value,score_data,exam_group_id,check_field,renew,student_id,is_repeat from import_score_temp where id='".$id."' limit 1";
  1154. $data=$this->sConn->createCommand($sql)->queryRow();
  1155. if(!$data){
  1156. $result['msg']='id不正确';
  1157. exit(json_encode($result));
  1158. }
  1159. $check_field=$data['check_field'];
  1160. //excel中是否有重复数据
  1161. $excelCheck="select id from import_score_temp where check_field_value='".$value."' and exam_type=1 ";
  1162. $excelCheckData=$this->sConn->createCommand($excelCheck)->queryRow();
  1163. if($excelCheckData){
  1164. $result['msg']='excel中已存在相同记录';
  1165. if($check_field=='student_name'){
  1166. $result['status']=1;
  1167. $updateSql="update import_score_temp set `is_repeat`=1,check_field_value='{$value}' where (id={$id} or check_field_value='{$value}') and exam_type=1";
  1168. $this->sConn->createCommand($updateSql)->execute();
  1169. $result['msg']='excel中已存在相同记录,请返回检测页面,继续处理重名';
  1170. }
  1171. exit(json_encode($result));
  1172. }
  1173. //系统中是否有数据
  1174. $exam_group_id=$data['exam_group_id'];
  1175. $ZlExam=new ZlExam();
  1176. $exam_group_data=$ZlExam->getExamByExamGroupId($exam_group_id);
  1177. $classIds=array();
  1178. $examIds=array();
  1179. if($exam_group_data){
  1180. foreach ($exam_group_data as $v){
  1181. $classIds[]=$v['zl_class_id'];
  1182. $examIds[]=$v['zl_exam_id'];
  1183. }
  1184. }
  1185. if($exam_group_data){
  1186. $student_info=array();
  1187. $sql="select si.student_id,si.realname from student_info si join zl_student_exam_relation spr on si.student_id = spr.zl_student_id where realname ='".$value."' and zl_exam_id in(".implode(',',$examIds).")";
  1188. $student_info=$this->sConn->createCommand($sql)->queryAll();
  1189. if(!$student_info){
  1190. $result['msg']='系统中不存在,或学生没有参加该次考试';
  1191. exit(json_encode($result));
  1192. }elseif(count($student_info)>1){
  1193. $updateSql="update import_score_temp set `is_repeat`=1,check_field_value='{$value}' where id={$id}";
  1194. $this->sConn->createCommand($updateSql)->execute();
  1195. $result['msg']='系统中存在多个该学生数据,请返回检测页面,继续处理重名';
  1196. exit(json_encode($result));
  1197. }else{
  1198. $result['status']=1;
  1199. $studentId=$student_info[0]['student_id'];
  1200. //查询是否参加考试
  1201. $StudentPaperRelation=$this->sConn->createCommand("select zl_student_id from `zl_student_exam_relation` where zl_student_id='".$studentId."' and zl_exam_id in(".implode(',',$examIds).")")->queryRow();
  1202. if(!$StudentPaperRelation){
  1203. $result['status']=1;
  1204. $result['msg']='学生没有参加本次考试';
  1205. exit(json_encode($result));
  1206. }
  1207. //判断学生id是否已关联过
  1208. $related=$this->sConn->createCommand("select id from import_score_temp where student_id='".$studentId."' and exam_type=1 limit 1")->queryRow();
  1209. if($related){
  1210. $result['msg']='学生已经被关联,请重新检查';
  1211. exit(json_encode($result));
  1212. }
  1213. $updateSql="update import_score_temp set student_id='{$studentId}',check_field_value='{$value}',is_repeat=0 where id={$id}";
  1214. $this->sConn->createCommand($updateSql)->execute();
  1215. exit(json_encode($result));
  1216. }
  1217. }else{
  1218. $result['msg']='考试数据有误';
  1219. exit(json_encode($result));
  1220. }
  1221. }
  1222. //处理完毕,执行成绩导入
  1223. public function actionUpdate_score(){
  1224. $result['status']=0;
  1225. $sql="select * from import_score_temp where student_id is not null and is_repeat=0 and exam_type=1";
  1226. $all_data=$this->sConn->createCommand($sql)->queryAll();
  1227. if(!$all_data){
  1228. $result['msg']='没有发现可导入学生成绩数据';
  1229. exit(json_encode($result));
  1230. }
  1231. $exam_group_id=$all_data[0]['exam_group_id'];
  1232. $ZlExam=new ZlExam();
  1233. $exam_group_data=$ZlExam->getExamByExamGroupId($exam_group_id);
  1234. if(!$exam_group_data){
  1235. $result['msg']='考试ID不正确,请从考试列表点击上传成绩';
  1236. exit(json_encode($result));
  1237. }
  1238. $classIds=array();
  1239. if($exam_group_data){
  1240. foreach ($exam_group_data as $v){
  1241. $classIds[]=$v['zl_class_id'];
  1242. $examIds[]=$v['zl_exam_id'];
  1243. }
  1244. }
  1245. $letters = array('C','D','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');
  1246. $allSubject=Yii::app()->params['subjectId'];
  1247. unset($allSubject[3]);
  1248. unset($allSubject[51]);
  1249. unset($allSubject[20]);
  1250. $ExcelToSubject=array();
  1251. $subjectOrder=0;
  1252. foreach ($allSubject as $key =>$val){
  1253. $ExcelToSubject[$letters[$subjectOrder]]=$key;
  1254. $subjectOrder++;
  1255. }
  1256. // $tpl_data=json_decode($exam_group_data[0]['tpl_data'],true);
  1257. $sql='INSERT INTO `zl_student_exam_rs` (`id`,`zl_student_id`,`zl_exam_group_id`,`zl_exam_id`,`zl_subject_id`,`zl_scoring`)VALUE ';
  1258. $deleteSql=array();
  1259. $error=array();
  1260. $studentIds=array(); //用于检测重复
  1261. $time=time();
  1262. foreach($all_data as $val){
  1263. $StudentPaperRelation=$this->sConn->createCommand("select zl_student_id,zl_exam_id from `zl_student_exam_relation` where zl_student_id='".$val['student_id']."' and zl_exam_id in(".implode(',',$examIds).")")->queryRow();
  1264. if(!$StudentPaperRelation){
  1265. $error[]='学生没有参加本次考试 :'.$val['student_name'];
  1266. continue;
  1267. }
  1268. $ZlExamId=$StudentPaperRelation['zl_exam_id'];
  1269. $deleteSql[]="delete from `zl_student_exam_rs` where zl_student_id='".$val['student_id']."' and zl_exam_group_id='".$exam_group_id."' ";
  1270. $topicScoreData=json_decode($val['score_data'],true);
  1271. $uuidArr=array();
  1272. $uuidArr=getBatchUuid($this->schoolId,count($topicScoreData));
  1273. foreach($topicScoreData as $key=> $ts){
  1274. if(isset($ts)== true){
  1275. if(!is_numeric($ts) || floatval($ts)<0){
  1276. continue;
  1277. }
  1278. $ts=(float)$ts;
  1279. if(!$ts){
  1280. $ts=0;
  1281. }
  1282. // $uuid = $this->sConn->createCommand("select RIGHT(UUID_SHORT(), 20)")->queryAll();
  1283. // $uuid = current(current($uuid));
  1284. //$uuid=getUniqueId($this->schoolId);
  1285. $uuid=current($uuidArr);
  1286. unset($uuidArr[$uuid]);
  1287. $valueSql[]=' ('.$uuid.','.$val['student_id'].','.$exam_group_id.','.$ZlExamId.','.$ExcelToSubject[$key].','.$ts.') ';
  1288. }
  1289. }
  1290. }
  1291. if($deleteSql && $valueSql){
  1292. $transaction = $this->sConn->beginTransaction();
  1293. try{
  1294. if($deleteSql){
  1295. foreach ($deleteSql as $dquery){
  1296. $this->sConn->createCommand($dquery)->execute();
  1297. }
  1298. if($valueSql){
  1299. if(count($valueSql)>100){
  1300. $valueSql = array_chunk($valueSql, 10);
  1301. foreach($valueSql as $value){
  1302. $chunkSql=$sql;
  1303. $chunkSql.=implode(',',$value);
  1304. $this->sConn->createCommand($chunkSql)->execute();
  1305. }
  1306. }else{
  1307. $sql.=implode(',',$valueSql);
  1308. $this->sConn->createCommand($sql)->execute();
  1309. }
  1310. }
  1311. //清理导入临时数据
  1312. // $delSql="truncate table import_score_temp;";
  1313. $delSql="delete from import_score_temp where exam_type=1;";
  1314. $this->sConn->createCommand($delSql)->execute();
  1315. $transaction->commit();
  1316. $result['status']=1;
  1317. if($error){
  1318. // Yii::app()->jump->error('导入成功,有部分学生成绩没有导入:'.implode(',',$error));
  1319. $result['msg']=implode('<br>',$error);
  1320. }else{
  1321. $result['msg']='导入成功';
  1322. }
  1323. exit(json_encode($result));
  1324. }
  1325. }catch (Exception $e) {
  1326. //如果操作失败, 数据回滚
  1327. $transaction->rollback();
  1328. // Yii::app()->jump->error('成绩导入失败,请检查后重新');
  1329. $result['msg']='成绩导入失败,请检查后重新导入';
  1330. exit(json_encode($result));
  1331. }
  1332. }else{
  1333. //没有需要重新导入的数据,清理导入临时数据
  1334. $delSql="delete from import_score_temp where exam_type=1;";
  1335. $this->sConn->createCommand($delSql)->execute();
  1336. $result['status']=1;
  1337. exit(json_encode($result));
  1338. }
  1339. }
  1340. /*切换记录状态*/
  1341. public function actionChangeStatus(){
  1342. $display=intval(Req::post('display'));
  1343. $examGroupId=Req::post('cid');
  1344. $result=array(
  1345. 'status'=>0
  1346. );
  1347. if(!$examGroupId || !in_array($display,array(0,1))){
  1348. exit(json_encode($result));
  1349. }
  1350. $ZlExamGroup=new ZlExamGroup();
  1351. $data=array(
  1352. 'zl_is_display'=>$display
  1353. );
  1354. $Condition=array(
  1355. 'zl_exam_group_id'=>$examGroupId
  1356. );
  1357. $res=$ZlExamGroup->updateByCondition($data,$Condition);
  1358. if($res){
  1359. $result['status']=1;
  1360. }
  1361. exit(json_encode($result));
  1362. }
  1363. public function actionChange(){
  1364. ini_set("memory_limit","200M");
  1365. Url::clean();
  1366. $sname = Req::get("sname");
  1367. $cid = Req::get("cid");
  1368. $eid = Req::get("eid");
  1369. $classInfo = ClassModel::model()->findByPk($cid);
  1370. if (empty($classInfo)) {
  1371. Yii::app()->jump->error('未找到班级!');
  1372. }
  1373. $ZlExam=new ZlExam();
  1374. $examInfo = $ZlExam->getExamByExamId($eid);
  1375. if (empty($examInfo)) {
  1376. Yii::app()->jump->error('未找到考试!');
  1377. }
  1378. $ZlexmGroup=new ZlExamGroup();
  1379. $examInfo=$ZlexmGroup->getExamGroupByExamGroupId($examInfo['zl_exam_group_id']);
  1380. $ZlStudent=new ZlStudentExamRelation();
  1381. $result = array();
  1382. $relateStudent = $ZlStudent->getStudentByExamId($eid);
  1383. // 获取学生姓名
  1384. $_student_id = array();
  1385. foreach($relateStudent as $v)
  1386. {
  1387. $_student_id[$v['zl_student_id']] = $v['zl_student_id'];
  1388. }
  1389. $studentNames = array();
  1390. $criteria = new CDbCriteria();
  1391. $criteria->addInCondition('student_id',$_student_id);
  1392. $studentArray = SStudentInfo::model()->findAll($criteria);
  1393. if (!empty($studentArray)) {
  1394. foreach ($studentArray as $student) {
  1395. $studentNames[$student->student_id] = $student->realname;
  1396. }
  1397. }
  1398. //debug($examInfo);
  1399. foreach ($relateStudent as $key=>$val) {
  1400. //查询学生身份证号
  1401. $studentInfo=SStudentInfo::model()->find('student_id=:s_id',array('s_id'=>$val['zl_student_id']));
  1402. if($studentInfo){
  1403. $result[$key]['id_number'] = $studentInfo->id_number;
  1404. }else{
  1405. $result[$key]['id_number'] = '';
  1406. }
  1407. if (empty($sname)) {
  1408. $result[$key]['clazzName'] = $classInfo->class_name;
  1409. $result[$key]['paperName'] = $examInfo['zl_exam_name'];
  1410. $result[$key]['studentCode'] = $val['zl_student_id'];
  1411. $result[$key]['studentName'] = isset($studentNames[$val['zl_student_id']]) ? $studentNames[$val['zl_student_id']] : null;
  1412. $result[$key]['is_complete'] = !empty($val['zl_subject_id'])?1:0;
  1413. } else {
  1414. if ($sname == $studentNames[$val['zl_student_id']]) {
  1415. $result[$key]['clazzName'] = $classInfo->class_name;
  1416. $result[$key]['paperName'] = $examInfo['zl_exam_name'];
  1417. $result[$key]['studentCode'] = $val['zl_student_id'];
  1418. $result[$key]['studentName'] = $studentNames[$val['zl_student_id']];
  1419. $result[$key]['is_complete'] = !empty($val['zl_subject_id'])?1:0;
  1420. }else{
  1421. unset($result[$key]);
  1422. }
  1423. unset($relateStudent[$key]);
  1424. }
  1425. }
  1426. //}
  1427. $no_paper_student = array();
  1428. $paper_student_array = array();
  1429. $c_paper_student_array = array();
  1430. $class_student_info_data = array();
  1431. $_student_ids = array();
  1432. $_student_id_names = array();
  1433. $class_student_data = $this->schoolManager->getClassStudentByClassId($cid); //student_class_relation
  1434. if($class_student_data)
  1435. {
  1436. foreach($class_student_data as $v)
  1437. {
  1438. $_student_ids[$v['student_id']] = $v['student_id'];
  1439. }
  1440. $criteria = new CDbCriteria();
  1441. $criteria->addInCondition('student_id',$_student_ids);
  1442. $studentArray = SStudentInfo::model()->findAll($criteria);
  1443. if (!empty($studentArray)) {
  1444. foreach ($studentArray as $student) {
  1445. $_student_id_names[$student->student_id] = $student->realname;
  1446. }
  1447. }
  1448. }
  1449. ///$class_student_info_data = $this->schoolManager->getClassStudentInfoByClassId($cid); //student_info
  1450. if ($class_student_data) {
  1451. foreach($class_student_data as $v)
  1452. {
  1453. if(!isset($b_student_arr[$v['student_id']]))
  1454. {
  1455. if ($paper_student_array)
  1456. {
  1457. if(isset($paper_student_array[$v['student_id']])){
  1458. $no_paper_student[$v['student_id']] = array(
  1459. 'student_id' => $v['student_id'],
  1460. 'realname' => isset($class_student_info_array[$v['student_id']]) ?$class_student_info_array[$v['student_id']]:'',
  1461. );
  1462. }
  1463. }
  1464. if($c_paper_student_array )
  1465. {
  1466. if(!isset($c_paper_student_array[$v['student_id']]) )
  1467. {
  1468. $no_paper_student[$v['student_id']] = array(
  1469. 'student_id' => $v['student_id'],
  1470. 'realname' => isset($_student_id_names[$v['student_id']]) ?$_student_id_names[$v['student_id']]:'',
  1471. );
  1472. }
  1473. }else
  1474. {
  1475. $no_paper_student[$v['student_id']] = array(
  1476. 'student_id' => $v['student_id'],
  1477. 'realname' => isset($_student_id_names[$v['student_id']]) ?$_student_id_names[$v['student_id']]:'',
  1478. );
  1479. }
  1480. }
  1481. }
  1482. }
  1483. $printType = '2';
  1484. $data = array();
  1485. if(isset($isUnderLine)){
  1486. $data['under_line']=$isUnderLine;
  1487. }
  1488. $data['no_paper_student'] = $no_paper_student;
  1489. $data['result'] = $result;
  1490. $data["sname"] = $sname;
  1491. $data['exam_id'] = $eid;
  1492. $data['class_id'] = $cid;
  1493. $subject_exam_data = $this->schoolManager->getxuekeStatus($this->semesterId);
  1494. $data["subject"] = $subject_exam_data;
  1495. $data['className'] = $classInfo->class_name;
  1496. $data['paperName'] = $examInfo['zl_exam_name'];
  1497. $data['examInfo'] = $examInfo;
  1498. $data['printType'] = $printType;
  1499. $this->render('change',$data);
  1500. }
  1501. //不推送成绩设置列表
  1502. public function actionBlackList(){
  1503. $name = Req::get("name");
  1504. $classId = Req::get("class_id");
  1505. $grade = Req::get("grade");
  1506. $page = intval(Req::get("page"));
  1507. $subjectId=$this->subjectId;
  1508. $query=array();
  1509. if(!$page) $page=1;
  1510. $query['page']=$page;
  1511. $where=array();
  1512. if(in_array($subjectId,$this->mathSubjectId)){
  1513. $where[]=" subject_id in(".implode(',',$this->mathSubjectId).") and semester_id='".$this->semesterId."'";
  1514. }else{
  1515. $where[]=" subject_id ='".$subjectId."' and semester_id='".$this->semesterId."'";
  1516. }
  1517. if($name){
  1518. $where[]=" name like '%".$name."%'";
  1519. $query['name']=$name;
  1520. }
  1521. if($classId){
  1522. $where[]=" class_id = '".$classId."'";
  1523. $query['class_id']=$classId;
  1524. }
  1525. if($grade){
  1526. $where[]=" grade = '".$grade."'";
  1527. $query['grade']=$grade;
  1528. }
  1529. $pageLimit=10;
  1530. $data=Blacklist::model()->getExamList($where,$page,$pageLimit);
  1531. $ExamModel=new SExam();
  1532. if($data['dataList']){
  1533. foreach ($data['dataList'] as $key =>$val){
  1534. $data['dataList'][$key]['subject']=Yii::app()->params['subjectId'][$val['subject_id']];
  1535. //判断成绩是否生成
  1536. $exam=$ExamModel->getDetailByExamId($val['exam_id']);
  1537. if($exam['status']==1){
  1538. $data['dataList'][$key]['status']='是';
  1539. }else{
  1540. $data['dataList'][$key]['status']='否';
  1541. }
  1542. }
  1543. }
  1544. $data['query']=$query;
  1545. $data['subject']=$subjectId;
  1546. $data['name'] = $name?$name:"";
  1547. $data['grade'] = $grade?$grade:0;
  1548. $data['classId'] = $classId?$classId:'';
  1549. // debug($data);
  1550. $this->render('blacklist',$data);
  1551. }
  1552. //加载考试
  1553. public function actionAjaxSearchExam(){
  1554. $grade=Req::post('grade');
  1555. $class=Req::post('class');
  1556. $keyword=Req::post('keyword');
  1557. $page=Req::post('page');
  1558. if(!$page) $page=1;
  1559. $pageLimit=10;
  1560. $condition=array();
  1561. $subject=$this->subjectId;
  1562. $condition[]="e.semester_id='".$this->semesterId."'";
  1563. if($subject==3){
  1564. $condition[]='e.subject_id in ('.implode(',',$this->mathSubjectId).')';
  1565. }else{
  1566. $condition[]="e.subject_id ='".$subject."'";
  1567. }
  1568. if($grade){
  1569. $condition[]="c.grade='".$grade."'";
  1570. }
  1571. if($class){
  1572. $condition[]="c.class_id='".$class."'";
  1573. }
  1574. if($keyword){
  1575. $condition[]="e.name like '%".$keyword."%'";
  1576. }
  1577. $notInExamIds=array();
  1578. if(in_array($subject,$this->mathSubjectId)){
  1579. $blacklist=$this->sConn->createCommand("select exam_id from blacklist where subject_id in(".implode(',',$this->mathSubjectId).") and semester_id='".$this->semesterId."'")->queryAll();
  1580. }else{
  1581. $blacklist=$this->sConn->createCommand("select exam_id from blacklist where subject_id='".$subject."' and semester_id='".$this->semesterId."'")->queryAll();
  1582. }
  1583. if($blacklist){
  1584. foreach ($blacklist as $value){
  1585. $notInExamIds[]=$value['exam_id'];
  1586. }
  1587. }
  1588. if($notInExamIds){
  1589. $condition[]="e.exam_id not in(".implode(',',$notInExamIds).")";
  1590. }
  1591. $sqlCount="SELECT count(*) as count FROM `exam` e ";
  1592. $sqlCount.="join class c on c.class_id=e.class_id ";
  1593. if($condition){
  1594. $sqlCount.=" where ".implode(' and ',$condition);
  1595. }
  1596. $countData=$this->sConn->createCommand($sqlCount)->queryRow();
  1597. $pages=array(
  1598. 'total'=>$countData['count'],
  1599. 'totalPage'=>ceil($countData['count']/$pageLimit),
  1600. 'page'=>$page,
  1601. );
  1602. $offset=($page-1)*$pageLimit;
  1603. $sql="SELECT e.exam_id,e.name,c.grade,e.tpl_data,e.`status`,c.class_id,e.type,c.class_type,c.class_name,e.create_time FROM `exam` e ";
  1604. $sql.="join class c on c.class_id=e.class_id ";
  1605. if($condition){
  1606. $sql.=" where ".implode(' and ',$condition);
  1607. }
  1608. $sql.=" order by e.create_time desc limit {$offset},{$pageLimit}";
  1609. $classArr=array(
  1610. 1=>'行政班',
  1611. 2=>'教学班'
  1612. );
  1613. //1:周考2:单元考3:月考4:联考5:期中6:期末7:高考模拟8:冲刺
  1614. $typeArr=array(
  1615. 1=>'周考',
  1616. 2=>'单元考',
  1617. 3=>'月考',
  1618. 4=>'联考',
  1619. 5=>'期中',
  1620. 6=>'期末',
  1621. 7=>'高考模拟',
  1622. 8=>'冲刺',
  1623. 9=>'测验'
  1624. );
  1625. $list = $this->sConn->createCommand($sql)->queryAll();
  1626. if($list){
  1627. foreach ($list as $key=>$val){
  1628. $list[$key]['class_type']=$classArr[$val['class_type']];
  1629. if(isset($typeArr[$val['type']])){
  1630. $list[$key]['type']=$typeArr[$val['type']];
  1631. }
  1632. $list[$key]['subject_name']=Yii::app()->params['subjectId'][$this->subjectId];
  1633. $list[$key]['create_date']=date('Y-m-d',$val['create_time']);
  1634. $list[$key]['exam_date']='';
  1635. if($val['tpl_data']){
  1636. $tpl_data=json_decode($val['tpl_data'],true);
  1637. if(isset($tpl_data['examDate'])){
  1638. $list[$key]['exam_date']=$tpl_data['examDate'];
  1639. }
  1640. }
  1641. if($val['status']==1){
  1642. $list[$key]['status_msg']='是';
  1643. }else{
  1644. $list[$key]['status_msg']='否';
  1645. }
  1646. switch ($val['grade']){
  1647. case 1:
  1648. $list[$key]['grade']='高一';
  1649. break;
  1650. case 2:
  1651. $list[$key]['grade']='高二';
  1652. break;
  1653. case 3:
  1654. $list[$key]['grade']='高三';
  1655. break;
  1656. default:
  1657. $list[$key]['grade']='高一';
  1658. }
  1659. }
  1660. }
  1661. $result['status']=1;
  1662. $result['list']=$list;
  1663. $result['pages']=$pages;
  1664. exit(json_encode($result));
  1665. }
  1666. //添加黑名单
  1667. public function actionAddBlacklist(){
  1668. $examIds=Req::post('examIds');
  1669. $result['status']=0;
  1670. if(!$examIds){
  1671. exit(json_encode($result));
  1672. }
  1673. $delSql="delete from blacklist where exam_id in(".implode(',',$examIds).")";
  1674. $insertSql="insert into blacklist(`exam_group_id`,`exam_id`,`name`,`type`,`subject_id`,`semester_id`,`class_id`,`class_name`,`class_type`,`grade`,`exam_create_time`,`exam_date`,`dateline`) values ";
  1675. $insertData=array();
  1676. $ExamModel=new SExam();
  1677. foreach ($examIds as $val){
  1678. $ExamInfo=$ExamModel->getDetailByExamId($val);
  1679. $classInfo = ClassModel::model()->findByPk($ExamInfo['class_id']);
  1680. $tpl_data=json_decode($ExamInfo['tpl_data'],true);
  1681. $insertData[]="('".$ExamInfo['exam_group_id']."','".$val."','".$ExamInfo['name']."','".$ExamInfo['type']."','".$ExamInfo['subject_id']."','".$this->semesterId."','".$ExamInfo['class_id']."','".$classInfo->class_name."','".$classInfo->class_type."','".$classInfo->grade."','".$ExamInfo['create_time']."','".$tpl_data['examDate']."','".time()."')";
  1682. }
  1683. if($insertData){
  1684. $transcation = $this->sConn->beginTransaction();
  1685. try {
  1686. $insertSql.=implode(',',$insertData);
  1687. $this->sConn->createCommand($delSql)->execute();
  1688. $this->sConn->createCommand($insertSql)->execute();
  1689. $transcation->commit();
  1690. $result['status']=1;
  1691. }catch (Exception $e){
  1692. $transcation->rollback();
  1693. }
  1694. }
  1695. exit(json_encode($result));
  1696. }
  1697. //删除黑名单
  1698. public function actionDelBlacklist(){
  1699. $examId=Req::get('exam_id');
  1700. if(!$examId || !is_numeric($examId)){
  1701. Yii::app()->jump->error('参数异常!');
  1702. }
  1703. $url=$_SERVER['HTTP_REFERER'];
  1704. if($this->sConn->createCommand("delete from blacklist where exam_id = '".$examId."'")->execute()){
  1705. $arr=array(
  1706. 'schoolId' => $this->schoolId,
  1707. 'examIds' =>array($examId)
  1708. );
  1709. sendDataToKafka('zsyte-marking-finished-notify-parent',$arr);
  1710. // $send_json=json_encode($arr);
  1711. // $stompconn = new Stomp(Yii::app()->params["activeMq"]["server"]);
  1712. // $stompconn->send("zsyte.markingFinishedNotifyParent", $send_json);
  1713. unset($stompconn);
  1714. $this->redirect($url);
  1715. }
  1716. }
  1717. //下载excel
  1718. public function actionDownloadExcel(){
  1719. $rs = $this->schoolManager->getClasses('ALL',array('class_id desc'));
  1720. $objPHPExcel = new PHPExcel();
  1721. $objPHPExcel->getProperties()->setCreator("ctos")
  1722. ->setLastModifiedBy("ctos")
  1723. ->setTitle("班级信息")
  1724. ->setSubject("班级信息")
  1725. ->setDescription("班级信息")
  1726. ->setKeywords("excel")
  1727. ->setCategory("result file");
  1728. $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(20);
  1729. $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(30);
  1730. $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(10);
  1731. $letters = array('C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
  1732. $allSubject=Yii::app()->params['subjectId'];
  1733. unset($allSubject[3]);
  1734. unset($allSubject[51]);
  1735. unset($allSubject[20]);
  1736. $objPHPExcel->setActiveSheetIndex(0)
  1737. ->setCellValue('A1', '姓名(必填)')
  1738. ->setCellValue('B1', '班级(当前学期唯一)');
  1739. $i=0;
  1740. foreach ($allSubject as $key =>$val){
  1741. $column=$letters[$i].'1';
  1742. $objPHPExcel->getActiveSheet(0)->setCellValue($column,$val);
  1743. $i++;
  1744. }
  1745. // $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
  1746. $i = 2;
  1747. $objPHPExcel->getActiveSheet(0)->setCellValue('A' . $i, '小李1');
  1748. $objPHPExcel->getActiveSheet(0)->setCellValue('B' . $i, '高一一班');
  1749. $subjectOrder=0;
  1750. foreach ($allSubject as $key =>$val){
  1751. $column=$letters[$subjectOrder].$i;
  1752. $subjectOrder++;
  1753. $objPHPExcel->getActiveSheet(0)->setCellValue($column, '');
  1754. }
  1755. $objPHPExcel->getActiveSheet()->setTitle('知了家校导入成绩');
  1756. $objPHPExcel->setActiveSheetIndex(0);
  1757. ob_end_clean(); // Added by me
  1758. header("Accept-Ranges:bytes");
  1759. header('Content-Type:application/vnd.ms-excel');
  1760. header("Content-type:application/vnd.ms-excel;charset=UTF-8");
  1761. header('Content-Disposition:attachment;filename="知了家校导入成绩.xls"');
  1762. header('Cache-Control:max-age=0');
  1763. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  1764. $objWriter->save('php://output');
  1765. exit;
  1766. }
  1767. //成绩报告设置
  1768. public function actionReportsetting(){
  1769. $data = array();
  1770. $this->render('reportsetting',$data);
  1771. }
  1772. //获取成绩报告设置
  1773. public function actionAjaxGetReportSetting(){
  1774. $data = array();
  1775. $error = array();
  1776. $zl_model = new BusinessZl_report_setting();
  1777. $setting_data = $zl_model->getReportSetting($this->schoolId);
  1778. if($setting_data){
  1779. $data['class_average'] = $setting_data['class_average'];
  1780. $data['grade_average'] = $setting_data['grade_average'];
  1781. $data['class_rank'] = $setting_data['class_rank'];
  1782. $data['grade_rank'] = $setting_data['grade_rank'];
  1783. $data['level_replace_score'] = $setting_data['level_replace_score'];
  1784. if($setting_data['score_level_setting']){
  1785. $data['score_level_setting'] = json_decode($setting_data['score_level_setting'],true);
  1786. }else{
  1787. $data['score_level_setting']['A']['min_score'] = 90;
  1788. $data['score_level_setting']['A']['max_score'] = 100;
  1789. $data['score_level_setting']['B']['min_score'] = 70;
  1790. $data['score_level_setting']['B']['max_score'] = 89;
  1791. $data['score_level_setting']['C']['min_score'] = 60;
  1792. $data['score_level_setting']['C']['max_score'] = 69;
  1793. $data['score_level_setting']['D']['min_score'] = 40;
  1794. $data['score_level_setting']['D']['max_score'] = 59;
  1795. $data['score_level_setting']['E']['min_score'] = 0;
  1796. $data['score_level_setting']['E']['max_score'] = 39;
  1797. }
  1798. }else{
  1799. $data['class_average'] = 1;
  1800. $data['grade_average'] = 1;
  1801. $data['class_rank'] = 1;
  1802. $data['grade_rank'] = 1;
  1803. $data['level_replace_score'] = 0;
  1804. $data['score_level_setting']['A']['min_score'] = 90;
  1805. $data['score_level_setting']['A']['max_score'] = 100;
  1806. $data['score_level_setting']['B']['min_score'] = 70;
  1807. $data['score_level_setting']['B']['max_score'] = 89;
  1808. $data['score_level_setting']['C']['min_score'] = 60;
  1809. $data['score_level_setting']['C']['max_score'] = 69;
  1810. $data['score_level_setting']['D']['min_score'] = 40;
  1811. $data['score_level_setting']['D']['max_score'] = 59;
  1812. $data['score_level_setting']['E']['min_score'] = 0;
  1813. $data['score_level_setting']['E']['max_score'] = 39;
  1814. }
  1815. if($error){
  1816. echo json_encode(array("status"=>0,"error"=>implode("<br>",$error)));exit;
  1817. }else{
  1818. echo json_encode(array("status"=>1,"data"=>$data));exit;
  1819. }
  1820. }
  1821. //保存成绩报告设置
  1822. public function actionAjaxSaveReportSetting(){
  1823. $error = array();
  1824. $insert_data = array();
  1825. $class_average = (int)Req::post('class_average');
  1826. $grade_average = (int)Req::post('grade_average');
  1827. $class_rank = (int)Req::post('class_rank');
  1828. $grade_rank = (int)Req::post('grade_rank');
  1829. $level_replace_score = (int)Req::post('level_replace_score');
  1830. $setting_data = Req::post('setting_data');
  1831. if($level_replace_score == 1 && !$setting_data){
  1832. $error[] = "分数等级不能为空";
  1833. }
  1834. if(!$error){
  1835. $insert_data["class_average"] = $class_average;
  1836. $insert_data["grade_average"] = $grade_average;
  1837. $insert_data["class_rank"] = $class_rank;
  1838. $insert_data["grade_rank"] = $grade_rank;
  1839. $insert_data["level_replace_score"] = $level_replace_score;
  1840. $insert_data["score_level_setting"] = $setting_data?htmlspecialchars_decode($setting_data):"";
  1841. $zl_model = new BusinessZl_report_setting();
  1842. $status= $zl_model->saveReportSetting($this->schoolId,$insert_data);
  1843. if(!$status){
  1844. $error[] = "更新失败";
  1845. }
  1846. }
  1847. if($error){
  1848. echo json_encode(array("status"=>0,"error"=>implode(",",$error)));exit;
  1849. }else{
  1850. echo json_encode(array("status"=>1));exit;
  1851. }
  1852. }
  1853. //未付费用户权限设置
  1854. public function actionUnpaidUserSetting(){
  1855. $unpaidModel=new UnpaidUserSetting();
  1856. $formData=getAttribute($unpaidModel->find('school_id=:school_id',array(':school_id'=>$this->schoolId)));
  1857. if (Yii::app()->request->getIsPostRequest()){
  1858. $parent_report=(int)Req::post('parent_report');
  1859. $parent_exam_notify=(int)Req::post('parent_exam_notify');
  1860. $student_report=(int)Req::post('student_report');
  1861. $student_knowledge_bill=(int)Req::post('student_knowledge_bill');
  1862. if($parent_report==$formData['parent_report'] && $parent_exam_notify==$formData['parent_exam_notify'] && $student_report==$formData['student_report'] && $student_knowledge_bill==$formData['student_knowledge_bill']){
  1863. // Yii::app()->jump->error('保存成功');
  1864. }
  1865. $insertData=array(
  1866. 'school_id'=>$this->schoolId,
  1867. 'parent_report'=>$parent_report,
  1868. 'parent_exam_notify'=>$parent_exam_notify,
  1869. 'student_report'=>$student_report,
  1870. 'student_knowledge_bill'=>$student_knowledge_bill
  1871. );
  1872. if($unpaidModel->saveReportSetting($insertData)){
  1873. Yii::app()->unpaid_user_setting->hmset('zhiliao:unpaid_user_setting:'.$this->schoolId,$insertData);
  1874. Yii::app()->jump->error('保存成功');
  1875. }else{
  1876. Yii::app()->jump->error('保存失败');
  1877. }
  1878. }
  1879. $this->render('unpaid',$formData);
  1880. }
  1881. }