RecordController.php 153 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646
  1. <?php
  2. class RecordController extends Controller{
  3. public function actionAddAct(){
  4. $recordData = Filter::act($_POST);
  5. $uploader = new Uploader("upload/xls/");
  6. $uploader->allowTypes = array("xls");
  7. $rs = $uploader->act();
  8. $xls = current($rs);
  9. $xls = $xls ? $xls[0] : array();
  10. if(!$xls){
  11. Yii::app()->jump->error('请选择上传的Excel文件');
  12. }
  13. if(!in_array($xls["ext"], array("xls", "xlsx")))
  14. Yii::app()->jump->error('上传的文件必须是Excel文件');
  15. $rs = $this->schoolManager->insertExamRecord($recordData, $xls);
  16. $url = "record/index";
  17. if(isset($recordData["class_id"]) && $recordData["class_id"])
  18. $url .= "?classId={$recordData["class_id"]}";
  19. $url = $this->createUrl($url);
  20. $result = array();
  21. $result["url"] = $url;
  22. $result["title"] = "导入结果";
  23. if(is_array($rs)){
  24. $result["result"] = $rs["global"]["result"];
  25. $errorsCount = count($rs["errors"]);
  26. $result["content"] = "
  27. {$rs["global"]["msg"]}<br/>
  28. ";
  29. $errorsCount = 0;
  30. $result["content"] = "";
  31. foreach($rs["errors"] as $key => $val){
  32. if($val["count"]){
  33. $errorsCount++;
  34. $result["content"] .= "
  35. 错误{$errorsCount}:<br/>
  36. 错误原因:{$val["type"]}<br/>
  37. 错误信息:{$val["msg"]}<br/>
  38. ";
  39. }
  40. }
  41. $result["content"] = "
  42. {$rs["global"]["msg"]}<br/>
  43. 共遇到{$errorsCount}个错误<br/>
  44. {$result["content"]}
  45. ";
  46. }
  47. else{
  48. $result["result"] = "失败";
  49. $result["content"] = "
  50. 共遇到1个错误<br/>
  51. 错误原因:数据库操作出错<br/>
  52. 错误信息:数据写入失败<br/>
  53. ";
  54. }
  55. Yii::app()->cache->set("coach_".Yii::app()->session->sessionID."_tips", $result, 120);
  56. $this->redirect($this->createUrl("index/showtips"));
  57. }
  58. public function actionDelAct(){
  59. $examId = Req::post("examId");
  60. $rs = $this->schoolManager->delExam($examId, 2);
  61. $code = $rs ? "0" : "1";
  62. $msg = array(
  63. "0" => "删除成功",
  64. "1" => "删除失败",
  65. );
  66. $rs = array(
  67. "code" => $code,
  68. "msg" => isset($msg[$code]) ? $msg[$code] : "",
  69. );
  70. echo json_encode($rs);exit;
  71. }
  72. public function actionEdit(){
  73. $examId = Req::get("examId");
  74. $classes = $this->schoolManager->getClasses();
  75. $exam = $this->schoolManager->getExam($examId);
  76. $examClassesIds = $this->schoolManager->getExamClassesIds($examId);
  77. $this->render("edit", array(
  78. "classes" => $classes,
  79. "examClassesIds" => $examClassesIds,
  80. "exam" => $exam,
  81. ));
  82. }
  83. public function actionIndex(){
  84. $classId = Req::get("classId");
  85. $grade = Req::get("grade");
  86. if(!$grade && !$classId){
  87. $grade = "1";
  88. }
  89. else if($classId){
  90. $class = $this->schoolManager->getClass($classId);
  91. if(!$class) $grade = "1";
  92. else $grade = $class["grade"];
  93. }
  94. $classes = $this->schoolManager->getClasses($grade);
  95. if(!$classId){
  96. $class = current($classes);
  97. if($class)
  98. $classId = $class["class_id"];
  99. }
  100. $rs = $this->schoolManager->getClassExamsList($classId);
  101. $this->render("index", array(
  102. "exams" => $rs["rs"],
  103. "pager" => $rs["pager"],
  104. "class" => $class,
  105. "classes" => $classes,
  106. "grade" => $grade,
  107. ));
  108. }
  109. public function actionGetGradeClassesJson(){
  110. $grade = Req::get("grade");
  111. echo json_encode($this->schoolManager->getClasses($grade));exit;
  112. }
  113. public function actionView(){
  114. $examId = Req::get("examId");
  115. $records = $this->schoolManager->getExamRecordsList($examId);
  116. $this->render("view", array(
  117. "records" => $records,
  118. ));
  119. }
  120. public function actionTo_zhixue_grade()
  121. {
  122. $data = array();
  123. $exam_group_ids = array();
  124. $exam_data = array();
  125. $exam_groups = array();
  126. // $condition[] = "eg.create_type in (0,1,2,3) ";
  127. $criteria = new CDbCriteria();
  128. $criteria->addCondition('semester_id = '.$this->semesterId);
  129. $criteria->addInCondition('subject_id',$this->mathSubjectId);
  130. $criteria->addCondition('status = 3');
  131. $criteria->addCondition('upload_status = 0');
  132. $criteria->order = 'create_time desc';
  133. $exam_all_data = Exam::model()->findAll($criteria);
  134. unset($criteria);
  135. if($exam_all_data)
  136. {
  137. foreach ($exam_all_data as $v)
  138. {
  139. $exam_group_ids[$v->exam_group_id] = $v->exam_group_id;
  140. $exam_data[$v->exam_group_id] = $v;
  141. }
  142. if($exam_group_ids)
  143. {
  144. $criteria = new CDbCriteria();
  145. $criteria->addInCondition('exam_group_id',$exam_group_ids);
  146. $criteria->addInCondition('create_type ',array(0,1,2,3));
  147. $exam_group_data = ExamGroup::model()->findAll($criteria);
  148. }
  149. if($exam_group_data)
  150. {
  151. foreach ($exam_group_data as $v)
  152. {
  153. if(isset($exam_data[$v->exam_group_id]))
  154. {
  155. $exam_groups[] = $exam_data[$v->exam_group_id];
  156. }
  157. }
  158. }
  159. $data['exam_info'] = $exam_groups;
  160. }
  161. unset($exam_all_data);
  162. $data["use_zhixue"] = $this->schoolInfo->use_zhixue;
  163. $this->render("to_zhixue_grade",$data);
  164. }
  165. public function actionZhixue_import()
  166. {
  167. ini_set ('memory_limit', '300M');
  168. if(!$_FILES){
  169. Yii::app()->jump->error('文件大小超过范围');
  170. }else{
  171. if(!isset($_FILES['exname']) || !isset($_FILES['exname']['size']) || $_FILES['exname']['size'] > 5242880){
  172. Yii::app()->jump->error('文件大小超过范围');
  173. }
  174. }
  175. if (Yii::app()->request->getIsPostRequest()) {
  176. $bstudents = new BusinessStudent();
  177. $exam_group_id = Req::post("exam_group_id");
  178. if(!$exam_group_id)
  179. {
  180. Yii::app()->jump->error('请选择考试信息');
  181. }
  182. $uploader = new Uploader("upload/tmpDir/zhixue_chengji/{$this->schoolId}/");
  183. $uploader->allowTypes = array("xls","xlsx");
  184. $uploader->fieldsMappings = array("exname" => array(0 => $this->schoolId . date('Ymdhis', time())));
  185. $file = $uploader->act();
  186. $file = Arr::current(Arr::current($file));
  187. if (!$file || !isset($file["error"]))
  188. Yii::app()->jump->error('请上传Excel!');
  189. if ($file["error"] != 0) {
  190. switch ($file["error"]) {
  191. case 2001:
  192. Yii::app()->jump->error('文件类型不符');
  193. break;
  194. case 2002:
  195. Yii::app()->jump->error('文件大小超出允许范围');
  196. break;
  197. default:
  198. Yii::app()->jump->error('上传失败');
  199. break;
  200. }
  201. }
  202. $inputFileName = $file["src"];
  203. // 导入PHPExcel类
  204. Yii::import('application.extensions.*');
  205. require_once('phpexcel/PHPExcel/IOFactory.php');
  206. // 读取Excel文档
  207. $exam_id = '';
  208. $exam_ids = array();
  209. $topic_count = 0;
  210. $zhixue_student_card = array();
  211. $class_name_data = array();
  212. $student_ids = array();
  213. $student_topic = array();
  214. $student_name_data = array();
  215. $_student_name_data = array();
  216. $tops = array();
  217. $scores = array();
  218. $_err = array();
  219. $_paper_ids = array();
  220. $_student_paper_ids = array();
  221. $_exam_ids = array();
  222. $total_score = 0;
  223. $student_score = array();
  224. $student_paper_all = array();
  225. $student_paper = array();
  226. $sql_arr = array();
  227. $student_paper_info = array();
  228. $paper_ids = array();
  229. $paper_student_ids = array();
  230. $zhixue_student_cards =array();
  231. $id_sum = 0;
  232. try{
  233. $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
  234. $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
  235. // FIXME 20191202
  236. @unlink($file["src"]);
  237. }catch (Exception $e){
  238. // FIXME 20191202
  239. @unlink($file["src"]);
  240. Yii::app()->jump->error('Excel格式不正确:'.$e->getMessage());
  241. }
  242. if(!$sheetData)
  243. {
  244. Yii::app()->jump->error('请正确的Excel!');
  245. }
  246. unset($objPHPExcel);
  247. unset($sheetData[1]);
  248. krsort($sheetData);
  249. $sheetData = array_reverse($sheetData);
  250. $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  251. if($exam_group_data)
  252. {
  253. foreach($exam_group_data as $v)
  254. {
  255. $exam_ids[$v->exam_id] = $v->exam_id;
  256. $exam_id = $v->exam_id;
  257. $tpl_data = json_decode($v->tpl_data,1);
  258. if(isset($tpl_data['scores']))
  259. {
  260. $total_score = $tpl_data['scores'];
  261. }
  262. }
  263. unset($exam_group_data);
  264. $paper_data = SPaper::model()->find('exam_id=:exam_id',array(':exam_id'=>$exam_id));
  265. if($paper_data)
  266. {
  267. $paper_topic_data = SPaperTopicRelation::model()->findAll(array('order'=>'`type` asc,`order` asc','condition'=>'paper_id=:paper_id','params'=>array(':paper_id'=>$paper_data->paper_id)));
  268. if($paper_topic_data)
  269. {
  270. foreach($paper_topic_data as $k=>$v)
  271. {
  272. $tops[$k] = $v->topic_id;
  273. $types[$v->topic_id] = $v->type;
  274. $scores[$v->topic_id] = $v->score;
  275. }
  276. unset($paper_data);
  277. $criteria = new CDbCriteria();
  278. //$criteria->select = 'student_id,paper_id,class_id,exam_id,semester_id,student_card,school_student_card,partial_right_count,compare,right_count,wrong_count,lost_score';
  279. $criteria->addInCondition('exam_id',$exam_ids);
  280. $criteria->addCondition('is_del=0');
  281. $student_paper_all_data = SStudentPaperRelation::model()->findAll($criteria);
  282. if($student_paper_all_data)
  283. {
  284. foreach($student_paper_all_data as $v)
  285. {
  286. $student_paper_all[$v->student_id] = $v->exam_id;
  287. $student_paper[$v->student_id] = $v->paper_id;
  288. $paper_ids[$v->paper_id] = $v->paper_id;
  289. $_paper_ids[$v->exam_id] = $v->paper_id;
  290. $student_paper_info[$v->student_id] = $v;
  291. }
  292. }
  293. unset($criteria);
  294. unset($student_paper_all_data);
  295. foreach($sheetData as $xv)
  296. {
  297. if(isset($xv['A']) && !empty($xv['A']) && isset($xv['B']) && !empty($xv['B']) && isset($xv['C'])&& !empty($xv['C']) && isset($xv['D']))
  298. {
  299. if(!is_numeric($xv['B'])){
  300. continue;
  301. }
  302. $id_sum++;
  303. if(isset($xv['E']))
  304. {
  305. $z_card = (string)$xv['B'];
  306. if(in_array($z_card, $zhixue_student_cards)){
  307. continue;
  308. }
  309. $zhixue_student_cards[$z_card] = $z_card;
  310. $student_name_data[(string)$z_card] = $xv['A'];
  311. $_student_name_data[(string)$z_card] = $xv['A'];
  312. $class_name_data[(string)$z_card] = $xv['C'];
  313. $student_topic[(string)$z_card] = array_merge(array(),array_slice($xv,4));
  314. $zhixue_student_card[(string)$z_card] = $z_card;
  315. $student_score[(string)$z_card] = (float)$xv['D'];
  316. //验证导入的成绩
  317. if($student_score[(string)$z_card] && $student_topic[(string)$z_card]){
  318. if($student_score[(string)$z_card] != array_sum($student_topic[(string)$z_card])){
  319. $_err['total_score']['student'][] = $xv['A'];
  320. }
  321. }
  322. if($student_topic[(string)$z_card] && $scores){
  323. if(count($scores) != count($student_topic[(string)$z_card])){
  324. $_err['score_count']['student'][] = $xv['A'];
  325. }else{
  326. $n = 0;
  327. $m = 0;
  328. foreach($scores as $v){
  329. $scoreArr = array_slice($student_topic[(string)$z_card],$n,1);
  330. if((int)$v < (int)current($scoreArr)){
  331. $_err['wrong_score']['student'][$z_card] = $xv['A'];
  332. }
  333. $n++;
  334. }
  335. }
  336. }
  337. }else
  338. {
  339. $_err['no_score']['student'][] = $xv['A'];
  340. }
  341. }else
  342. {
  343. //$_err['no_topic']['student'][] = $xv['A'];
  344. continue;
  345. }
  346. }
  347. if(!$zhixue_student_card){
  348. Yii::app()->jump->error('没有需要导入的正常数据');
  349. }
  350. $_uuid_arr = $this->createId(count($types)*$id_sum);
  351. $_uuid_arr_num = count($_uuid_arr);
  352. if(!$_uuid_arr)
  353. {
  354. Yii::app()->jump->error('预定义UUID不足,请联系技术人员');
  355. }
  356. // $criteria = new CDbCriteria();
  357. // $criteria->select = 'student_id,zhixue_student_card';
  358. // $criteria->addCondition('school_id=:school_id');
  359. // $criteria->addInCondition('zhixue_student_card',$zhixue_student_card);
  360. // $criteria->params[':school_id'] = $this->schoolId;
  361. // $b_student_data = BusinessStudent::model()->findAll($criteria);
  362. // unset($criteria);
  363. //处理准考证号量太大的问题
  364. $ArrCount=count($zhixue_student_card);
  365. $Student_data_temp=array();
  366. $b_student_data=array();
  367. if($ArrCount<500){
  368. $Student_data_temp = $bstudents->getStudentsBySchoolIdAndZhixuecard($this->schoolId,$zhixue_student_card);
  369. }elseif($ArrCount<1000){
  370. $TempArr=array_chunk($zhixue_student_card, 2);
  371. }else{
  372. $TempArr=array_chunk($zhixue_student_card, 5);
  373. }
  374. if($Student_data_temp){
  375. $b_student_data=$Student_data_temp;
  376. }elseif($TempArr){
  377. foreach ($TempArr as $item){
  378. $Student_data_temp=$bstudents->getStudentsBySchoolIdAndZhixuecard($this->schoolId,$item);
  379. if($Student_data_temp){
  380. $b_student_data=array_merge($b_student_data,$Student_data_temp);
  381. }
  382. }
  383. }
  384. // $b_student_data = $bstudents->getStudentsBySchoolIdAndZhixuecard($this->schoolId,$zhixue_student_card);
  385. if($b_student_data)
  386. {
  387. // foreach($b_student_data as $v)
  388. // {
  389. // if(isset($student_paper_all[$v->student_id]) && !empty($student_paper_all[$v->student_id]))
  390. // {
  391. // $student_ids[(string)$v->zhixue_student_card] = $v->student_id;
  392. // $paper_student_ids[$v->student_id] = $v->student_id;
  393. // unset($_student_name_data[(string)$v->zhixue_student_card]);
  394. //
  395. // }else
  396. // {
  397. // continue;
  398. // }
  399. //
  400. //
  401. //
  402. // }
  403. foreach($b_student_data as $v)
  404. {
  405. if(isset($student_paper_all[$v['student_id']]) && !empty($student_paper_all[$v['student_id']]))
  406. {
  407. $student_ids[(string)$v['zhixue_student_card']] = $v['student_id'];
  408. $paper_student_ids[$v['student_id']] = $v['student_id'];
  409. unset($_student_name_data[(string)$v['zhixue_student_card']]);
  410. }else
  411. {
  412. continue;
  413. }
  414. }
  415. unset($b_student_data);
  416. //写入
  417. $sql = '';
  418. $sql_sum = 0;
  419. $_sql_sum = 0;
  420. $_sql = '';
  421. $_sql_arr = array();
  422. /* */
  423. foreach($zhixue_student_card as $v)
  424. {
  425. $v = (string)$v;
  426. $complete_count = 0;
  427. $r_count = 0;
  428. $f_count = 0;
  429. $_student_id = 0;
  430. $_scoring = isset($student_score[$v])?$student_score[$v]:0;
  431. if(isset($student_topic[$v]))
  432. {
  433. if( count($student_topic[$v]) != count($paper_topic_data))
  434. {
  435. Yii::app()->jump->error('导入的题数不正确!');exit;
  436. }
  437. }
  438. if(isset($student_ids[$v]) && !empty($student_ids[$v]) && isset($student_paper[$student_ids[$v]]) && !empty($student_paper[$student_ids[$v]]) && isset($student_paper_info[$student_ids[$v]]))
  439. {
  440. $_paper_id = $student_paper[$student_ids[$v]];
  441. $_student_id = $student_ids[$v];
  442. if(isset($student_topic[$v]) && !empty($student_topic[$v]))
  443. {
  444. $i = 0;
  445. foreach($student_topic[$v] as $key => $val)
  446. {
  447. $val = (int)$val;
  448. $complete_count += 1;
  449. $topic_id = '';
  450. $_score = 0;
  451. $type = '';
  452. $is_right = 0;
  453. if(isset($tops[$i]) && !empty($tops[$i]))
  454. {
  455. $topic_id = $tops[$i];
  456. if(isset($scores[$tops[$i]]) && !empty($scores[$tops[$i]]))
  457. {
  458. $_score = $scores[$tops[$i]];
  459. }
  460. if(isset($types[$tops[$i]]) && !empty($types[$tops[$i]]))
  461. {
  462. $type = $types[$tops[$i]];
  463. }
  464. }
  465. if($type==1)
  466. {
  467. if($val==$_score)
  468. {
  469. $is_right = 1;
  470. $r_count += 1;
  471. }elseif($val>0 && $val<$_score)
  472. {
  473. $val = 0;
  474. $f_count +=1;
  475. }else
  476. {
  477. $f_count +=1;
  478. }
  479. }
  480. if($type==5)
  481. {
  482. if($val==$_score)
  483. {
  484. $is_right = 1;
  485. $r_count += 1;
  486. }else
  487. {
  488. $f_count +=1;
  489. }
  490. }
  491. if($type>5)
  492. {
  493. if($val==$_score)
  494. {
  495. $is_right = 1;
  496. $r_count += 1;
  497. }elseif($val>0 && $val<$_score)
  498. {
  499. if($_score*0.8<$val)
  500. {
  501. $is_right = 1;
  502. $r_count += 1;
  503. }else{
  504. $is_right = 2;
  505. $f_count +=1;
  506. }
  507. }
  508. }
  509. if(empty($val))
  510. {
  511. $val=0;
  512. }
  513. $_uuid = current($_uuid_arr);
  514. unset($_uuid_arr[$_uuid]);
  515. $sql.="(".$_uuid.",".$_student_id.",".$_paper_id.",".$topic_id.",".$type.','.$is_right.','.$val.",''),";
  516. if($sql_sum==300 )
  517. {
  518. $sql = substr($sql,0,-1).';';
  519. $sql_arr[] = $sql;
  520. $sql_sum = 0;
  521. $sql = '';
  522. }
  523. $i++;
  524. $sql_sum++;
  525. }
  526. }
  527. unset($student_topic[$v]);
  528. $paper_obj = $student_paper_info[$_student_id];
  529. $_sql.= "(".$paper_obj->student_id.",".$paper_obj->paper_id.",".$paper_obj->class_id.",".$paper_obj->exam_id.",".$paper_obj->semester_id.",".$paper_obj->student_card.",'".$paper_obj->school_student_card."',".$complete_count.",".$r_count.",".$paper_obj->partial_right_count.",".$f_count.",".$_scoring.",".($total_score-$_scoring).",".$paper_obj->compare.",0,1,1,".time().",".time().",''),";
  530. if($_sql_sum ==300)
  531. {
  532. $_sql = substr($_sql,0,-1).';';
  533. $_sql_arr[] = $_sql;
  534. $_sql_sum = 0;
  535. $_sql = '';
  536. }
  537. $_sql_sum++;
  538. }else
  539. {
  540. $_err['no_student']['student'][] = isset($student_name_data[(string)$v])?$student_name_data[(string)$v]:'';
  541. continue;
  542. }
  543. }
  544. unset($zhixue_student_card);
  545. $result = '';
  546. if($_student_name_data)
  547. {
  548. $_err['no_student']['no_exam_student'] = $_student_name_data;
  549. }
  550. if($_err)
  551. {
  552. $y = 0;
  553. foreach($_err as $k=>$v)
  554. {
  555. if($k=='no_score')
  556. {
  557. $result['msg'][$y]['title'] = '错误无分数';
  558. $result['msg'][$y]['result'] = implode(',',$v['student']);
  559. }
  560. if($k=='no_topic')
  561. {
  562. $result['msg'][$y]['title'] = '无做题';
  563. $result['msg'][$y]['result'] = implode(',',$v['student']);
  564. }
  565. if($k=='no_exam_student')
  566. {
  567. $result['msg'][$y]['title'] = '无考试';
  568. $result['msg'][$y]['result'] = implode(',',$v['student']);
  569. }
  570. if($k=='no_student')
  571. {
  572. $result['msg'][$y]['title'] = '不存在学生';
  573. $result['msg'][$y]['result'] = implode(',',$v['student']);
  574. }
  575. if($k=='wrong_score')
  576. {
  577. $result['msg'][$y]['title'] = '上传成绩超出试卷小题成绩';
  578. $result['msg'][$y]['result'] = implode(',',$v['student']);
  579. }
  580. if($k=='total_score')
  581. {
  582. $result['msg'][$y]['title'] = '上传成绩总分与各小题不符';
  583. $result['msg'][$y]['result'] = implode(',',$v['student']);
  584. }
  585. $y++;
  586. }
  587. $result['url'] = Yii::app()->createUrl('record/to_zhixue_grade');
  588. $this->render('show',$result);exit;
  589. }
  590. if($sql){
  591. $sql = substr($sql,0,-1).';';
  592. $sql_arr[] = $sql;
  593. }
  594. if(!$sql_arr )
  595. {
  596. Yii::app()->jump->error('数据有误,无法导入!');exit;
  597. }
  598. if($_sql){
  599. $_sql = substr($_sql,0,-1).';';
  600. $_sql_arr[] = $_sql;
  601. }
  602. if(!$_sql_arr )
  603. {
  604. Yii::app()->jump->error('数据有误,无法导入!');exit;
  605. }
  606. $transaction = $this->sConn->beginTransaction();
  607. try{
  608. $criteria = new CDbCriteria();
  609. $criteria->addInCondition('paper_id',$paper_ids);
  610. $criteria->addInCondition('student_id',$paper_student_ids);
  611. SStudentPaperTopicRs::model()->deleteAll($criteria);
  612. unset($criteria);
  613. $criteria = new CDbCriteria();
  614. $criteria->addInCondition('paper_id',$paper_ids);
  615. $criteria->addInCondition('student_id',$paper_student_ids);
  616. SStudentPaperRelation::model()->deleteAll($criteria);
  617. unset($criteria);
  618. $sql2 = 'INSERT INTO `student_paper_relation`
  619. (`student_id`,`paper_id`,`class_id`,`exam_id`,`semester_id`,`student_card`,`school_student_card`,`complete_count`,`right_count`,`partial_right_count`,`wrong_count`,`scoring`,`lost_score`,`compare`,`report_created`,`is_feedback`,`is_complete`,`feedback_time`,`complete_time`,`studytrend_exam_name`)VALUES';
  620. $sql1='INSERT INTO `student_paper_topic_rs`
  621. (`id`,`student_id`,`paper_id`,`topic_id`,`type`,`is_right`,`scoring`,`simplify_answer_url`)VALUES';
  622. if($sql_arr)
  623. {
  624. foreach($sql_arr as $k=>$v)
  625. {
  626. if($v==';')
  627. {
  628. throw new Exception('数据有误,无法导入!');
  629. }
  630. $this->sConn->createCommand($sql1.$v)->execute();
  631. ob_flush();
  632. }
  633. }
  634. unset($sql_arr);
  635. if($_sql_arr)
  636. {
  637. foreach($_sql_arr as $v)
  638. {
  639. if($v==';')
  640. {
  641. throw new Exception('数据有误,无法导入!');
  642. }
  643. $this->sConn->createCommand($sql2.$v)->execute();
  644. }
  645. }
  646. unset($_sql_arr);
  647. Exam::model()->updateAll(array('upload_status'=>2,'status'=>1,'is_topwb_html'=>0,'is_topwb_pdf'=>0,'is_academicr_html'=>0,'is_academicr_pdf'=>0,'update_time'=>time(),'complete_time'=>time()),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  648. ExamGroup::model()->updateAll(array('mark_status'=>2,'upload_status'=>2,'status'=>2,'import_score_type'=>1),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  649. $transaction->commit();
  650. }catch(Exception $e)
  651. {
  652. $transaction->rollBack();
  653. Yii::app()->jump->error('Excel导入失败!');
  654. }
  655. //$this->UUID_log($exam_group_id,$_uuid_arr_num);
  656. Yii::app()->jump->error('Excel导入成功!');
  657. }else
  658. {
  659. $result['msg'][0]['title'] = '学生不存在';
  660. $result['msg'][0]['result'] = '此文档中所有学生不存在';
  661. $result['url'] = Yii::app()->createUrl('record/to_zhixue_grade');
  662. $this->render('show',$result);exit;
  663. }
  664. }
  665. }
  666. }
  667. Yii::app()->jump->error('Excel导入失败!');
  668. }
  669. }
  670. //预生成ID
  671. private function addSetUUID($_uuid_arr)
  672. {
  673. if($_uuid_arr)
  674. {
  675. Yii::app()->business_uuid_cache->hmset('redis_business_uuid:'.$this->schoolId,$_uuid_arr);
  676. }
  677. }
  678. private function UUID_log($exam_group_id,$sum)
  679. {
  680. Yii::app()->business_uuid_cache->setValue('redis_business_uuid_log'.$this->schoolId,'导入智学网成绩,使用了'.$sum.'个UUID,导入时间为'.date('Y-n-d H:i:s',time()).',导入考试的ID:'.$exam_group_id);
  681. Yii::app()->redis_business_student->expire('redis_business_uuid_log:'.$this->schoolId,86400);
  682. }
  683. //新版导入成绩
  684. public function actionImportScore(){
  685. $examGroupId=Req::get('exam_group_id');
  686. $checkField=Req::get('check_field');
  687. $renew=Req::get('renew');
  688. $data = array();
  689. $sql="select * from import_score_temp where exam_type=0 limit 1";
  690. $data=$this->sConn->createCommand($sql)->queryRow();
  691. if($data){
  692. $this->redirect(Yii::app()->createUrl('record/check_excel'));
  693. }else{
  694. $sql="select * from import_score_temp where exam_type=2 limit 1";
  695. $data=$this->sConn->createCommand($sql)->queryRow();
  696. if($data) {
  697. $this->redirect(Yii::app()->createUrl('record/checkImgExcel'));
  698. }
  699. }
  700. $exam=Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examGroupId));
  701. $data['exam_name']=$exam['name'];
  702. $data['exam_group_id']=$examGroupId;
  703. $data['check_field']=$checkField;
  704. $data['renew']=$renew;
  705. //扩展字段设置
  706. $studentExtend=$this->schoolManager->getStudentExtend();
  707. $data['studentExtend']=$studentExtend;
  708. $this->render('import', $data);
  709. }
  710. //加载考试
  711. public function actionAjaxSearchExam(){
  712. $exam_type=Req::post('exam_type');
  713. $subject=Req::post('subject');
  714. $grade=Req::post('grade');
  715. $class=Req::post('class');
  716. $keyword=Req::post('keyword');
  717. $condition=array();
  718. //$condition[]=" (eg.qxk_paper_id=0 or eg.qxk_paper_id is null)";
  719. $condition[]="e.semester_id='{$this->semesterId}'";
  720. $condition[] = "e.is_display = 0";
  721. if($exam_type==1){
  722. $condition[]='eg.is_third=0';
  723. }elseif($exam_type==2){
  724. $condition[]='eg.is_third=1';
  725. }
  726. $condition[] = "eg.homework = 0";
  727. $condition[] = "eg.import_score_type <> 2";
  728. if($subject==3){
  729. $condition[]='e.subject_id in ('.implode(',',$this->mathSubjectId).')';
  730. }else{
  731. $condition[]="e.subject_id ='".$subject."'";
  732. }
  733. if($grade){
  734. $condition[]="c.grade='".$grade."'";
  735. }
  736. if($class){
  737. $condition[]="c.class_id='".$class."'";
  738. }
  739. if($keyword){
  740. $condition[]="e.name like '%".$keyword."%'";
  741. }
  742. $sql="SELECT eg.exam_group_id,e.exam_id,e.name,c.grade,e.tpl_data,eg.is_third,e.`status`,c.class_id,e.subject_id,p.paper_id,eg.import_score_type,e.is_backlog FROM `exam` e ";
  743. $sql.="join exam_group eg on eg.exam_group_id=e.exam_group_id ";
  744. $sql.="join class c on c.class_id=e.class_id ";
  745. $sql.="join paper p on p.exam_id=e.exam_id ";
  746. if($condition){
  747. $sql.=" where ".implode(' and ',$condition);
  748. }
  749. $sql.=" order by e.create_time desc ";
  750. $Exam = $this->sConn->createCommand($sql)->queryAll();
  751. $list=array();
  752. if($Exam){
  753. $paperIds=array();
  754. $examGroupIds=array();
  755. foreach($Exam as $key=>$val){
  756. $paperIds[$val['exam_group_id']][]=$val['paper_id'];
  757. $examGroupIds[]=$val['exam_group_id'];
  758. $list[$val['exam_group_id']]=$val;
  759. }
  760. if($class && $examGroupIds){
  761. $paperIds=array();
  762. $sqlClassCount="SELECT eg.exam_group_id,e.exam_id,e.name,c.grade,e.tpl_data,eg.is_third,e.`status`,c.class_id,e.subject_id,p.paper_id,eg.import_score_type FROM `exam_group` eg ";
  763. $sqlClassCount.="join exam e on eg.exam_group_id=e.exam_group_id ";
  764. $sqlClassCount.="join class c on c.class_id=e.class_id ";
  765. $sqlClassCount.="join paper p on p.exam_id=e.exam_id ";
  766. $sqlClassCount.=" where e.exam_group_id in(".implode(',',$examGroupIds).")";
  767. $ExamCount = $this->sConn->createCommand($sqlClassCount)->queryAll();
  768. foreach ($ExamCount as $val){
  769. $paperIds[$val['exam_group_id']][]=$val['paper_id'];
  770. $list[$val['exam_group_id']]=$val;
  771. }
  772. }
  773. //debug($examGroupIds);
  774. if($list){
  775. foreach ($list as $key=>$val){
  776. $list[$key]['student_score_count']=0;
  777. $list[$key]['class_count']=0;
  778. $list[$key]['exam_date']='';
  779. if(isset($paperIds[$val['exam_group_id']])){
  780. $list[$key]['class_count']=count($paperIds[$val['exam_group_id']]);
  781. $sql_student_paper="select count(*) as count from student_paper_relation where paper_id in(".implode(',',$paperIds[$val['exam_group_id']]).") and is_feedback=1";
  782. $studentCount = $this->sConn->createCommand($sql_student_paper)->queryRow();
  783. if($studentCount){
  784. if($val['import_score_type']==0 && $studentCount['count']>0){
  785. //扫描成绩,跳过
  786. unset($list[$key]);
  787. continue;
  788. }else{
  789. $list[$key]['student_score_count']=$studentCount['count'];
  790. }
  791. }
  792. }
  793. if($val['tpl_data']){
  794. $tpl_data=json_decode($val['tpl_data'],true);
  795. if(isset($tpl_data['examDate'])){
  796. $list[$key]['exam_date']=$tpl_data['examDate'];
  797. }
  798. }
  799. if(isset(Yii::app()->params['grade_list'][$val['grade']])){
  800. $list[$key]['grade']=Yii::app()->params['grade_list'][$val['grade']]['grade_name'];
  801. }else{
  802. $list[$key]['grade']='';
  803. }
  804. }
  805. }
  806. }
  807. $result['status']=1;
  808. $result['list']=$list;
  809. exit(json_encode($result));
  810. }
  811. //新版全学科导入成绩,导入表格
  812. public function actionImportStore(){
  813. ini_set ('memory_limit', '300M');
  814. if(!$_FILES){
  815. Yii::app()->jump->error('文件大小超过范围');
  816. }else{
  817. if(!isset($_FILES['exname']) || !isset($_FILES['exname']['size']) || $_FILES['exname']['size'] > 5242880){
  818. Yii::app()->jump->error('文件大小超过范围');
  819. }
  820. }
  821. if (Yii::app()->request->getIsPostRequest()) {
  822. $exam_group_id=Req::post('exam_group_id');
  823. $check_field=Req::post('check_field');
  824. $exam_renew=Req::post('exam_renew');
  825. if(!$exam_group_id)
  826. {
  827. Yii::app()->jump->error('请选择考试信息');
  828. }
  829. $uploader = new Uploader("upload/tmpDir/zhixue_chengji/{$this->schoolId}/");
  830. $uploader->allowTypes = array("xls","xlsx");
  831. $uploader->fieldsMappings = array("exname" => array(0 => $this->schoolId . date('Ymdhis', time())));
  832. $file = $uploader->act();
  833. $file = Arr::current(Arr::current($file));
  834. if (!$file || !isset($file["error"]))
  835. Yii::app()->jump->error('请上传的Excel!');
  836. if ($file["error"] != 0) {
  837. switch ($file["error"]) {
  838. case 2001:
  839. Yii::app()->jump->error('文件类型不符');
  840. break;
  841. case 2002:
  842. Yii::app()->jump->error('文件大小超出允许范围');
  843. break;
  844. default:
  845. Yii::app()->jump->error('上传失败');
  846. break;
  847. }
  848. }
  849. $inputFileName = $file["src"];
  850. // 导入PHPExcel类
  851. Yii::import('application.extensions.*');
  852. require_once('phpexcel/PHPExcel/IOFactory.php');
  853. try{
  854. $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
  855. $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
  856. // FIXME 20191202
  857. @unlink($file["src"]);
  858. }catch (Exception $e){
  859. // FIXME 20191202
  860. @unlink($file["src"]);
  861. Yii::app()->jump->error('Excel格式不正确:'.$e->getMessage());
  862. }
  863. if(!$sheetData)
  864. {
  865. Yii::app()->jump->error('请正确的Excel!');
  866. }
  867. unset($objPHPExcel);
  868. if(($check_field=='student_name' && $sheetData[1]['C']!='科目总分') || ($check_field!='student_name' && $sheetData[1]['C']=='科目总分')){
  869. Yii::app()->jump->error('Excel格式不正确!');
  870. }
  871. unset($sheetData[1]);
  872. if(!$sheetData)
  873. {
  874. Yii::app()->jump->error('请输入学生成绩数据');
  875. }
  876. $insertSql="insert into import_score_temp(`student_name`,`class_name`,`check_field_value`,`score_data`,`exam_group_id`,`check_field`,`renew`) values";
  877. $valuesArray=array();
  878. foreach ($sheetData as $val){
  879. if(!isset($val['A']) || !isset($val['B']) || !isset($val['C']) || !isset($val['D'])){
  880. continue;
  881. }
  882. $student_topic= array_merge(array(),array_slice($val,2));
  883. $regex = '/^[a-zA-Z0-9]+$/u';
  884. if($check_field=='student_name'){
  885. $topic_score=array_slice($student_topic,1);
  886. $check_field_value=$val['A'];
  887. }else{
  888. $topic_score=array_slice($student_topic,2);
  889. $check_field_value=$val['C'];
  890. if(!preg_match($regex, $check_field_value)){
  891. Yii::app()->jump->error('识别考号内容只能是数字和字母');
  892. }
  893. }
  894. foreach ($topic_score as $k=>$v){
  895. if(!empty($v) && (!is_numeric($v) || floatval($v)<0)){
  896. Yii::app()->jump->error('分数必须是数值类型且》=0');
  897. }
  898. }
  899. if($check_field=='student_name'){
  900. $valuesArray[]="('".$val['A']."','".$val['B']."','','".json_encode($student_topic)."','".$exam_group_id."','".$check_field."','".$exam_renew."')";
  901. }else{
  902. $valuesArray[]="('".$val['A']."','".$val['B']."','".$val['C']."','".json_encode($student_topic)."','".$exam_group_id."','".$check_field."','".$exam_renew."')";
  903. }
  904. }
  905. if($valuesArray){
  906. // $delSql="truncate table import_score_temp;";
  907. $delSql="delete from import_score_temp;";
  908. $this->sConn->createCommand($delSql)->execute();
  909. $insertSql.=implode(',',$valuesArray);
  910. $this->sConn->createCommand($insertSql)->execute();
  911. $this->redirect(Yii::app()->createUrl('record/check_excel'));
  912. }else{
  913. Yii::app()->jump->error('没有发现学生成绩数据');
  914. }
  915. Yii::app()->jump->error('导入失败');
  916. }
  917. }
  918. //导入数据检测页
  919. public function actionCheck_Excel(){
  920. $sql="select * from import_score_temp where exam_type=0 limit 1";
  921. $data=$this->sConn->createCommand($sql)->queryRow();
  922. $fileName=array(
  923. 'student_name'=>'学生姓名',
  924. 'userno'=>'学号',
  925. 'student_card'=>'准考证号',
  926. 'school_student_card'=>'学校准考证号',
  927. 'zhixue_student_card'=>'智学网考证号',
  928. 'id_number'=>'身份证号',
  929. 'student_phone'=>'手机号'
  930. );
  931. //扩展字段
  932. $studentExtend=$this->schoolManager->getStudentExtend();
  933. if($studentExtend){
  934. foreach ($studentExtend as $key=> $value){
  935. $fileName[$key]=$value['field_mean'];
  936. }
  937. }
  938. if(isset($fileName[$data['check_field']])){
  939. $data['check_field_name']=$fileName[$data['check_field']];
  940. }else{
  941. $data['check_field_name']='学生姓名';
  942. }
  943. $data['need_check_name']=0;
  944. if($data['check_field_name']=='学生姓名'){
  945. $data['need_check_name']=1;
  946. }
  947. $this->render('check',$data);
  948. }
  949. //处理导入数据页面
  950. public function actionHandle_Excel(){
  951. $this->render('handle');
  952. }
  953. //检测格式
  954. public function actionCheck_field_first(){
  955. $result['status']=0;
  956. $sql="select * from import_score_temp where exam_type=0";
  957. $All_Data=$this->sConn->createCommand($sql)->queryAll();
  958. if(!$All_Data){
  959. exit(json_encode($result));
  960. }
  961. $data=$All_Data[0];
  962. $check_field=$data['check_field'];
  963. $score_data=json_decode($data['score_data'],true);
  964. $exam_group_id=$data['exam_group_id'];
  965. if(!$score_data){
  966. $result['msg']='数据不完整';
  967. exit(json_encode($result));
  968. }
  969. $examGroup=SExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  970. //检测题量
  971. $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  972. $total_score=0;
  973. if($exam_group_data) {
  974. foreach ($exam_group_data as $v) {
  975. $exam_id = $v->exam_id;
  976. $tpl_data = json_decode($v->tpl_data, 1);
  977. if (isset($tpl_data['scores'])) {
  978. $total_score = $tpl_data['scores'];
  979. }
  980. break;
  981. }
  982. unset($exam_group_data);
  983. $paper_data = SPaper::model()->find('exam_id=:exam_id', array(':exam_id' => $exam_id));
  984. $paper_topic_data = SPaperTopicRelation::model()->findAll(array('order'=>'`no` asc','condition'=>'paper_id=:paper_id','params'=>array(':paper_id'=>$paper_data->paper_id)));
  985. if(!$paper_topic_data){
  986. $result['msg']='请先关联答题卡再上传成绩';
  987. exit(json_encode($result));
  988. }
  989. $alias=array();
  990. $sortPaperTopic=array();
  991. //检测试题别名
  992. if(isset($tpl_data['new_items']) && !$examGroup['qxk_paper_id']){
  993. foreach ($tpl_data['new_items'] as $item){
  994. $alias[$item['id']]=$item['alias'];
  995. }
  996. //重新排序
  997. foreach ($paper_topic_data as $key =>$datum){
  998. $sortPaperTopic[$alias[$datum['order']]]=$datum;
  999. }
  1000. ksort($sortPaperTopic);
  1001. $sortPaperTopic=array_values($sortPaperTopic);
  1002. }else{
  1003. $sortPaperTopic=$paper_topic_data;
  1004. }
  1005. //检测试题数据
  1006. foreach($All_Data as $key=> $val){
  1007. $score_data=json_decode($val['score_data'],true);
  1008. if($check_field!='student_name'){
  1009. $topic_score=array_slice($score_data,2);
  1010. $total_score_import=$score_data['D'];
  1011. }else{
  1012. $topic_score=array_slice($score_data,1);
  1013. $total_score_import=$score_data['C'];
  1014. }
  1015. if($total_score_import!=array_sum($topic_score)){
  1016. $result['msg']='科目总分和试题总分不一致:'.$val['student_name'];
  1017. exit(json_encode($result));
  1018. }
  1019. if(count($topic_score)!=count($sortPaperTopic)){
  1020. $result['msg']='上传题量和试卷题量不一致:'.$val['student_name'];
  1021. exit(json_encode($result));
  1022. }
  1023. $topic_score=array_values($topic_score);
  1024. foreach($topic_score as $order => $v){
  1025. if(!empty($v) && (!is_numeric($v) || floatval($v)<0)){
  1026. $result['msg']='试题分数必须是数值类型:'.$val['student_name'];
  1027. exit(json_encode($result));
  1028. }
  1029. if(isset($sortPaperTopic[$order])){
  1030. if($v>$sortPaperTopic[$order]['score']){
  1031. $result['msg']=$val['student_name'].':第'.($order+1).'题试题分数和考试设置分数不一致,提交分数:'.$v."试卷设置分数:".$sortPaperTopic[$order]['score'];
  1032. exit(json_encode($result));
  1033. }
  1034. }else{
  1035. $result['msg']='上传题量和试卷题量不一致';
  1036. exit(json_encode($result));
  1037. }
  1038. }
  1039. }
  1040. $result['msg']='检测完成';
  1041. $result['status']=1;
  1042. }else{
  1043. $result['msg']='未发现对应考试';
  1044. exit(json_encode($result));
  1045. }
  1046. exit(json_encode($result));
  1047. }
  1048. //检测姓名
  1049. public function actionCheck_student_name(){
  1050. ini_set('memory_limit','512M');
  1051. set_time_limit(0);
  1052. $result['status']=0;
  1053. $result['data']=0;
  1054. $student_all_data = $this->sConn->createCommand("SELECT id,student_name FROM `import_score_temp` `t` where exam_type=0")->queryAll();
  1055. if($student_all_data){
  1056. //去除非中文字符
  1057. $updateArr=array();
  1058. $preg="/[^\x{4E00}-\x{9FFF}^·0-9]+/u";
  1059. $count=0;
  1060. foreach($student_all_data as $val){
  1061. if(preg_match($preg,$val['student_name'])){
  1062. $ModifyName = preg_replace($preg, "", $val['student_name']);
  1063. if($ModifyName){
  1064. $updateArr[$val['id']]=$ModifyName;
  1065. $count++;
  1066. }
  1067. }else{
  1068. $updateArr[$val['id']]=$val['student_name'];
  1069. }
  1070. }
  1071. //组织更新语句
  1072. if($updateArr){
  1073. $arrNumber=ceil(count($updateArr)/500);
  1074. $Arr=array_chunk($updateArr,$arrNumber,true);
  1075. $transcation = $this->sConn->beginTransaction();
  1076. try {
  1077. foreach ($Arr as $item){
  1078. $sql='update import_score_temp set `check_field_value`= case id ';
  1079. foreach ($item as $key=> $val){
  1080. $sql.=" WHEN ".$key." THEN '".$val."' ";
  1081. }
  1082. $sql.=" End ";
  1083. $sql.=" where check_field_value='' or check_field_value is null and exam_type=0";
  1084. $this->sConn->createCommand($sql)->execute();
  1085. }
  1086. $transcation->commit();
  1087. $result['status']=1;
  1088. }catch (Exception $e){
  1089. $transcation->rollback();
  1090. }
  1091. }
  1092. $result['count']=$count;
  1093. }
  1094. exit(json_encode($result));
  1095. }
  1096. //匹配信息
  1097. public function actionMatching(){
  1098. $noExistent=0; //不存在
  1099. $repeat=0; //重复(组)
  1100. $success=0; //匹配成功
  1101. $scoreWrong=0; //成绩不正确
  1102. $result['status']=0;
  1103. $sql="select * from import_score_temp where exam_type=0 limit 1";
  1104. $data=$this->sConn->createCommand($sql)->queryRow();
  1105. if(!$data){
  1106. exit(json_encode($result));
  1107. }
  1108. $check_field=$data['check_field'];
  1109. $exam_group_id=$data['exam_group_id'];
  1110. $classArr=array();
  1111. $classIds=array();
  1112. $check_data_group=array(); //检查字段对应临时表id
  1113. $update_temp_data=array(); //更新临时表数据
  1114. $student_card=array(); //学生id,准考证号对应数据
  1115. $tpl_data=array();
  1116. $updateSql=array();
  1117. $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  1118. $exam_group_data = $this->sConn->createCommand("SELECT e.exam_id,e.tpl_data,p.paper_id,e.class_id FROM `exam` e join paper p on e.exam_id=p.exam_id where e.exam_group_id='".$exam_group_id."'")->queryAll();
  1119. $paperIds=array();
  1120. if($exam_group_data){
  1121. foreach ($exam_group_data as $v){
  1122. if(!$tpl_data && isset($v['tpl_data'])){
  1123. $tpl_data=json_decode($v['tpl_data'],true);
  1124. }
  1125. $classIds[]=$v['class_id'];
  1126. $paperIds[]=$v['paper_id'];
  1127. }
  1128. }
  1129. //统计已经匹配成功的数据
  1130. $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=0 ")->queryAll();
  1131. if($success_student_data){
  1132. $success=count($success_student_data);
  1133. }
  1134. $check_field_val_arr=array();
  1135. $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=0 ")->queryAll();
  1136. if(!$student_all_data){
  1137. $result['repeat']=0;
  1138. $result['success']=$success;
  1139. $result['noExistent']=0;
  1140. $result['status']=1;
  1141. exit(json_encode($result));
  1142. }
  1143. foreach ($student_all_data as $val){
  1144. //验证学生分数
  1145. $check_field_val_arr[]="'".$val['check_field_value']."'";
  1146. $check_data_group[$val['check_field_value']]=$val['id'];
  1147. }
  1148. //处理重复数据
  1149. $repeat_group_data=array();
  1150. $search_value_arr=array();
  1151. foreach ($check_field_val_arr as $value){
  1152. $repeat_group_data[$value][]=$value;
  1153. }
  1154. foreach ($repeat_group_data as $key=>$val){
  1155. if(count($val)>1){
  1156. $repeat++;
  1157. $modify_name=str_replace("'",'',$key);
  1158. $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=0";
  1159. }else{
  1160. $search_value_arr[]=$val[0];
  1161. }
  1162. }
  1163. if($search_value_arr){
  1164. $student_info=array();
  1165. $b_student=array();
  1166. switch ($check_field){
  1167. case 'student_name':
  1168. $sql="select si.student_id,si.realname from student_info si join student_paper_relation spr on si.student_id = spr.student_id where realname in(".implode(',',$search_value_arr).") and paper_id in(".implode(',',$paperIds).")";
  1169. $student_info=$this->sConn->createCommand($sql)->queryAll();
  1170. break;
  1171. case 'userno':
  1172. $sql="select userno,spr.student_id from student_info si ";
  1173. $sql.="join student_class_relation scr on scr.student_id=si.student_id ";
  1174. $sql.="join student_paper_relation spr on si.student_id = spr.student_id ";
  1175. $sql.=" where scr.userno in(".implode(',',$search_value_arr).") and scr.status=0 and scr.class_id in(".implode(',',$classIds).") and spr.paper_id in(".implode(',',$paperIds).")";
  1176. $student_info=$this->sConn->createCommand($sql)->queryAll();
  1177. break;
  1178. case 'student_card':
  1179. $sql="select student_id,student_card from student where student_card in(".implode(',',$search_value_arr).") and status=0";
  1180. $b_student=$this->conn->createCommand($sql)->queryAll();
  1181. break;
  1182. case 'school_student_card':
  1183. $sql="select student_id,school_student_card from student where school_student_card in(".implode(',',$search_value_arr).") and status=0";
  1184. $b_student=$this->conn->createCommand($sql)->queryAll();
  1185. break;
  1186. case 'zhixue_student_card':
  1187. $sql="select student_id,zhixue_student_card from student where zhixue_student_card in(".implode(',',$search_value_arr).") and status=0";
  1188. $b_student=$this->conn->createCommand($sql)->queryAll();
  1189. break;
  1190. default:
  1191. $sql="select * from student_info si join student_paper_relation spr on si.student_id = spr.student_id where `".$check_field."` in(".implode(',',$search_value_arr).") and paper_id in(".implode(',',$paperIds).") and is_del=0 ";
  1192. $student_info=$this->sConn->createCommand($sql)->queryAll();
  1193. }
  1194. if($b_student){
  1195. $studentIds=array();
  1196. foreach ($b_student as $item){
  1197. $studentIds[]=$item['student_id'];
  1198. $student_card[$item['student_id']]=$item[$check_field];
  1199. }
  1200. $sql="select si.student_id from student_info si join student_paper_relation spr on si.student_id = spr.student_id where si.student_id in(".implode(',',$studentIds).") and paper_id in(".implode(',',$paperIds).") and is_del=0 ";
  1201. $student_info=$this->sConn->createCommand($sql)->queryAll();
  1202. if($student_info){
  1203. foreach($student_info as $key=>$val){
  1204. $student_info[$key][$check_field]=$student_card[$val['student_id']];
  1205. }
  1206. }
  1207. }
  1208. if(!$student_info){
  1209. $noExistent=count($search_value_arr);
  1210. $result['repeat']=$repeat;
  1211. $result['success']=$success;
  1212. $result['noExistent']=$noExistent;
  1213. $result['status']=1;
  1214. }else{
  1215. $result['status']=1;
  1216. //过滤掉已被删除的学生
  1217. foreach ($student_info as $key=>$value){
  1218. $sql_class_relation="select * from student_class_relation where student_id='".$value['student_id']."' and status=0 ";
  1219. $student_class_realtion=$this->sConn->createCommand($sql_class_relation)->queryRow();
  1220. if(!$student_class_realtion){
  1221. unset($student_info[$key]);
  1222. }
  1223. }
  1224. if($check_field=='student_name'){
  1225. $nameArr=array();
  1226. foreach ($student_info as $item){
  1227. $preg="/[^\x{4E00}-\x{9FFF}^·0-9]+/u";
  1228. $ModifyName = preg_replace($preg, "", $item['realname']);
  1229. $nameArr[$ModifyName][]=$item;
  1230. }
  1231. $noExistent=count($search_value_arr)-count($nameArr);
  1232. if($noExistent<0) $noExistent=0;
  1233. $result['noExistent']=$noExistent;
  1234. foreach ($nameArr as $key=>$value){
  1235. if(count($value)>1){
  1236. $repeat++;
  1237. $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=0";
  1238. }else{
  1239. $success++;
  1240. if(isset($check_data_group[$key])){
  1241. $update_temp_data[$check_data_group[$key]]=$value[0]['student_id'];
  1242. }
  1243. }
  1244. }
  1245. $result['repeat']=$repeat;
  1246. $result['success']=$success;
  1247. }else{
  1248. $studentGroup=array();
  1249. foreach ($student_info as $item){
  1250. $studentGroup[$item[$check_field]][]=$item;
  1251. }
  1252. foreach ($studentGroup as $key=>$val){
  1253. if(count($val)>1){
  1254. $repeat++;
  1255. $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=0";
  1256. }else{
  1257. $success++;
  1258. if(isset($check_data_group[$key])){
  1259. $update_temp_data[$check_data_group[$key]]=$val[0]['student_id'];
  1260. }
  1261. }
  1262. }
  1263. $noExistent=count($search_value_arr)-count($studentGroup);
  1264. if($noExistent<0) $noExistent=0;
  1265. $result['noExistent']=$noExistent;
  1266. $result['repeat']=$repeat;
  1267. $result['success']=$success;
  1268. }
  1269. }
  1270. }else{
  1271. $result['repeat']=$repeat;
  1272. $result['success']=$success;
  1273. $result['noExistent']=0;
  1274. $result['status']=1;
  1275. }
  1276. //更新检测成功的数据
  1277. if($update_temp_data || $updateSql){
  1278. $transcation = $this->sConn->beginTransaction();
  1279. try {
  1280. if($update_temp_data) {
  1281. if ($check_field == 'student_name') {
  1282. $sql = 'update import_score_temp set `student_id`= case id ';
  1283. } else {
  1284. $sql = 'update import_score_temp set `student_id`= case id ';
  1285. }
  1286. foreach ($update_temp_data as $key => $val) {
  1287. $sql .= " WHEN " . $key . " THEN '" . $val . "' ";
  1288. }
  1289. $sql .= " End ";
  1290. $sql .= " where (student_id='' or student_id is null) and exam_type=0";
  1291. $this->sConn->createCommand($sql)->execute();
  1292. }
  1293. if($updateSql){
  1294. foreach ($updateSql as $query){
  1295. $this->sConn->createCommand($query)->execute();
  1296. }
  1297. }
  1298. $transcation->commit();
  1299. $result['status']=1;
  1300. }catch (Exception $e){
  1301. $result['status']=0;
  1302. $transcation->rollback();
  1303. }
  1304. }
  1305. exit(json_encode($result));
  1306. }
  1307. //重新上传
  1308. public function actionGiveup(){
  1309. // $delSql="truncate table import_score_temp;";
  1310. $result['data']=$this->sConn->createCommand("select exam_group_id,check_field,renew from import_score_temp limit 1")->queryRow();
  1311. $delSql="delete from import_score_temp where exam_type=0 or exam_type=2;";
  1312. $this->sConn->createCommand($delSql)->execute();
  1313. $result['status']=1;
  1314. exit(json_encode($result));
  1315. }
  1316. //处理完毕,执行成绩导入
  1317. public function actionUpdate_score(){
  1318. ini_set('memory_limit','512M');
  1319. $result['status']=0;
  1320. $sql="select * from import_score_temp where student_id is not null and is_repeat=0 and exam_type=0";
  1321. $all_data=$this->sConn->createCommand($sql)->queryAll();
  1322. if(!$all_data){
  1323. $result['msg']='没有发现可导入学生成绩数据';
  1324. exit(json_encode($result));
  1325. }
  1326. $exam_group_id=$all_data[0]['exam_group_id'];
  1327. $examGroup=$this->sConn->createCommand("SELECT qxk_paper_id FROM `exam_group` where exam_group_id='".$exam_group_id."'")->queryRow();
  1328. $exam = $this->sConn->createCommand("SELECT e.exam_id,e.tpl_data,p.paper_id FROM `exam` e join paper p on e.exam_id=p.exam_id where e.exam_group_id='".$exam_group_id."'")->queryAll();
  1329. if(!$exam){
  1330. $result['msg']='考试ID不正确,请从考试列表点击上传成绩';
  1331. exit(json_encode($result));
  1332. }
  1333. $paperIds=array();
  1334. $examIds=array();
  1335. foreach ($exam as $value){
  1336. $paperIds[]=$value['paper_id'];
  1337. $examIds[]=$value['exam_id'];
  1338. }
  1339. $tpl_data=json_decode($exam[0]['tpl_data'],true);
  1340. $paper_topic_relation=$this->sConn->createCommand("select `paper_id`,`topic_id`,`order`,`score`,`type` from `paper_topic_relation` where paper_id='".$paperIds[0]."'")->queryAll();
  1341. if(!$paper_topic_relation){
  1342. $result['msg']='请关联答题卡';
  1343. exit(json_encode($result));
  1344. }
  1345. $sortPaperTopic=array();
  1346. //检测试题别名
  1347. if(isset($tpl_data['new_items'])){
  1348. foreach ($tpl_data['new_items'] as $item){
  1349. if($examGroup['qxk_paper_id']>0){
  1350. $alias[$item['id']]=$item['id'];
  1351. }else{
  1352. $alias[$item['id']]=$item['alias'];
  1353. }
  1354. }
  1355. //重新排序
  1356. foreach ($paper_topic_relation as $key =>$datum){
  1357. $sortPaperTopic[$alias[$datum['order']]]=$datum;
  1358. }
  1359. ksort($sortPaperTopic);
  1360. $sortPaperTopic=array_values($sortPaperTopic);
  1361. }else{
  1362. $sortPaperTopic=$paper_topic_relation;
  1363. }
  1364. $paper_topic_rs=array();
  1365. $scores=array();
  1366. $paperType=array();
  1367. foreach ($sortPaperTopic as $key=>$value){
  1368. $paper_topic_rs[$key]=$value['topic_id'];
  1369. $scores[$key]=$value['score'];
  1370. $paperType[$key]=$value['type'];
  1371. }
  1372. $sql='Replace INTO `student_paper_topic_rs` (`id`,`student_id`,`paper_id`,`topic_id`,`type`,`scoring`,`is_right`)VALUE ';
  1373. $deleteSql=array();
  1374. $updateSql=array();
  1375. $error=array();
  1376. $studentIds=array(); //用于检测重复
  1377. $time=time();
  1378. $uuidArr=array(); //批量uuid
  1379. $needUuidCount=count($all_data)*count($paper_topic_relation);
  1380. while ($needUuidCount>0){
  1381. $getIds=array();
  1382. if($needUuidCount>100000){
  1383. $getIds=getBatchUuid($this->schoolId,100000);
  1384. $needUuidCount-=100000;
  1385. }else{
  1386. $getIds=getBatchUuid($this->schoolId,$needUuidCount);
  1387. $needUuidCount=0;
  1388. }
  1389. $uuidArr=array_merge($uuidArr,$getIds);
  1390. }
  1391. //debug($uuidArr);
  1392. // $uuidArr=getBatchUuid($this->schoolId,$needUuidCount);
  1393. foreach($all_data as $val){
  1394. $StudentPaperRelation=$this->sConn->createCommand("select student_id,paper_id from `student_paper_relation` where student_id='".$val['student_id']."' and paper_id in(".implode(',',$paperIds).") and is_del=0")->queryRow();
  1395. if(!$StudentPaperRelation){
  1396. $error[]='学生没有参加本次考试 :'.$val['student_name'];
  1397. continue;
  1398. }
  1399. $paper_id=$StudentPaperRelation['paper_id'];
  1400. if($val['renew']==0){
  1401. $isFound=$this->sConn->createCommand("select * from student_paper_topic_rs where student_id='".$val['student_id']."' and paper_id='".$paper_id."'")->queryRow();
  1402. if($isFound){
  1403. continue; //已有成绩,跳过
  1404. }
  1405. }
  1406. $deleteSql[]="delete from `student_paper_topic_rs` where student_id='".$val['student_id']."' and paper_id='".$paper_id."' ";
  1407. $topicScoreData=json_decode($val['score_data'],true);
  1408. if($val['check_field']=='student_name'){
  1409. $topicScoreData=array_slice($topicScoreData,1);
  1410. }else{
  1411. $topicScoreData=array_slice($topicScoreData,2);
  1412. }
  1413. $score_get=0;
  1414. $lost_score=0;
  1415. $topicScoreData=array_values($topicScoreData);
  1416. $isHandle=0;
  1417. foreach($topicScoreData as $key=> $ts){
  1418. $ts=(float)$ts;
  1419. if(!$ts){
  1420. $ts=0;
  1421. }
  1422. $is_right=1;
  1423. $bcR=bccomp($ts,$scores[$key],1);
  1424. if($bcR==1 || $bcR==0){
  1425. if(!$isHandle || $paperType[$key]!=17){
  1426. $score=$scores[$key];
  1427. }
  1428. if($paperType[$key]==17){
  1429. $isHandle=1;
  1430. }
  1431. }else{
  1432. $score=$ts;
  1433. $l=bcsub($scores[$key],$ts,1);
  1434. if(!$isHandle || $paperType[$key]!=17){
  1435. $lost_score=bcadd($lost_score,$l,1);
  1436. }
  1437. if($paperType[$key]==17 && $score){
  1438. $isHandle=1;
  1439. }
  1440. $is_right=0;
  1441. }
  1442. $score_get=bcadd($score_get,$score,1);
  1443. $topic_id= $paper_topic_rs[$key];
  1444. $uuid=array_pop($uuidArr);
  1445. $valueSql[]=' ('.$uuid.','.$val['student_id'].','.$paper_id.','.$topic_id.','.$paperType[$key].','.$score.','.$is_right.') ';
  1446. }
  1447. $updateSql_t=" update `student_paper_relation` set complete_count='".$tpl_data['totals']."',`scoring`='".$score_get."',`lost_score`='".$lost_score."',is_feedback=1,feedback_time='".$time."',is_complete=1,complete_time='".$time."'";
  1448. $updateSql_t.=" where student_id='".$val['student_id']."' and paper_id='".$paper_id."' ";
  1449. $updateSql[]=$updateSql_t;
  1450. }
  1451. if($deleteSql && $updateSql && $valueSql){
  1452. $transaction = $this->sConn->beginTransaction();
  1453. try{
  1454. if($deleteSql){
  1455. foreach ($deleteSql as $dquery){
  1456. $this->sConn->createCommand($dquery)->execute();
  1457. }
  1458. if($updateSql){
  1459. foreach ($updateSql as $uquery){
  1460. $this->sConn->createCommand($uquery)->execute();
  1461. }
  1462. }
  1463. if($valueSql){
  1464. if(count($valueSql)>100){
  1465. $valueSql = array_chunk($valueSql, 10);
  1466. foreach($valueSql as $value){
  1467. $chunkSql=$sql;
  1468. $chunkSql.=implode(',',$value);
  1469. $this->sConn->createCommand($chunkSql)->execute();
  1470. }
  1471. }else{
  1472. $sql.=implode(',',$valueSql);
  1473. $this->sConn->createCommand($sql)->execute();
  1474. }
  1475. }
  1476. Exam::model()->updateAll(array('status'=>1,'upload_status'=>2,'complete_time'=>$time),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  1477. ExamGroup::model()->updateAll(array('mark_status'=>2,'status'=>2,'upload_status'=>2,'import_score_type'=>3),'exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  1478. //清理导入临时数据
  1479. // $delSql="truncate table import_score_temp;";
  1480. $delSql="delete from import_score_temp where exam_type=0;";
  1481. $this->sConn->createCommand($delSql)->execute();
  1482. $transaction->commit();
  1483. $result['status']=1;
  1484. if($error){
  1485. // Yii::app()->jump->error('导入成功,有部分学生成绩没有导入:'.implode(',',$error));
  1486. $result['msg']=implode('<br>',$error);
  1487. }else{
  1488. $result['msg']='导入成功';
  1489. }
  1490. if(Yii::app()->params['handle_log_on_off'])
  1491. {
  1492. writeFileLog(jsonEncode(array(
  1493. "exam_group_id" => 0,
  1494. "operate_project" => 'zsyas2',
  1495. "school_id" => $this->schoolId,
  1496. "title" => '新导入成绩',
  1497. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  1498. "operate_method" => $this->action,
  1499. "operate_url" => $this->getRoute(),
  1500. "operate_sql" =>'',
  1501. "operate_param" =>'',
  1502. "date"=>date('Y-m-d H:i:s')
  1503. )));
  1504. }
  1505. $conf = new RdKafka\Conf();
  1506. $conf->set('metadata.broker.list', Yii::app()->params['kafka']);
  1507. $producer = new RdKafka\Producer($conf);
  1508. $topic = $producer->newTopic("zsyte-academic-offline-generate-report");
  1509. $kafkaData=array(
  1510. 'examGroupId'=>$exam_group_id,
  1511. 'schoolId'=>$this->schoolId,
  1512. 'generateTime'=>time()*1000
  1513. );
  1514. $topic->produce(RD_KAFKA_PARTITION_UA, 0, json_encode($kafkaData));
  1515. $producer->poll(0);
  1516. $producer->flush(10000);
  1517. //发送学生端消息
  1518. $sendJsonArr=array(
  1519. 'school_id'=>$this->schoolId,
  1520. 'send_type'=>'zsyas',
  1521. 'update_type'=>0,
  1522. 'exam_group_id'=>$exam_group_id,
  1523. );
  1524. sendStudentCacheQueue($sendJsonArr);
  1525. exit(json_encode($result));
  1526. }
  1527. }catch (Exception $e) {
  1528. //如果操作失败, 数据回滚
  1529. $transaction->rollback();
  1530. // Yii::app()->jump->error('成绩导入失败,请检查后重新');
  1531. $result['msg']='成绩导入失败,请检查后重新导入';
  1532. exit(json_encode($result));
  1533. }
  1534. }else{
  1535. //没有需要重新导入的数据,清理导入临时数据
  1536. //$delSql="truncate table import_score_temp;";
  1537. $delSql="delete from import_score_temp where exam_type=0;";
  1538. $this->sConn->createCommand($delSql)->execute();
  1539. $result['status']=1;
  1540. exit(json_encode($result));
  1541. }
  1542. }
  1543. //处理重复学生
  1544. public function actionHandle_repeat(){
  1545. $page=Req::post('page');
  1546. $name_like=Req::post('name');
  1547. if(!$page) $page=1;
  1548. $pageSize=10;
  1549. $offset=($page-1)*$pageSize;
  1550. $sql="select * from import_score_temp where exam_type=0 limit 1";
  1551. $checkData=$this->sConn->createCommand($sql)->queryRow();
  1552. $check_field=$checkData['check_field'];
  1553. $sql="select count(*) as count,check_field_value,check_field from import_score_temp where is_repeat=1 and exam_type=0 group by check_field_value ";
  1554. if($name_like){
  1555. $sql.=" having check_field_value='".$name_like."'";
  1556. }
  1557. $sql.="order by count desc";
  1558. $all_data=$this->sConn->createCommand($sql)->queryAll();
  1559. if(!$all_data){
  1560. $this->redirect(Yii::app()->createUrl('record/check_excel'));
  1561. }
  1562. $repeat=array();
  1563. $total=count($all_data);
  1564. $data['total_page']=ceil($total/$pageSize);
  1565. $data['name_group']=array_slice($all_data,$offset,$pageSize);
  1566. $data['page']=$page;
  1567. if(Yii::app()->request->isAjaxRequest){
  1568. $result['status']=1;
  1569. $result['data']=$data['name_group'];
  1570. $result['total_page']=$data['total_page'];
  1571. exit(json_encode($result));
  1572. }else{
  1573. if($check_field=='student_name'){
  1574. $this->render('handle', $data);
  1575. }else{
  1576. $fileName=array(
  1577. 'student_name'=>'学生姓名',
  1578. 'userno'=>'学号',
  1579. 'student_card'=>'准考证号',
  1580. 'school_student_card'=>'学校准考证号',
  1581. 'zhixue_student_card'=>'智学网考证号',
  1582. 'id_number'=>'身份证号',
  1583. 'student_phone'=>'手机号'
  1584. );
  1585. //扩展字段
  1586. $studentExtend=$this->schoolManager->getStudentExtend();
  1587. if($studentExtend){
  1588. foreach ($studentExtend as $key=> $value){
  1589. $fileName[$key]=$value['field_mean'];
  1590. }
  1591. }
  1592. $data['fieldName']=$fileName[$check_field];
  1593. $data['check_field']=$check_field;
  1594. $this->render('handle_card', $data);
  1595. }
  1596. }
  1597. }
  1598. //处理重复考号
  1599. public function actionHandle_card(){
  1600. $fileName=array(
  1601. 'student_name'=>'学生姓名',
  1602. 'userno'=>'学号',
  1603. 'student_card'=>'准考证号',
  1604. 'school_student_card'=>'学校准考证号',
  1605. 'zhixue_student_card'=>'智学网考证号',
  1606. 'id_number'=>'身份证号',
  1607. 'student_phone'=>'手机号'
  1608. );
  1609. //扩展字段
  1610. $studentExtend=$this->schoolManager->getStudentExtend();
  1611. if($studentExtend){
  1612. foreach ($studentExtend as $key=> $value){
  1613. $fileName[$key]=$value['field_mean'];
  1614. }
  1615. }
  1616. //查询不存在的数据
  1617. $sql="select * from import_score_temp where is_repeat=1 and exam_type=0 ";
  1618. $all_data=$this->sConn->createCommand($sql)->queryAll();
  1619. $data['list']=$all_data;
  1620. $data['fieldName']=$fileName;
  1621. $this->render('handle_card',$data);
  1622. }
  1623. //处理不存在学生
  1624. public function actionHandle_existent(){
  1625. $fileName=array(
  1626. 'student_name'=>'学生姓名',
  1627. 'userno'=>'学号',
  1628. 'student_card'=>'准考证号',
  1629. 'school_student_card'=>'学校准考证号',
  1630. 'zhixue_student_card'=>'智学网考证号',
  1631. 'id_number'=>'身份证号',
  1632. 'student_phone'=>'手机号'
  1633. );
  1634. //扩展字段
  1635. $studentExtend=$this->schoolManager->getStudentExtend();
  1636. if($studentExtend){
  1637. foreach ($studentExtend as $key=> $value){
  1638. $fileName[$key]=$value['field_mean'];
  1639. }
  1640. }
  1641. //查询不存在的数据
  1642. $sql="select * from import_score_temp where is_repeat=0 and (student_id is null or student_id =0) and exam_type=0 ";
  1643. $all_data=$this->sConn->createCommand($sql)->queryAll();
  1644. if($all_data){
  1645. $data['check_field']=$all_data[0]['check_field'];
  1646. }else{
  1647. $data['check_field']='';
  1648. }
  1649. $data['list']=$all_data;
  1650. $data['fieldName']=$fileName;
  1651. $this->render('handle_existent',$data);
  1652. }
  1653. //根据名称加载重名学生
  1654. public function actionShowrepeatstudent(){
  1655. $name=Req::post('name');
  1656. $fileName=array(
  1657. 'student_name'=>'学生姓名',
  1658. 'userno'=>'学号',
  1659. 'student_card'=>'准考证号',
  1660. 'school_student_card'=>'学校准考证号',
  1661. 'zhixue_student_card'=>'智学网考证号',
  1662. 'id_number'=>'身份证号',
  1663. 'student_phone'=>'手机号'
  1664. );
  1665. //扩展字段
  1666. $studentExtend=$this->schoolManager->getStudentExtend();
  1667. if($studentExtend){
  1668. foreach ($studentExtend as $key=> $value){
  1669. $fileName[$key]=$value['field_mean'];
  1670. }
  1671. }
  1672. $classIds=array();
  1673. $sql="select * from import_score_temp where check_field_value='".$name."' and ( student_id is null or student_id =0) and exam_type=0";
  1674. $nameArr=array();
  1675. $systemStudent=array();
  1676. $numberToId=array();
  1677. $excel_data = $this->sConn->createCommand($sql)->queryAll();
  1678. if($excel_data){
  1679. $topic_score=json_decode($excel_data[0]['score_data'],true);
  1680. $check_field=$excel_data[0]['check_field'];
  1681. $excel_html='<table class="table table-striped table-bordered table-hover dataTable no-footer DTTT_selectable">';
  1682. $excel_html.='<tr>';
  1683. $excel_html.='<th>序号</th>';
  1684. $excel_html.='<th>姓名</th>';
  1685. $excel_html.='<th>班级</th>';
  1686. if($check_field=='student_name'){
  1687. $scoreArr=array_slice($topic_score,1);
  1688. $excel_html.='<th>科目总分</th>';
  1689. }else{
  1690. $excel_html.='<th>'.$fileName[$check_field].'</th>';
  1691. $excel_html.='<th>科目总分</th>';
  1692. $scoreArr=array_slice($topic_score,2);
  1693. }
  1694. for($i=1;$i<=count($scoreArr);$i++){
  1695. $excel_html.='<th>第'.$i.'题</th>';
  1696. }
  1697. $excel_html.='</tr>';
  1698. $i=1;
  1699. foreach($excel_data as $val){
  1700. $topic_score=json_decode($val['score_data'],true);
  1701. if($check_field=='student_name'){
  1702. $scoreArr=array_slice($topic_score,1);
  1703. $totalScore=$topic_score['C'];
  1704. }else{
  1705. $card_value=$val['check_field_value'];
  1706. $totalScore=$topic_score['D'];
  1707. $scoreArr=array_slice($topic_score,2);
  1708. }
  1709. $numberToId[$i]=$val['id'];
  1710. $excel_html.='<tr>';
  1711. $excel_html.='<td>'.$i.'</td>';
  1712. if(isset($card_value)){
  1713. $excel_html.='<td>'.$val['student_name'].'</td>';
  1714. $excel_html.='<td>'.$val['class_name'].'</td>';
  1715. $excel_html.='<td><input type="text" value="'.$val['check_field_value'].'" data="'.$val['check_field_value'].'" class="change_card" id="'.$val['id'].'"></td>';
  1716. }else{
  1717. $excel_html.='<td>'.$val['check_field_value'].'(原'.$val['student_name'].')</td>';
  1718. $excel_html.='<td>'.$val['class_name'].'</td>';
  1719. }
  1720. $excel_html.='<td>'.$totalScore.'</td>';
  1721. foreach($scoreArr as $v){
  1722. $excel_html.='<td>'.$v.'</td>';
  1723. }
  1724. $excel_html.='</tr>';
  1725. $i++;
  1726. }
  1727. $excel_html.='</table>';
  1728. $exam_group_data = $this->sConn->createCommand("SELECT e.exam_id,e.tpl_data,p.paper_id FROM `exam` e join paper p on e.exam_id=p.exam_id where e.exam_group_id='".$excel_data[0]['exam_group_id']."'")->queryAll();
  1729. $paperIds=array();
  1730. if($exam_group_data){
  1731. foreach ($exam_group_data as $v){
  1732. $paperIds[]=$v['paper_id'];
  1733. }
  1734. }
  1735. $_allStudent=array();
  1736. if($check_field=='student_name'){
  1737. $check_field='realname';
  1738. $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 ";
  1739. $sys_sql.="LEFT JOIN class c on sc.class_id=c.class_id ";
  1740. $sys_sql.="LEFT JOIN semester s on s.semester_id=c.semester_id ";
  1741. $sys_sql.="LEFT JOIN student_paper_relation spr on sc.student_id = spr.student_id ";
  1742. $sys_sql.=" where `".$check_field."` = '".$name."' and spr.paper_id in(".implode(',',$paperIds).") and s.semester_id <>'' ";
  1743. $sys_sql.="order by end_time desc ;";
  1744. $_allStudent = $this->sConn->createCommand($sys_sql)->queryAll();
  1745. }elseif($check_field=='student_card'){
  1746. $sql="select student_id,student_card from student where student_card ='".$name."' and status=0";
  1747. $b_student=$this->conn->createCommand($sql)->queryRow();
  1748. if($b_student){
  1749. $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 ";
  1750. $sys_sql.="LEFT JOIN class c on sc.class_id=c.class_id ";
  1751. $sys_sql.="LEFT JOIN semester s on s.semester_id=c.semester_id ";
  1752. $sys_sql.="LEFT JOIN student_paper_relation spr on sc.student_id = spr.student_id ";
  1753. $sys_sql.=" where sc.student_id = '".$b_student['student_id']."' and spr.paper_id in(".implode(',',$paperIds).") and s.semester_id <>'' ";
  1754. $sys_sql.="order by end_time desc ;";
  1755. $_allStudent = $this->sConn->createCommand($sys_sql)->queryAll();
  1756. }
  1757. }elseif($check_field=='school_student_card') {
  1758. $sql = "select student_id,school_student_card from student where school_student_card ='" . $name . "'and status=0";
  1759. $b_student = $this->conn->createCommand($sql)->queryRow();
  1760. if ($b_student) {
  1761. $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 ";
  1762. $sys_sql .= "LEFT JOIN class c on sc.class_id=c.class_id ";
  1763. $sys_sql .= "LEFT JOIN semester s on s.semester_id=c.semester_id ";
  1764. $sys_sql .= "LEFT JOIN student_paper_relation spr on sc.student_id = spr.student_id ";
  1765. $sys_sql .= " where sc.student_id = '" . $b_student['student_id'] . "' and spr.paper_id in(" . implode(',', $paperIds) . ") and s.semester_id <>'' ";
  1766. $sys_sql .= "order by end_time desc ;";
  1767. $_allStudent = $this->sConn->createCommand($sys_sql)->queryAll();
  1768. }
  1769. }elseif($check_field=='zhixue_student_card'){
  1770. $sql = "select student_id,zhixue_student_card from student where zhixue_student_card ='" . $name . "'and status=0";
  1771. $b_student = $this->conn->createCommand($sql)->queryRow();
  1772. if ($b_student) {
  1773. $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 ";
  1774. $sys_sql .= "LEFT JOIN class c on sc.class_id=c.class_id ";
  1775. $sys_sql .= "LEFT JOIN semester s on s.semester_id=c.semester_id ";
  1776. $sys_sql .= "LEFT JOIN student_paper_relation spr on sc.student_id = spr.student_id ";
  1777. $sys_sql .= " where sc.student_id = '" . $b_student['student_id'] . "' and spr.paper_id in(" . implode(',', $paperIds) . ") and s.semester_id <>'' ";
  1778. $sys_sql .= "order by end_time desc ;";
  1779. $_allStudent = $this->sConn->createCommand($sys_sql)->queryAll();
  1780. }
  1781. }else{
  1782. $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 ";
  1783. $sys_sql.="LEFT JOIN class c on sc.class_id=c.class_id ";
  1784. $sys_sql.="LEFT JOIN semester s on s.semester_id=c.semester_id ";
  1785. $sys_sql.="LEFT JOIN student_paper_relation spr on sc.student_id = spr.student_id ";
  1786. $sys_sql.=" where `".$check_field."` = '".$name."' and spr.paper_id in(".implode(',',$paperIds).") and s.semester_id <>'' ";
  1787. $sys_sql.="order by end_time desc ;";
  1788. $_allStudent = $this->sConn->createCommand($sys_sql)->queryAll();
  1789. }
  1790. $nameArr=array();
  1791. $studentData=array();
  1792. $businessData=array();
  1793. $semester=array();
  1794. $studentId=array();
  1795. $html='';
  1796. if($_allStudent){
  1797. foreach ($_allStudent as $val){
  1798. $val['serial_number']=0;
  1799. $val['userno']=0;
  1800. //班级信息
  1801. $sql_class_relation="select * from student_class_relation where student_id='".$val['student_id']."' and status=0 ";
  1802. $student_class_realtion=$this->sConn->createCommand($sql_class_relation)->queryRow();
  1803. if($student_class_realtion){
  1804. $val['serial_number']=$student_class_realtion['serial_number'];
  1805. $val['userno']=$student_class_realtion['userno'];
  1806. }else{
  1807. continue;
  1808. }
  1809. //查询副号
  1810. $sql_fuhao="select * from student_relation where find_in_set('".$val['student_id']."',relation_student_id)";
  1811. $student_fuhao=$this->sConn->createCommand($sql_fuhao)->queryRow();
  1812. $val['fuhao']=0;
  1813. if($student_fuhao){
  1814. if($val['student_id']!=$student_fuhao['master_student_id']){
  1815. continue;
  1816. }else{
  1817. $fuhao_arr=explode(',',$student_fuhao['relation_student_id']);
  1818. $val['fuhao']=count($fuhao_arr)-1;
  1819. }
  1820. }
  1821. $studentData[$val['semester_id']][]=$val;
  1822. $semester[$val['semester_id']]=$val['semester_name'];
  1823. $studentId[]=$val['student_id'];
  1824. }
  1825. //查询business
  1826. $criteria = new CDbCriteria();
  1827. $b_student = array();
  1828. $criteria->addInCondition('student_id',$studentId);
  1829. $b_student_data = BusinessStudent::model()->findAll($criteria);
  1830. if($b_student_data){
  1831. foreach($b_student_data as $v)
  1832. {
  1833. $businessData[$v->student_id]=array(
  1834. 'username'=>$v->username,
  1835. 'student_card'=>$v->student_card,
  1836. 'school_student_card'=>$v->school_student_card,
  1837. 'zhixue_student_card'=>$v->zhixue_student_card,
  1838. );
  1839. }
  1840. }
  1841. $i=1;
  1842. $currSemester = $this->schoolManager->getCurrSemester();
  1843. $smid=$currSemester['semester_id'];
  1844. foreach ($semester as $key=> $val){
  1845. $semesterStatus='非当前学期';
  1846. if($smid==$key){
  1847. $semesterStatus='当前学期';
  1848. }
  1849. $html.='<div class="handel-term-list">';
  1850. $html.='<div class="term-name fw"></div>';
  1851. $html.='<div class="relative flex">';
  1852. $html.='<img src="/images/prev-arrow.png" alt="" class="prev-arrow arrow-img pointer">';
  1853. $html.='<div class="term-card-layout flex-one" >';
  1854. $html.='<ul class="term-card-detail">';
  1855. if(isset($studentData[$key])){
  1856. // debug($studentData[$key]);
  1857. foreach ($studentData[$key] as $item){
  1858. $isZj='是';
  1859. if($item['is_outer']==1){
  1860. $isZj='否';
  1861. }
  1862. $html.='<li class="term-card-list" id="'.$item['student_id'].'" draggable="true" >';
  1863. $html.='<div class="padding-layout">';
  1864. $html.='<div class="card-lis-data flex">';
  1865. $html.='<div class="card_select">';
  1866. $html.='<select class="nToId"><option value="0">请选择序号</option>';
  1867. foreach ($numberToId as $number=>$Id){
  1868. $html.='<option value="'.$Id.'">'.$number.'</option>';
  1869. }
  1870. $html.='</select>';
  1871. $html.='</div>';
  1872. $html.='</div>';
  1873. $html.='<div class="card-lis-data flex">';
  1874. $html.='<span class="card-list-menu gray-font">姓名</span>';
  1875. $html.='<span class="card-list-msg flex-one">'.$item['realname'].'</span>';
  1876. $html.='</div>';
  1877. $html.='<div class="card-lis-data flex">';
  1878. $html.='<span class="card-list-menu gray-font">班级</span>';
  1879. $html.='<span class="card-list-msg flex-one">'.$item['class_name'].'</span>';
  1880. $html.='</div>';
  1881. $html.='<div class="hide-list">';
  1882. $html.='<div class="card-lis-data flex">';
  1883. $html.='<span class="card-list-menu gray-font">学期</span>';
  1884. $html.='<span class="card-list-msg flex-one">'.$val.'</span>';
  1885. $html.='</div>';
  1886. $html.='<div class="card-lis-data flex">';
  1887. $html.='<span class="card-list-menu gray-font">学期状态</span>';
  1888. $html.='<span class="card-list-msg flex-one">'.$semesterStatus.'</span>';
  1889. $html.='</div>';
  1890. $html.='<div class="card-lis-data flex">';
  1891. $html.='<span class="card-list-menu gray-font">班级序号</span>';
  1892. $html.='<span class="card-list-msg flex-one">'.$item['serial_number'].'</span>';
  1893. $html.='</div>';
  1894. $html.='<div class="card-lis-data flex">';
  1895. $html.='<span class="card-list-menu gray-font">学号</span>';
  1896. $html.='<span class="card-list-msg flex-one">'.$item['userno'].'</span>';
  1897. $html.='</div>';
  1898. $html.='<div class="card-lis-data flex">';
  1899. $html.='<span class="card-list-menu gray-font">登录账号</span>';
  1900. if(isset($businessData[$item['student_id']])){
  1901. $html.='<span class="card-list-msg flex-one">'.$businessData[$item['student_id']]['username'].'</span>';
  1902. }else{
  1903. $html.='<span class="card-list-msg flex-one"></span>';
  1904. }
  1905. $html.='</div>';
  1906. $html.='<div class="card-lis-data flex">';
  1907. $html.='<span class="card-list-menu gray-font">系统准考证号</span>';
  1908. if(isset($businessData[$item['student_id']])){
  1909. $html.='<span class="card-list-msg flex-one">'.$businessData[$item['student_id']]['student_card'].'</span>';
  1910. }else{
  1911. $html.='<span class="card-list-msg flex-one"></span>';
  1912. }
  1913. $html.='</div>';
  1914. $html.='<div class="card-lis-data flex">';
  1915. $html.='<span class="card-list-menu gray-font">学校准考证号</span>';
  1916. if(isset($businessData[$item['student_id']])){
  1917. $html.='<span class="card-list-msg flex-one">'.$businessData[$item['student_id']]['school_student_card'].'</span>';
  1918. }else{
  1919. $html.='<span class="card-list-msg flex-one"></span>';
  1920. }
  1921. $html.='</div>';
  1922. $html.='<div class="card-lis-data flex">';
  1923. $html.='<span class="card-list-menu gray-font">智学网考号</span>';
  1924. if(isset($businessData[$item['student_id']])){
  1925. $html.='<span class="card-list-msg flex-one">'.$businessData[$item['student_id']]['zhixue_student_card'].'</span>';
  1926. }else{
  1927. $html.='<span class="card-list-msg flex-one"></span>';
  1928. }
  1929. $html.='</div>';
  1930. $html.='<div class="card-lis-data flex">';
  1931. $html.='<span class="card-list-menu gray-font">身份证号</span>';
  1932. $html.='<span class="card-list-msg flex-one">'.$item['id_number'].'</span>';
  1933. $html.='</div>';
  1934. $html.='<div class="card-lis-data flex">';
  1935. $html.='<span class="card-list-menu gray-font">是否为在籍生</span>';
  1936. $html.='<span class="card-list-msg flex-one">'.$isZj.'</span>';
  1937. $html.='</div>';
  1938. $html.='<div class="card-lis-data flex">';
  1939. $html.='<span class="card-list-menu gray-font">历史考试成绩</span>';
  1940. $html.='<span rel="'.$item['student_id'].'" class="card-list-msg flex-one browse-history green-font">查看</span>';
  1941. $html.='</div>';
  1942. $html.='<div class="card-lis-data flex">';
  1943. $html.='<span class="card-list-menu gray-font">副号</span>';
  1944. $html.='<span rel="'.$item['student_id'].'" class="card-list-msg flex-one green-font pointer fuhao-lock">'.$item['fuhao'].'</span>';
  1945. $html.='</div>';
  1946. $html.='</div>';
  1947. $html.='<span class="toggle-opt-btn green-font pointer">展开</span>';
  1948. $html.='</div>';
  1949. $html.='</li>';
  1950. $i++;
  1951. }
  1952. }
  1953. $html.='</ul>';
  1954. $html.='</div>';
  1955. $html.='<img src="/images/next-arrow.png" alt="" class="next-arrow arrow-img pointer">';
  1956. $html.='</div>';
  1957. $html.='</div>';
  1958. }
  1959. }
  1960. }
  1961. $result['html']=$html;
  1962. $result['excel_html']=$excel_html;
  1963. $result['status']=1;
  1964. exit(json_encode($result));
  1965. }
  1966. //绑定学生id
  1967. public function actionBinding(){
  1968. $str=Req::post('str');
  1969. $result['status']=0;
  1970. if(!$str || !is_array($str)){
  1971. exit(json_encode($result));
  1972. }
  1973. $studentIds=array();
  1974. $tempIds=array();
  1975. foreach($str as $val){
  1976. @$nToId=explode('///',$val);
  1977. if(isset($nToId[0])){
  1978. if(in_array((string)$nToId[0],$studentIds,true)){
  1979. $result['msg']='不能学生重复选择';
  1980. exit(json_encode($result));
  1981. }else{
  1982. $studentIds[]=(string)$nToId[0];
  1983. }
  1984. }
  1985. if(isset($nToId[1])){
  1986. if(in_array((string)$nToId[1],$tempIds,true)){
  1987. $result['msg']='不能学生重复选择';
  1988. exit(json_encode($result));
  1989. }else{
  1990. $tempIds[]=(string)$nToId[1];
  1991. }
  1992. }
  1993. }
  1994. $updateSql=array();
  1995. foreach($str as $val){
  1996. @$nToId=explode('///',$val);
  1997. if(isset($nToId[0]) && isset($nToId[1])){
  1998. //判断学生id是否已关联过
  1999. $related=$this->sConn->createCommand("select id from import_score_temp where student_id='".$nToId[0]."' and exam_type=0 limit 1")->queryRow();
  2000. if($related){
  2001. $result['msg']='学生已经被关联,请重新检查';
  2002. exit(json_encode($result));
  2003. }
  2004. $updateSql[]="update import_score_temp set student_id='".$nToId[0]."',is_repeat=0 where id='".$nToId[1]."' and exam_type=0";
  2005. }
  2006. }
  2007. if($updateSql){
  2008. foreach($updateSql as $query){
  2009. $this->sConn->createCommand($query)->execute();
  2010. }
  2011. $result['status']=1;
  2012. }
  2013. exit(json_encode($result));
  2014. }
  2015. //修改不存在的学生数据
  2016. public function actionChange_value(){
  2017. $id=Req::post('id');
  2018. $value=Req::post('value');
  2019. $result['status']=0;
  2020. if(!$id || !$value){
  2021. $result['msg']='参数不正确';
  2022. exit(json_encode($result));
  2023. }
  2024. $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";
  2025. $data=$this->sConn->createCommand($sql)->queryRow();
  2026. if(!$data){
  2027. $result['msg']='id不正确';
  2028. exit(json_encode($result));
  2029. }
  2030. $check_field=$data['check_field'];
  2031. //excel中是否有重复数据
  2032. $excelCheck="select id from import_score_temp where check_field_value='".$value."' and exam_type=0 ";
  2033. $excelCheckData=$this->sConn->createCommand($excelCheck)->queryRow();
  2034. if($excelCheckData){
  2035. $result['msg']='excel中已存在相同记录';
  2036. if($check_field=='student_name'){
  2037. $result['status']=1;
  2038. $updateSql="update import_score_temp set `is_repeat`=1,check_field_value='{$value}' where (id={$id} or check_field_value='{$value}') and exam_type=0";
  2039. $this->sConn->createCommand($updateSql)->execute();
  2040. $result['msg']='excel中已存在相同记录,请返回检测页面,继续处理重名';
  2041. }
  2042. exit(json_encode($result));
  2043. }
  2044. //系统中是否有数据
  2045. $exam_group_id=$data['exam_group_id'];
  2046. $exam_group_data = $this->sConn->createCommand("SELECT e.exam_id,e.tpl_data,p.paper_id,e.class_id FROM `exam` e join paper p on e.exam_id=p.exam_id where e.exam_group_id='".$exam_group_id."'")->queryAll();
  2047. if(!$exam_group_data){
  2048. $result['status']=0; //还有重复数据,需要继续处理
  2049. exit(json_encode($result));
  2050. }
  2051. $paperIds=array();
  2052. $examIds=array();
  2053. $classIds=array();
  2054. foreach ($exam_group_data as $val){
  2055. $paperIds[]=$val['paper_id'];
  2056. $examIds[]=$val['exam_id'];
  2057. $classIds[]=$val['class_id'];
  2058. }
  2059. if($exam_group_data){
  2060. $student_info=array();
  2061. switch ($check_field){
  2062. case 'student_name':
  2063. $sql="select si.student_id,si.realname from student_info si join student_paper_relation spr on si.student_id = spr.student_id where realname ='".$value."' and paper_id in(".implode(',',$paperIds).")";
  2064. $student_info=$this->sConn->createCommand($sql)->queryAll();
  2065. break;
  2066. case 'userno':
  2067. $sql="select userno,spr.student_id from student_info si ";
  2068. $sql.="join student_class_relation scr on scr.student_id=si.student_id ";
  2069. $sql.="join student_paper_relation spr on si.student_id = spr.student_id ";
  2070. $sql.=" where sscr.userno ='".$value."' and scr.status=0 and scr.class_id in(".implode(',',$classIds).") and spr.paper_id in(".implode(',',$paperIds).")";
  2071. $student_info=$this->sConn->createCommand($sql)->queryAll();
  2072. break;
  2073. case 'student_card':
  2074. $sql="select student_id,student_card from student where student_card ='".$value."' and status=0";
  2075. $b_student=$this->conn->createCommand($sql)->queryAll();
  2076. break;
  2077. case 'school_student_card':
  2078. $sql="select student_id,school_student_card from student where school_student_card='".$value."' and status=0";
  2079. $b_student=$this->conn->createCommand($sql)->queryAll();
  2080. break;
  2081. case 'zhixue_student_card':
  2082. $sql="select student_id,zhixue_student_card from student where zhixue_student_card='".$value."' and status=0";
  2083. $b_student=$this->conn->createCommand($sql)->queryAll();
  2084. break;
  2085. default:
  2086. $sql="select * from student_info si join student_paper_relation spr on si.student_id = spr.student_id where `".$check_field."` ='".$value."' and paper_id in(".implode(',',$paperIds).") ";
  2087. $student_info=$this->sConn->createCommand($sql)->queryAll();
  2088. }
  2089. if(isset($b_student) && $b_student){
  2090. $studentIds=array();
  2091. foreach ($b_student as $item){
  2092. $studentIds[]=$item['student_id'];
  2093. }
  2094. $sql="select si.student_id,si.realname from student_info si join student_paper_relation spr on si.student_id = spr.student_id where si.student_id in(".implode(',',$studentIds).") and paper_id in(".implode(',',$paperIds).")";
  2095. $student_info=$this->sConn->createCommand($sql)->queryAll();
  2096. }
  2097. if(!$student_info){
  2098. $result['msg']='系统中不存在,或学生没有参加该次考试';
  2099. exit(json_encode($result));
  2100. }elseif(count($student_info)>1){
  2101. $updateSql="update import_score_temp set `is_repeat`=1,check_field_value='{$value}' where id={$id}";
  2102. $this->sConn->createCommand($updateSql)->execute();
  2103. $result['msg']='系统中存在多个该学生数据,请返回检测页面,继续处理重名';
  2104. exit(json_encode($result));
  2105. }else{
  2106. $result['status']=1;
  2107. $studentId=$student_info[0]['student_id'];
  2108. //查询是否参加考试
  2109. $StudentPaperRelation=$this->sConn->createCommand("select student_id,paper_id from `student_paper_relation` where student_id='".$studentId."' and paper_id in(".implode(',',$paperIds).")")->queryRow();
  2110. if(!$StudentPaperRelation){
  2111. $result['status']=1;
  2112. $result['msg']='学生没有参加本次考试';
  2113. exit(json_encode($result));
  2114. }
  2115. //判断学生id是否已关联过
  2116. $related=$this->sConn->createCommand("select id from import_score_temp where student_id='".$studentId."' and exam_type=0 limit 1")->queryRow();
  2117. if($related){
  2118. $result['msg']='学生已经被关联,请重新检查';
  2119. exit(json_encode($result));
  2120. }
  2121. $updateSql="update import_score_temp set student_id='{$studentId}',check_field_value='{$value}',is_repeat=0 where id={$id}";
  2122. $this->sConn->createCommand($updateSql)->execute();
  2123. exit(json_encode($result));
  2124. }
  2125. }else{
  2126. $result['msg']='考试数据有误';
  2127. exit(json_encode($result));
  2128. }
  2129. }
  2130. //修改后确认
  2131. public function actionChange_check(){
  2132. $check_value=Req::post('check_value');
  2133. $result['status']=0;
  2134. if(!$check_value){
  2135. exit(json_encode($result));
  2136. }
  2137. $sql="select id,student_name,class_name,check_field_value,score_data,exam_group_id,check_field,renew,student_id,is_repeat from import_score_temp where check_field_value='".$check_value."' and is_repeat=1 and exam_type=0";
  2138. $student_info=$this->sConn->createCommand($sql)->queryAll();
  2139. if(!$student_info){
  2140. $result['status']=1; //没有数据,处理完毕
  2141. exit(json_encode($result));
  2142. }elseif(count($student_info)>1){
  2143. $result['status']=0; //还有重复数据,需要继续处理
  2144. exit(json_encode($result));
  2145. }else{
  2146. //只剩一条,查询
  2147. $data=$student_info[0];
  2148. $check_field=$data['check_field'];
  2149. $id=$data['id'];
  2150. //系统中是否有数据
  2151. $exam_group_id=$data['exam_group_id'];
  2152. $exam_group_data = $this->sConn->createCommand("SELECT e.exam_id,e.tpl_data,p.paper_id,e.class_id FROM `exam` e join paper p on e.exam_id=p.exam_id where e.exam_group_id='".$exam_group_id."'")->queryAll();
  2153. if(!$exam_group_data){
  2154. $result['status']=0; //还有重复数据,需要继续处理
  2155. exit(json_encode($result));
  2156. }
  2157. $paperIds=array();
  2158. $examIds=array();
  2159. $classIds=array();
  2160. foreach ($exam_group_data as $value){
  2161. $paperIds[]=$value['paper_id'];
  2162. $examIds[]=$value['exam_id'];
  2163. $classIds[]=$value['class_id'];
  2164. }
  2165. if($exam_group_data){
  2166. $student_info=array();
  2167. switch ($check_field){
  2168. case 'student_name':
  2169. $sql="select student_id,realname from student_info where realname ='".$check_value."' and class_id in(".implode(',',$classIds).")";
  2170. $student_info=$this->sConn->createCommand($sql)->queryAll();
  2171. break;
  2172. case 'userno':
  2173. $sql="select userno,student_id from student_info si ";
  2174. $sql.="join student_class_relation scr on scr.student_id=si.student_id ";
  2175. $sql.=" where scr.userno ='".$check_value."' and scr.status=0 and scr.class_id in(".implode(',',$classIds).")";
  2176. $student_info=$this->sConn->createCommand($sql)->queryAll();
  2177. break;
  2178. case 'student_card':
  2179. $sql="select student_id,student_card from student where student_card ='".$check_value."' and status=0";
  2180. $b_student=$this->conn->createCommand($sql)->queryAll();
  2181. break;
  2182. case 'school_student_card':
  2183. $sql="select student_id,school_student_card from student where school_student_card='".$check_value."' and status=0";
  2184. $b_student=$this->conn->createCommand($sql)->queryAll();
  2185. break;
  2186. case 'zhixue_student_card':
  2187. $sql="select student_id,zhixue_student_card from student where zhixue_student_card ='".$check_value."' and status=0";
  2188. $b_student=$this->conn->createCommand($sql)->queryAll();
  2189. break;
  2190. default:
  2191. $sql="select * from student_info where `".$check_field."` ='".$check_value."' and class_id in(".implode(',',$classIds).")";
  2192. $student_info=$this->sConn->createCommand($sql)->queryAll();
  2193. }
  2194. if(isset($b_student) && $b_student){
  2195. $studentIds=array();
  2196. foreach ($b_student as $item){
  2197. $studentIds[]=$item['student_id'];
  2198. }
  2199. $sql="select student_id from student_info where student_id in(".implode(',',$studentIds).") and class_id in(".implode(',',$classIds).")";
  2200. $student_info=$this->sConn->createCommand($sql)->queryAll();
  2201. }
  2202. if(!$student_info){
  2203. $updateSql="update import_score_temp set is_repeat=0,student_id='' where id={$id}";
  2204. $this->sConn->createCommand($updateSql)->execute();
  2205. $result['msg']='还有系统中不存在,或没有参加本次考试的数据,需要继续处理';
  2206. $result['status']=0;
  2207. exit(json_encode($result));
  2208. }elseif(count($student_info)>1){
  2209. $result['msg']='系统中存在多个该学生数据,请检查后重新填写';
  2210. $result['status']=0;
  2211. exit(json_encode($result));
  2212. }else{
  2213. $result['status']=1;
  2214. $studentId=$student_info[0]['student_id'];
  2215. //查询是否参加考试
  2216. $StudentPaperRelation=$this->sConn->createCommand("select student_id,paper_id from `student_paper_relation` where student_id='".$studentId."' and paper_id in(".implode(',',$paperIds).")")->queryRow();
  2217. if(!$StudentPaperRelation){
  2218. $result['status']=1;
  2219. $result['msg']='学生没有参加本次考试';
  2220. exit(json_encode($result));
  2221. }
  2222. //判断学生id是否已关联过
  2223. $related=$this->sConn->createCommand("select id from import_score_temp where student_id='".$studentId."' limit 1")->queryRow();
  2224. if($related){
  2225. $result['status']=0;
  2226. $result['msg']='需要继续处理';
  2227. exit(json_encode($result));
  2228. }else{
  2229. $updateSql="update import_score_temp set student_id='{$studentId}',is_repeat=0 where id={$id}";
  2230. $this->sConn->createCommand($updateSql)->execute();
  2231. exit(json_encode($result));
  2232. }
  2233. }
  2234. }else{
  2235. $result['msg']='考试数据有误';
  2236. exit(json_encode($result));
  2237. }
  2238. }
  2239. }
  2240. /*导入学生答题图片*/
  2241. //导入图片,导入表格
  2242. public function actionImportStudentExcel(){
  2243. ini_set ('memory_limit', '300M');
  2244. if(!$_FILES){
  2245. Yii::app()->jump->error('文件大小超过范围');
  2246. }else{
  2247. if(!isset($_FILES['exname']) || !isset($_FILES['exname']['size']) || $_FILES['exname']['size'] > 5242880){
  2248. Yii::app()->jump->error('文件大小超过范围');
  2249. }
  2250. }
  2251. if (Yii::app()->request->getIsPostRequest()) {
  2252. $exam_group_id=Req::post('exam_group_id');
  2253. $check_field=Req::post('check_field');
  2254. $exam_renew=Req::post('exam_renew');
  2255. if(!$exam_group_id)
  2256. {
  2257. Yii::app()->jump->error('请选择考试信息');
  2258. }
  2259. $uploader = new Uploader("upload/tmpDir/zhixue_chengji/{$this->schoolId}/");
  2260. $uploader->allowTypes = array("xls","xlsx");
  2261. $uploader->fieldsMappings = array("exnameYwy" => array(0 => $this->schoolId . date('Ymdhis', time())));
  2262. $file = $uploader->act();
  2263. $file = Arr::current(Arr::current($file));
  2264. if (!$file || !isset($file["error"]))
  2265. Yii::app()->jump->error('请上传的Excel!');
  2266. if ($file["error"] != 0) {
  2267. switch ($file["error"]) {
  2268. case 2001:
  2269. Yii::app()->jump->error('文件类型不符');
  2270. break;
  2271. case 2002:
  2272. Yii::app()->jump->error('文件大小超出允许范围');
  2273. break;
  2274. default:
  2275. Yii::app()->jump->error('上传失败');
  2276. break;
  2277. }
  2278. }
  2279. $inputFileName = $file["src"];
  2280. // 导入PHPExcel类
  2281. Yii::import('application.extensions.*');
  2282. require_once('phpexcel/PHPExcel/IOFactory.php');
  2283. try{
  2284. $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
  2285. $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
  2286. // FIXME 20191202
  2287. @unlink($file["src"]);
  2288. }catch (Exception $e){
  2289. // FIXME 20191202
  2290. @unlink($file["src"]);
  2291. Yii::app()->jump->error('Excel格式不正确:'.$e->getMessage());
  2292. }
  2293. if(!$sheetData)
  2294. {
  2295. Yii::app()->jump->error('请正确的Excel!');
  2296. }
  2297. unset($objPHPExcel);
  2298. unset($sheetData[1]);
  2299. if(!$sheetData)
  2300. {
  2301. Yii::app()->jump->error('请输入学生图片数据');
  2302. }
  2303. $insertSql="insert into import_score_temp(`student_name`,`class_name`,`check_field_value`,`score_data`,`exam_group_id`,`check_field`,`renew`,`exam_type`) values";
  2304. $valuesArray=array();
  2305. foreach ($sheetData as $val){
  2306. if(!isset($val['A']) || !isset($val['B']) || !isset($val['C']) ){
  2307. continue;
  2308. }
  2309. $student_topic=array_slice($val,2);
  2310. $regex = '/^[a-zA-Z0-9]+$/u';
  2311. if($check_field=='student_name'){
  2312. //$student_topic=array_slice($val,2);
  2313. }else{
  2314. $check_field_value=$val['C'];
  2315. if(!preg_match($regex, $check_field_value)){
  2316. Yii::app()->jump->error('识别考号内容只能是数字和字母');
  2317. }
  2318. }
  2319. if($check_field=='student_name'){
  2320. $valuesArray[]="('".$val['A']."','".$val['B']."','','".json_encode($student_topic)."','".$exam_group_id."','".$check_field."','".$exam_renew."',2)";
  2321. }else{
  2322. $valuesArray[]="('".$val['A']."','".$val['B']."','".$val['C']."','".json_encode($student_topic)."','".$exam_group_id."','".$check_field."','".$exam_renew."',2)";
  2323. }
  2324. }
  2325. if($valuesArray){
  2326. // $delSql="truncate table import_score_temp;";
  2327. $delSql="delete from import_score_temp;";
  2328. $this->sConn->createCommand($delSql)->execute();
  2329. $insertSql.=implode(',',$valuesArray);
  2330. $this->sConn->createCommand($insertSql)->execute();
  2331. $this->redirect(Yii::app()->createUrl('record/checkImgExcel'));
  2332. }else{
  2333. Yii::app()->jump->error('没有发现学生图片数据');
  2334. }
  2335. Yii::app()->jump->error('导入失败');
  2336. }
  2337. }
  2338. //导入图片检测页
  2339. public function actionCheckImgExcel(){
  2340. $sql="select * from import_score_temp where exam_type=2 limit 1";
  2341. $data=$this->sConn->createCommand($sql)->queryRow();
  2342. $fileName=array(
  2343. 'student_name'=>'学生姓名',
  2344. 'userno'=>'学号',
  2345. 'student_card'=>'准考证号',
  2346. 'school_student_card'=>'学校准考证号',
  2347. 'zhixue_student_card'=>'智学网考证号',
  2348. 'id_number'=>'身份证号',
  2349. 'student_phone'=>'手机号'
  2350. );
  2351. //扩展字段
  2352. $studentExtend=$this->schoolManager->getStudentExtend();
  2353. if($studentExtend){
  2354. foreach ($studentExtend as $key=> $value){
  2355. $fileName[$key]=$value['field_mean'];
  2356. }
  2357. }
  2358. if(isset($fileName[$data['check_field']])){
  2359. $data['check_field_name']=$fileName[$data['check_field']];
  2360. }else{
  2361. $data['check_field_name']='学生姓名';
  2362. }
  2363. $data['need_check_name']=0;
  2364. if($data['check_field_name']=='学生姓名'){
  2365. $data['need_check_name']=1;
  2366. }
  2367. $this->render('check_img',$data);
  2368. }
  2369. //检测导入图片数据格式
  2370. public function actionCheck_img_field_first(){
  2371. $result['status']=0;
  2372. $sql="select * from import_score_temp where exam_type=2";
  2373. $All_Data=$this->sConn->createCommand($sql)->queryAll();
  2374. if(!$All_Data){
  2375. exit(json_encode($result));
  2376. }
  2377. $data=$All_Data[0];
  2378. $check_field=$data['check_field'];
  2379. $score_data=json_decode($data['score_data'],true);
  2380. $exam_group_id=$data['exam_group_id'];
  2381. if(!$score_data){
  2382. $result['msg']='数据不完整';
  2383. exit(json_encode($result));
  2384. }
  2385. //检测题量
  2386. $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  2387. if($exam_group_data) {
  2388. foreach ($exam_group_data as $v) {
  2389. $exam_id = $v->exam_id;
  2390. $tpl_data = json_decode($v->tpl_data, 1);
  2391. }
  2392. unset($exam_group_data);
  2393. $paper_data = SPaper::model()->find('exam_id=:exam_id', array(':exam_id' => $exam_id));
  2394. $paper_topic_data = SPaperTopicRelation::model()->findAll(array('order'=>'`no` asc','condition'=>'paper_id=:paper_id','params'=>array(':paper_id'=>$paper_data->paper_id)));
  2395. if(!$paper_topic_data){
  2396. $result['msg']='请先关联答题卡再上传成绩';
  2397. exit(json_encode($result));
  2398. }
  2399. //判断是否上传成绩
  2400. //检测试题数据
  2401. foreach($All_Data as $key=> $val){
  2402. $score_data=json_decode($val['score_data'],true);
  2403. $score_data=array_slice($score_data,1);
  2404. if(count($score_data)!=count($paper_topic_data)){
  2405. $result['msg']='上传题量和试卷题量不一致:'.$val['student_name'];
  2406. exit(json_encode($result));
  2407. }
  2408. $topic_score=array_values($score_data);
  2409. foreach($topic_score as $order => $v){
  2410. if(!isset($paper_topic_data[$order])){
  2411. $result['msg']='上传题量和试卷题量不一致';
  2412. exit(json_encode($result));
  2413. }
  2414. }
  2415. }
  2416. $result['msg']='检测完成';
  2417. $result['status']=1;
  2418. }else{
  2419. $result['msg']='未发现对应考试';
  2420. exit(json_encode($result));
  2421. }
  2422. exit(json_encode($result));
  2423. }
  2424. //检测导入图片姓名
  2425. public function actionCheck_img_student_name(){
  2426. ini_set('memory_limit','512M');
  2427. set_time_limit(0);
  2428. $result['status']=0;
  2429. $result['data']=0;
  2430. $student_all_data = $this->sConn->createCommand("SELECT id,student_name FROM `import_score_temp` `t` where exam_type=2")->queryAll();
  2431. if($student_all_data){
  2432. //去除非中文字符
  2433. $updateArr=array();
  2434. $preg="/[^\x{4E00}-\x{9FFF}^·]+/u";
  2435. $count=0;
  2436. foreach($student_all_data as $val){
  2437. if(preg_match($preg,$val['student_name'])){
  2438. $ModifyName = preg_replace($preg, "", $val['student_name']);
  2439. if($ModifyName){
  2440. $updateArr[$val['id']]=$ModifyName;
  2441. $count++;
  2442. }
  2443. }else{
  2444. $updateArr[$val['id']]=$val['student_name'];
  2445. }
  2446. }
  2447. //组织更新语句
  2448. if($updateArr){
  2449. $arrNumber=ceil(count($updateArr)/500);
  2450. $Arr=array_chunk($updateArr,$arrNumber,true);
  2451. $transcation = $this->sConn->beginTransaction();
  2452. try {
  2453. foreach ($Arr as $item){
  2454. $sql='update import_score_temp set `check_field_value`= case id ';
  2455. foreach ($item as $key=> $val){
  2456. $sql.=" WHEN ".$key." THEN '".$val."' ";
  2457. }
  2458. $sql.=" End ";
  2459. $sql.=" where check_field_value='' or check_field_value is null and exam_type=0";
  2460. $this->sConn->createCommand($sql)->execute();
  2461. }
  2462. $transcation->commit();
  2463. $result['status']=1;
  2464. }catch (Exception $e){
  2465. $transcation->rollback();
  2466. }
  2467. }
  2468. $result['count']=$count;
  2469. }
  2470. exit(json_encode($result));
  2471. }
  2472. //匹配信息
  2473. public function actionMatchingImg(){
  2474. $noExistent=0; //不存在
  2475. $repeat=0; //重复(组)
  2476. $success=0; //匹配成功
  2477. $scoreWrong=0; //成绩不正确
  2478. $result['status']=0;
  2479. $sql="select * from import_score_temp where exam_type=2 limit 1";
  2480. $data=$this->sConn->createCommand($sql)->queryRow();
  2481. if(!$data){
  2482. exit(json_encode($result));
  2483. }
  2484. $check_field=$data['check_field'];
  2485. $exam_group_id=$data['exam_group_id'];
  2486. $classArr=array();
  2487. $classIds=array();
  2488. $check_data_group=array(); //检查字段对应临时表id
  2489. $update_temp_data=array(); //更新临时表数据
  2490. $student_card=array(); //学生id,准考证号对应数据
  2491. $tpl_data=array();
  2492. $updateSql=array();
  2493. $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  2494. $exam_group_data = $this->sConn->createCommand("SELECT e.exam_id,e.tpl_data,p.paper_id,e.class_id FROM `exam` e join paper p on e.exam_id=p.exam_id where e.exam_group_id='".$exam_group_id."'")->queryAll();
  2495. $paperIds=array();
  2496. if($exam_group_data){
  2497. foreach ($exam_group_data as $v){
  2498. if(!$tpl_data && isset($v['tpl_data'])){
  2499. $tpl_data=json_decode($v['tpl_data'],true);
  2500. }
  2501. $classIds[]=$v['class_id'];
  2502. $paperIds[]=$v['paper_id'];
  2503. }
  2504. }
  2505. //统计已经匹配成功的数据
  2506. $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=0 ")->queryAll();
  2507. if($success_student_data){
  2508. $success=count($success_student_data);
  2509. }
  2510. $check_field_val_arr=array();
  2511. $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=0 ")->queryAll();
  2512. if(!$student_all_data){
  2513. $result['repeat']=0;
  2514. $result['success']=$success;
  2515. $result['noExistent']=0;
  2516. $result['status']=1;
  2517. exit(json_encode($result));
  2518. }
  2519. foreach ($student_all_data as $val){
  2520. //验证学生分数
  2521. $check_field_val_arr[]="'".$val['check_field_value']."'";
  2522. $check_data_group[$val['check_field_value']]=$val['id'];
  2523. }
  2524. //处理重复数据
  2525. $repeat_group_data=array();
  2526. $search_value_arr=array();
  2527. foreach ($check_field_val_arr as $value){
  2528. $repeat_group_data[$value][]=$value;
  2529. }
  2530. foreach ($repeat_group_data as $key=>$val){
  2531. if(count($val)>1){
  2532. $repeat++;
  2533. $modify_name=str_replace("'",'',$key);
  2534. $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=2";
  2535. }else{
  2536. $search_value_arr[]=$val[0];
  2537. }
  2538. }
  2539. if($search_value_arr){
  2540. $student_info=array();
  2541. $b_student=array();
  2542. switch ($check_field){
  2543. case 'student_name':
  2544. $sql="select si.student_id,si.realname from student_info si join student_paper_relation spr on si.student_id = spr.student_id where realname in(".implode(',',$search_value_arr).") and paper_id in(".implode(',',$paperIds).")";
  2545. $student_info=$this->sConn->createCommand($sql)->queryAll();
  2546. break;
  2547. case 'userno':
  2548. $sql="select userno,spr.student_id from student_info si ";
  2549. $sql.="join student_class_relation scr on scr.student_id=si.student_id ";
  2550. $sql.="join student_paper_relation spr on si.student_id = spr.student_id ";
  2551. $sql.=" where scr.userno in(".implode(',',$search_value_arr).") and scr.status=0 and scr.class_id in(".implode(',',$classIds).") and spr.paper_id in(".implode(',',$paperIds).")";
  2552. $student_info=$this->sConn->createCommand($sql)->queryAll();
  2553. break;
  2554. case 'student_card':
  2555. $sql="select student_id,student_card from student where student_card in(".implode(',',$search_value_arr).") and status=0";
  2556. $b_student=$this->conn->createCommand($sql)->queryAll();
  2557. break;
  2558. case 'school_student_card':
  2559. $sql="select student_id,school_student_card from student where school_student_card in(".implode(',',$search_value_arr).") and status=0";
  2560. $b_student=$this->conn->createCommand($sql)->queryAll();
  2561. break;
  2562. case 'zhixue_student_card':
  2563. $sql="select student_id,zhixue_student_card from student where zhixue_student_card in(".implode(',',$search_value_arr).") and status=0";
  2564. $b_student=$this->conn->createCommand($sql)->queryAll();
  2565. break;
  2566. default:
  2567. $sql="select * from student_info si join student_paper_relation spr on si.student_id = spr.student_id where `".$check_field."` in(".implode(',',$search_value_arr).") and paper_id in(".implode(',',$paperIds).") ";
  2568. $student_info=$this->sConn->createCommand($sql)->queryAll();
  2569. }
  2570. if($b_student){
  2571. $studentIds=array();
  2572. foreach ($b_student as $item){
  2573. $studentIds[]=$item['student_id'];
  2574. $student_card[$item['student_id']]=$item[$check_field];
  2575. }
  2576. $sql="select si.student_id from student_info si join student_paper_relation spr on si.student_id = spr.student_id where si.student_id in(".implode(',',$studentIds).") and paper_id in(".implode(',',$paperIds).") ";
  2577. $student_info=$this->sConn->createCommand($sql)->queryAll();
  2578. if($student_info){
  2579. foreach($student_info as $key=>$val){
  2580. $student_info[$key][$check_field]=$student_card[$val['student_id']];
  2581. }
  2582. }
  2583. }
  2584. if(!$student_info){
  2585. $noExistent=count($search_value_arr);
  2586. $result['repeat']=$repeat;
  2587. $result['success']=$success;
  2588. $result['noExistent']=$noExistent;
  2589. $result['status']=1;
  2590. }else{
  2591. $result['status']=1;
  2592. //过滤掉已被删除的学生
  2593. foreach ($student_info as $key=>$value){
  2594. $sql_class_relation="select * from student_class_relation where student_id='".$value['student_id']."' and status=0 ";
  2595. $student_class_realtion=$this->sConn->createCommand($sql_class_relation)->queryRow();
  2596. if(!$student_class_realtion){
  2597. unset($student_info[$key]);
  2598. }
  2599. }
  2600. if($check_field=='student_name'){
  2601. $nameArr=array();
  2602. foreach ($student_info as $item){
  2603. $preg="/[^\x{4E00}-\x{9FFF}^·]+/u";
  2604. $ModifyName = preg_replace($preg, "", $item['realname']);
  2605. $nameArr[$ModifyName][]=$item;
  2606. }
  2607. $noExistent=count($search_value_arr)-count($nameArr);
  2608. if($noExistent<0) $noExistent=0;
  2609. $result['noExistent']=$noExistent;
  2610. foreach ($nameArr as $key=>$value){
  2611. if(count($value)>1){
  2612. $repeat++;
  2613. $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=2";
  2614. }else{
  2615. $success++;
  2616. if(isset($check_data_group[$key])){
  2617. $update_temp_data[$check_data_group[$key]]=$value[0]['student_id'];
  2618. }
  2619. }
  2620. }
  2621. $result['repeat']=$repeat;
  2622. $result['success']=$success;
  2623. }else{
  2624. $studentGroup=array();
  2625. foreach ($student_info as $item){
  2626. $studentGroup[$item[$check_field]][]=$item;
  2627. }
  2628. foreach ($studentGroup as $key=>$val){
  2629. if(count($val)>1){
  2630. $repeat++;
  2631. $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=2";
  2632. }else{
  2633. $success++;
  2634. if(isset($check_data_group[$key])){
  2635. $update_temp_data[$check_data_group[$key]]=$val[0]['student_id'];
  2636. }
  2637. }
  2638. }
  2639. $noExistent=count($search_value_arr)-count($studentGroup);
  2640. if($noExistent<0) $noExistent=0;
  2641. $result['noExistent']=$noExistent;
  2642. $result['repeat']=$repeat;
  2643. $result['success']=$success;
  2644. }
  2645. }
  2646. }else{
  2647. $result['repeat']=$repeat;
  2648. $result['success']=$success;
  2649. $result['noExistent']=0;
  2650. $result['status']=1;
  2651. }
  2652. //更新检测成功的数据
  2653. if($update_temp_data || $updateSql){
  2654. $transcation = $this->sConn->beginTransaction();
  2655. try {
  2656. if($update_temp_data) {
  2657. if ($check_field == 'student_name') {
  2658. $sql = 'update import_score_temp set `student_id`= case id ';
  2659. } else {
  2660. $sql = 'update import_score_temp set `student_id`= case id ';
  2661. }
  2662. foreach ($update_temp_data as $key => $val) {
  2663. $sql .= " WHEN " . $key . " THEN '" . $val . "' ";
  2664. }
  2665. $sql .= " End ";
  2666. $sql .= " where (student_id='' or student_id is null) and exam_type=2";
  2667. $this->sConn->createCommand($sql)->execute();
  2668. }
  2669. if($updateSql){
  2670. foreach ($updateSql as $query){
  2671. $this->sConn->createCommand($query)->execute();
  2672. }
  2673. }
  2674. $transcation->commit();
  2675. $result['status']=1;
  2676. }catch (Exception $e){
  2677. $result['status']=0;
  2678. $transcation->rollback();
  2679. }
  2680. }
  2681. exit(json_encode($result));
  2682. }
  2683. //处理重复学生
  2684. public function actionHandle_repeat_img(){
  2685. $page=Req::post('page');
  2686. $name_like=Req::post('name');
  2687. if(!$page) $page=1;
  2688. $pageSize=10;
  2689. $offset=($page-1)*$pageSize;
  2690. $sql="select * from import_score_temp where exam_type=2 limit 1";
  2691. $checkData=$this->sConn->createCommand($sql)->queryRow();
  2692. $check_field=$checkData['check_field'];
  2693. $sql="select count(*) as count,check_field_value,check_field from import_score_temp where is_repeat=1 and exam_type=2 group by check_field_value ";
  2694. if($name_like){
  2695. $sql.=" having check_field_value='".$name_like."'";
  2696. }
  2697. $sql.="order by count desc";
  2698. $all_data=$this->sConn->createCommand($sql)->queryAll();
  2699. if(!$all_data){
  2700. $this->redirect(Yii::app()->createUrl('record/checkImgExcel'));
  2701. }
  2702. $repeat=array();
  2703. $total=count($all_data);
  2704. $data['total_page']=ceil($total/$pageSize);
  2705. $data['name_group']=array_slice($all_data,$offset,$pageSize);
  2706. $data['page']=$page;
  2707. if(Yii::app()->request->isAjaxRequest){
  2708. $result['status']=1;
  2709. $result['data']=$data['name_group'];
  2710. $result['total_page']=$data['total_page'];
  2711. exit(json_encode($result));
  2712. }else{
  2713. if($check_field=='student_name'){
  2714. $this->render('handle', $data);
  2715. }else{
  2716. $fileName=array(
  2717. 'student_name'=>'学生姓名',
  2718. 'userno'=>'学号',
  2719. 'student_card'=>'准考证号',
  2720. 'school_student_card'=>'学校准考证号',
  2721. 'zhixue_student_card'=>'智学网考证号',
  2722. 'id_number'=>'身份证号',
  2723. 'student_phone'=>'手机号'
  2724. );
  2725. //扩展字段
  2726. $studentExtend=$this->schoolManager->getStudentExtend();
  2727. if($studentExtend){
  2728. foreach ($studentExtend as $key=> $value){
  2729. $fileName[$key]=$value['field_mean'];
  2730. }
  2731. }
  2732. $data['fieldName']=$fileName[$check_field];
  2733. $data['check_field']=$check_field;
  2734. $this->render('handle_card_img', $data);
  2735. }
  2736. }
  2737. }
  2738. //修改后确认
  2739. public function actionChange_check_img(){
  2740. $check_value=Req::post('check_value');
  2741. $result['status']=0;
  2742. if(!$check_value){
  2743. exit(json_encode($result));
  2744. }
  2745. $sql="select id,student_name,class_name,check_field_value,score_data,exam_group_id,check_field,renew,student_id,is_repeat from import_score_temp where check_field_value='".$check_value."' and is_repeat=1 and exam_type=2";
  2746. $student_info=$this->sConn->createCommand($sql)->queryAll();
  2747. if(!$student_info){
  2748. $result['status']=1; //没有数据,处理完毕
  2749. exit(json_encode($result));
  2750. }elseif(count($student_info)>1){
  2751. $result['status']=0; //还有重复数据,需要继续处理
  2752. exit(json_encode($result));
  2753. }else{
  2754. //只剩一条,查询
  2755. $data=$student_info[0];
  2756. $check_field=$data['check_field'];
  2757. $id=$data['id'];
  2758. //系统中是否有数据
  2759. $exam_group_id=$data['exam_group_id'];
  2760. $exam_group_data = $this->sConn->createCommand("SELECT e.exam_id,e.tpl_data,p.paper_id,e.class_id FROM `exam` e join paper p on e.exam_id=p.exam_id where e.exam_group_id='".$exam_group_id."'")->queryAll();
  2761. if(!$exam_group_data){
  2762. $result['status']=0; //还有重复数据,需要继续处理
  2763. exit(json_encode($result));
  2764. }
  2765. $paperIds=array();
  2766. $examIds=array();
  2767. $classIds=array();
  2768. foreach ($exam_group_data as $value){
  2769. $paperIds[]=$value['paper_id'];
  2770. $examIds[]=$value['exam_id'];
  2771. $classIds[]=$value['class_id'];
  2772. }
  2773. if($exam_group_data){
  2774. $student_info=array();
  2775. switch ($check_field){
  2776. case 'student_name':
  2777. $sql="select student_id,realname from student_info where realname ='".$check_value."' and class_id in(".implode(',',$classIds).")";
  2778. $student_info=$this->sConn->createCommand($sql)->queryAll();
  2779. break;
  2780. case 'userno':
  2781. $sql="select userno,student_id from student_info si ";
  2782. $sql.="join student_class_relation scr on scr.student_id=si.student_id ";
  2783. $sql.=" where scr.userno ='".$check_value."' and scr.status=0 and scr.class_id in(".implode(',',$classIds).")";
  2784. $student_info=$this->sConn->createCommand($sql)->queryAll();
  2785. break;
  2786. case 'student_card':
  2787. $sql="select student_id,student_card from student where student_card ='".$check_value."' and status=0";
  2788. $b_student=$this->conn->createCommand($sql)->queryAll();
  2789. break;
  2790. case 'school_student_card':
  2791. $sql="select student_id,school_student_card from student where school_student_card='".$check_value."' and status=0";
  2792. $b_student=$this->conn->createCommand($sql)->queryAll();
  2793. break;
  2794. case 'zhixue_student_card':
  2795. $sql="select student_id,zhixue_student_card from student where zhixue_student_card ='".$check_value."' and status=0";
  2796. $b_student=$this->conn->createCommand($sql)->queryAll();
  2797. break;
  2798. default:
  2799. $sql="select * from student_info where `".$check_field."` ='".$check_value."' and class_id in(".implode(',',$classIds).")";
  2800. $student_info=$this->sConn->createCommand($sql)->queryAll();
  2801. }
  2802. if(isset($b_student) && $b_student){
  2803. $studentIds=array();
  2804. foreach ($b_student as $item){
  2805. $studentIds[]=$item['student_id'];
  2806. }
  2807. $sql="select student_id from student_info where student_id in(".implode(',',$studentIds).") and class_id in(".implode(',',$classIds).")";
  2808. $student_info=$this->sConn->createCommand($sql)->queryAll();
  2809. }
  2810. if(!$student_info){
  2811. $updateSql="update import_score_temp set is_repeat=0,student_id='' where id={$id}";
  2812. $this->sConn->createCommand($updateSql)->execute();
  2813. $result['msg']='还有系统中不存在,或没有参加本次考试的数据,需要继续处理';
  2814. $result['status']=0;
  2815. exit(json_encode($result));
  2816. }elseif(count($student_info)>1){
  2817. $result['msg']='系统中存在多个该学生数据,请检查后重新填写';
  2818. $result['status']=0;
  2819. exit(json_encode($result));
  2820. }else{
  2821. $result['status']=1;
  2822. $studentId=$student_info[0]['student_id'];
  2823. //查询是否参加考试
  2824. $StudentPaperRelation=$this->sConn->createCommand("select student_id,paper_id from `student_paper_relation` where student_id='".$studentId."' and paper_id in(".implode(',',$paperIds).")")->queryRow();
  2825. if(!$StudentPaperRelation){
  2826. $result['status']=1;
  2827. $result['msg']='学生没有参加本次考试';
  2828. exit(json_encode($result));
  2829. }
  2830. //判断学生id是否已关联过
  2831. $related=$this->sConn->createCommand("select id from import_score_temp where student_id='".$studentId."' limit 1")->queryRow();
  2832. if($related){
  2833. $result['status']=0;
  2834. $result['msg']='需要继续处理';
  2835. exit(json_encode($result));
  2836. }else{
  2837. $updateSql="update import_score_temp set student_id='{$studentId}',is_repeat=0 where id={$id}";
  2838. $this->sConn->createCommand($updateSql)->execute();
  2839. exit(json_encode($result));
  2840. }
  2841. }
  2842. }else{
  2843. $result['msg']='考试数据有误';
  2844. exit(json_encode($result));
  2845. }
  2846. }
  2847. }
  2848. //绑定学生id
  2849. public function actionBindingImg(){
  2850. $str=Req::post('str');
  2851. $result['status']=0;
  2852. if(!$str || !is_array($str)){
  2853. exit(json_encode($result));
  2854. }
  2855. $studentIds=array();
  2856. $tempIds=array();
  2857. foreach($str as $val){
  2858. @$nToId=explode('///',$val);
  2859. if(isset($nToId[0])){
  2860. if(in_array((string)$nToId[0],$studentIds,true)){
  2861. $result['msg']='不能学生重复选择';
  2862. exit(json_encode($result));
  2863. }else{
  2864. $studentIds[]=(string)$nToId[0];
  2865. }
  2866. }
  2867. if(isset($nToId[1])){
  2868. if(in_array((string)$nToId[1],$tempIds,true)){
  2869. $result['msg']='不能学生重复选择';
  2870. exit(json_encode($result));
  2871. }else{
  2872. $tempIds[]=(string)$nToId[1];
  2873. }
  2874. }
  2875. }
  2876. $updateSql=array();
  2877. foreach($str as $val){
  2878. @$nToId=explode('///',$val);
  2879. if(isset($nToId[0]) && isset($nToId[1])){
  2880. //判断学生id是否已关联过
  2881. $related=$this->sConn->createCommand("select id from import_score_temp where student_id='".$nToId[0]."' and exam_type=2 limit 1")->queryRow();
  2882. if($related){
  2883. $result['msg']='学生已经被关联,请重新检查';
  2884. exit(json_encode($result));
  2885. }
  2886. $updateSql[]="update import_score_temp set student_id='".$nToId[0]."',is_repeat=0 where id='".$nToId[1]."' and exam_type=2";
  2887. }
  2888. }
  2889. if($updateSql){
  2890. foreach($updateSql as $query){
  2891. $this->sConn->createCommand($query)->execute();
  2892. }
  2893. $result['status']=1;
  2894. }
  2895. exit(json_encode($result));
  2896. }
  2897. //修改不存在的学生数据
  2898. public function actionChange_value_img(){
  2899. $id=Req::post('id');
  2900. $value=Req::post('value');
  2901. $result['status']=0;
  2902. if(!$id || !$value){
  2903. $result['msg']='参数不正确';
  2904. exit(json_encode($result));
  2905. }
  2906. $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";
  2907. $data=$this->sConn->createCommand($sql)->queryRow();
  2908. if(!$data){
  2909. $result['msg']='id不正确';
  2910. exit(json_encode($result));
  2911. }
  2912. $check_field=$data['check_field'];
  2913. //excel中是否有重复数据
  2914. $excelCheck="select id from import_score_temp where check_field_value='".$value."' and exam_type=2 ";
  2915. $excelCheckData=$this->sConn->createCommand($excelCheck)->queryRow();
  2916. if($excelCheckData){
  2917. $result['msg']='excel中已存在相同记录';
  2918. if($check_field=='student_name'){
  2919. $result['status']=1;
  2920. $updateSql="update import_score_temp set `is_repeat`=1,check_field_value='{$value}' where (id={$id} or check_field_value='{$value}') and exam_type=2";
  2921. $this->sConn->createCommand($updateSql)->execute();
  2922. $result['msg']='excel中已存在相同记录,请返回检测页面,继续处理重名';
  2923. }
  2924. exit(json_encode($result));
  2925. }
  2926. //系统中是否有数据
  2927. $exam_group_id=$data['exam_group_id'];
  2928. $exam_group_data = $this->sConn->createCommand("SELECT e.exam_id,e.tpl_data,p.paper_id,e.class_id FROM `exam` e join paper p on e.exam_id=p.exam_id where e.exam_group_id='".$exam_group_id."'")->queryAll();
  2929. if(!$exam_group_data){
  2930. $result['status']=0; //还有重复数据,需要继续处理
  2931. exit(json_encode($result));
  2932. }
  2933. $paperIds=array();
  2934. $examIds=array();
  2935. $classIds=array();
  2936. foreach ($exam_group_data as $val){
  2937. $paperIds[]=$val['paper_id'];
  2938. $examIds[]=$val['exam_id'];
  2939. $classIds[]=$val['class_id'];
  2940. }
  2941. if($exam_group_data){
  2942. $student_info=array();
  2943. switch ($check_field){
  2944. case 'student_name':
  2945. $sql="select si.student_id,si.realname from student_info si join student_paper_relation spr on si.student_id = spr.student_id where realname ='".$value."' and paper_id in(".implode(',',$paperIds).")";
  2946. $student_info=$this->sConn->createCommand($sql)->queryAll();
  2947. break;
  2948. case 'userno':
  2949. $sql="select userno,spr.student_id from student_info si ";
  2950. $sql.="join student_class_relation scr on scr.student_id=si.student_id ";
  2951. $sql.="join student_paper_relation spr on si.student_id = spr.student_id ";
  2952. $sql.=" where sscr.userno ='".$value."' and scr.status=0 and scr.class_id in(".implode(',',$classIds).") and spr.paper_id in(".implode(',',$paperIds).")";
  2953. $student_info=$this->sConn->createCommand($sql)->queryAll();
  2954. break;
  2955. case 'student_card':
  2956. $sql="select student_id,student_card from student where student_card ='".$value."' and status=0";
  2957. $b_student=$this->conn->createCommand($sql)->queryAll();
  2958. break;
  2959. case 'school_student_card':
  2960. $sql="select student_id,school_student_card from student where school_student_card='".$value."' and status=0";
  2961. $b_student=$this->conn->createCommand($sql)->queryAll();
  2962. break;
  2963. case 'zhixue_student_card':
  2964. $sql="select student_id,zhixue_student_card from student where zhixue_student_card='".$value."' and status=0";
  2965. $b_student=$this->conn->createCommand($sql)->queryAll();
  2966. break;
  2967. default:
  2968. $sql="select * from student_info si join student_paper_relation spr on si.student_id = spr.student_id where `".$check_field."` ='".$value."' and paper_id in(".implode(',',$paperIds).") ";
  2969. $student_info=$this->sConn->createCommand($sql)->queryAll();
  2970. }
  2971. if(isset($b_student) && $b_student){
  2972. $studentIds=array();
  2973. foreach ($b_student as $item){
  2974. $studentIds[]=$item['student_id'];
  2975. }
  2976. $sql="select si.student_id,si.realname from student_info si join student_paper_relation spr on si.student_id = spr.student_id where si.student_id in(".implode(',',$studentIds).") and paper_id in(".implode(',',$paperIds).")";
  2977. $student_info=$this->sConn->createCommand($sql)->queryAll();
  2978. }
  2979. if(!$student_info){
  2980. $result['msg']='系统中不存在,或学生没有参加该次考试';
  2981. exit(json_encode($result));
  2982. }elseif(count($student_info)>1){
  2983. $updateSql="update import_score_temp set `is_repeat`=1,check_field_value='{$value}' where id={$id}";
  2984. $this->sConn->createCommand($updateSql)->execute();
  2985. $result['msg']='系统中存在多个该学生数据,请返回检测页面,继续处理重名';
  2986. exit(json_encode($result));
  2987. }else{
  2988. $result['status']=1;
  2989. $studentId=$student_info[0]['student_id'];
  2990. //查询是否参加考试
  2991. $StudentPaperRelation=$this->sConn->createCommand("select student_id,paper_id from `student_paper_relation` where student_id='".$studentId."' and paper_id in(".implode(',',$paperIds).")")->queryRow();
  2992. if(!$StudentPaperRelation){
  2993. $result['status']=1;
  2994. $result['msg']='学生没有参加本次考试';
  2995. exit(json_encode($result));
  2996. }
  2997. //判断学生id是否已关联过
  2998. $related=$this->sConn->createCommand("select id from import_score_temp where student_id='".$studentId."' and exam_type=2 limit 1")->queryRow();
  2999. if($related){
  3000. $result['msg']='学生已经被关联,请重新检查';
  3001. exit(json_encode($result));
  3002. }
  3003. $updateSql="update import_score_temp set student_id='{$studentId}',check_field_value='{$value}',is_repeat=0 where id={$id}";
  3004. $this->sConn->createCommand($updateSql)->execute();
  3005. exit(json_encode($result));
  3006. }
  3007. }else{
  3008. $result['msg']='考试数据有误';
  3009. exit(json_encode($result));
  3010. }
  3011. }
  3012. //处理不存在学生
  3013. public function actionHandle_existent_img(){
  3014. $fileName=array(
  3015. 'student_name'=>'学生姓名',
  3016. 'userno'=>'学号',
  3017. 'student_card'=>'准考证号',
  3018. 'school_student_card'=>'学校准考证号',
  3019. 'zhixue_student_card'=>'智学网考证号',
  3020. 'id_number'=>'身份证号',
  3021. 'student_phone'=>'手机号'
  3022. );
  3023. //扩展字段
  3024. $studentExtend=$this->schoolManager->getStudentExtend();
  3025. if($studentExtend){
  3026. foreach ($studentExtend as $key=> $value){
  3027. $fileName[$key]=$value['field_mean'];
  3028. }
  3029. }
  3030. //查询不存在的数据
  3031. $sql="select * from import_score_temp where is_repeat=0 and (student_id is null or student_id =0) and exam_type=2 ";
  3032. $all_data=$this->sConn->createCommand($sql)->queryAll();
  3033. if($all_data){
  3034. $data['check_field']=$all_data[0]['check_field'];
  3035. }else{
  3036. $data['check_field']='';
  3037. }
  3038. $data['list']=$all_data;
  3039. $data['fieldName']=$fileName;
  3040. $this->render('handle_existent',$data);
  3041. }
  3042. //处理完毕,执行图片导入
  3043. public function actionUpdate_images(){
  3044. ini_set('memory_limit','512M');
  3045. $result['status']=0;
  3046. $sql="select * from import_score_temp where student_id is not null and is_repeat=0 and exam_type=2";
  3047. $all_data=$this->sConn->createCommand($sql)->queryAll();
  3048. if(!$all_data){
  3049. $result['msg']='没有发现可导入学生成绩数据';
  3050. exit(json_encode($result));
  3051. }
  3052. $exam_group_id=$all_data[0]['exam_group_id'];
  3053. $exam = $this->sConn->createCommand("SELECT e.exam_id,e.tpl_data,p.paper_id FROM `exam` e join paper p on e.exam_id=p.exam_id where e.exam_group_id='".$exam_group_id."'")->queryAll();
  3054. if(!$exam){
  3055. $result['msg']='考试ID不正确,请从考试列表点击上传成绩';
  3056. exit(json_encode($result));
  3057. }
  3058. $paperIds=array();
  3059. $examIds=array();
  3060. foreach ($exam as $value){
  3061. $paperIds[]=$value['paper_id'];
  3062. $examIds[]=$value['exam_id'];
  3063. }
  3064. $tpl_data=json_decode($exam[0]['tpl_data'],true);
  3065. $paper_topic_relation=$this->sConn->createCommand("select `paper_id`,`topic_id`,`no`,`score`,`type` from `paper_topic_relation` where paper_id='".$paperIds[0]."'")->queryAll();
  3066. if(!$paper_topic_relation){
  3067. $result['msg']='请关联答题卡';
  3068. exit(json_encode($result));
  3069. }
  3070. $paper_topic_rs=array();
  3071. $paperType=array();
  3072. foreach ($paper_topic_relation as $key=>$value){
  3073. $paper_topic_rs[$key]=$value['topic_id'];
  3074. $paperType[$key]=$value['type'];
  3075. }
  3076. $error=array();
  3077. $updateArr=array();
  3078. $studentInPaper=array();
  3079. foreach($all_data as $val){
  3080. $StudentPaperRelation=$this->sConn->createCommand("select student_id,paper_id from `student_paper_relation` where student_id='".$val['student_id']."' and paper_id in(".implode(',',$paperIds).")")->queryRow();
  3081. if(!$StudentPaperRelation){
  3082. $error[]='学生没有参加本次考试 :'.$val['student_name'];
  3083. continue;
  3084. }
  3085. $studentInPaper[(string)$val['student_id']]=$StudentPaperRelation['paper_id'];
  3086. $topicScoreData=json_decode($val['score_data'],true);
  3087. if($val['check_field']!='student_name'){
  3088. $topicScoreData=array_slice($topicScoreData,1);
  3089. }
  3090. $topicScoreData=array_values($topicScoreData);
  3091. foreach($topicScoreData as $key=> $ts){
  3092. if(!$ts) continue;
  3093. $topic_id= $paper_topic_rs[$key];
  3094. $image_array = @getimagesize($ts);
  3095. if ($image_array && isset($image_array[0]) && isset($image_array[1])) {
  3096. $updateArr[(string)$val['student_id']]['answer_url'][$topic_id]=$ts;
  3097. $updateArr[(string)$val['student_id']]['answer_url_width'][$topic_id]=$image_array[0];
  3098. $updateArr[(string)$val['student_id']]['answer_url_height'][$topic_id]=$image_array[1];
  3099. $updateArr[(string)$val['student_id']]['simplify_answer_url'][$topic_id]=$ts;
  3100. $updateArr[(string)$val['student_id']]['simplify_answer_url_width'][$topic_id]=$image_array[0];
  3101. $updateArr[(string)$val['student_id']]['simplify_answer_url_height'][$topic_id]=$image_array[1];
  3102. }
  3103. }
  3104. }
  3105. if($updateArr){
  3106. $transaction = $this->sConn->beginTransaction();
  3107. try{
  3108. $sqlArr=array();
  3109. foreach ($updateArr as $student_id =>$value){
  3110. $updateSqlTemp=array();
  3111. $sql='update `student_paper_topic_rs` set ';
  3112. foreach ($value as $filed =>$val){
  3113. $updateSqlStr=" `{$filed}` = case topic_id ";
  3114. foreach ($val as $topic_id =>$v){
  3115. $updateSqlStr.=" WHEN '".$topic_id."' THEN '".$v."' ";
  3116. }
  3117. $updateSqlStr.=" ELSE `{$filed}` ";
  3118. $updateSqlStr.=" END ";
  3119. $updateSqlTemp[]=$updateSqlStr;
  3120. }
  3121. $sqlArr[]= $sql.implode(',',$updateSqlTemp)." where student_id='".$student_id."' and paper_id ='".$studentInPaper[$student_id]."'";
  3122. }
  3123. foreach ($sqlArr as $v){
  3124. $this->sConn->createCommand($v)->execute();
  3125. }
  3126. //清理导入临时数据
  3127. $delSql="delete from import_score_temp where exam_type=2;";
  3128. $this->sConn->createCommand($delSql)->execute();
  3129. $transaction->commit();
  3130. $result['status']=1;
  3131. if($error){
  3132. // Yii::app()->jump->error('导入成功,有部分学生成绩没有导入:'.implode(',',$error));
  3133. $result['msg']=implode('<br>',$error);
  3134. }else{
  3135. $result['msg']='导入成功';
  3136. }
  3137. if(Yii::app()->params['handle_log_on_off'])
  3138. {
  3139. writeFileLog(jsonEncode(array(
  3140. "exam_group_id" => 0,
  3141. "operate_project" => 'zsyas2',
  3142. "school_id" => $this->schoolId,
  3143. "title" => '新导入学生图片',
  3144. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  3145. "operate_method" => $this->action,
  3146. "operate_url" => $this->getRoute(),
  3147. "operate_sql" =>'',
  3148. "operate_param" =>'',
  3149. "date"=>date('Y-m-d H:i:s')
  3150. )));
  3151. }
  3152. exit(json_encode($result));
  3153. }catch (Exception $e) {
  3154. //如果操作失败, 数据回滚
  3155. $transaction->rollback();
  3156. // Yii::app()->jump->error('成绩导入失败,请检查后重新');
  3157. $result['msg']='图片导入失败,请检查后重新导入';
  3158. exit(json_encode($result));
  3159. }
  3160. }else{
  3161. //没有需要重新导入的数据,清理导入临时数据
  3162. //$delSql="truncate table import_score_temp;";
  3163. $delSql="delete from import_score_temp where exam_type=2;";
  3164. $this->sConn->createCommand($delSql)->execute();
  3165. $result['status']=1;
  3166. exit(json_encode($result));
  3167. }
  3168. }
  3169. public function actionT(){
  3170. //$image_array = getimagesize('http://zxhx-n-1302712961.cos.ap-beijing.myqcloud.com/PT/CScut/4016/990807494965600256/945581044318568448/6.jpg');
  3171. //$image_array = getimagesize('https://pics7.baidu.com/feed/2cf5e0fe9925bc31e23d52434fdae8bdca13709e.jpeg');
  3172. $image_array = getimagesize('http://ftp.hujiao.com/iu-1.png');
  3173. debug($image_array);
  3174. }
  3175. }