AllSubjectController.php 105 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378
  1. <?php
  2. class AllSubjectController extends Controller{
  3. public $topicTypeRelation=array(
  4. 'ke'=>array(1,2,3,4,12),
  5. 'zhu'=>array(5,6,7,8,9,10,11),
  6. 'jie'=>array(8,9,10,11),
  7. 'tian'=>array(5,6,7),
  8. 'single'=>array(1,2),
  9. 'multiple'=>array(3,4),
  10. 'pan'=>array(12)
  11. );
  12. public $oldTopicType=array(
  13. 1=>'单选题',
  14. 2=>"多选题",
  15. 3=>'判断题',
  16. 5=>'填空题',
  17. 7=>'解答题',
  18. 17=>'选做题'
  19. );
  20. // 打印列表
  21. public function actionIndex()
  22. {
  23. $examId = Req::get('eid');
  24. $examData= Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$examId));
  25. if(!$examData) Yii::app()->jump->error('考试id不正确!');
  26. $examGroup=ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examData->exam_group_id));
  27. if(!$examGroup->qxk_paper_id){
  28. $this->redirect('paper/index?eid='.$examId);
  29. }
  30. $tplData=json_decode($examData->tpl_data,true);
  31. $alias=array();
  32. $stemAlias=array();
  33. $newRules=array();
  34. $selectTopicGroup=array();
  35. if(isset($tplData['new_items'])){
  36. foreach ($tplData['new_items'] as $item){
  37. if(isset($item['fullAlias'])){
  38. $alias[$item['id']]=$item['fullAlias'];
  39. }else{
  40. $alias[$item['id']]=$item['alias'];
  41. if($item['stemId']==$item['topicId']){
  42. $stemAlias[$item['id']]=$item['alias'];
  43. }else{
  44. $stemAlias[$item['id']]=$item['stemAlias'].$item['alias'];
  45. }
  46. }
  47. if(isset($item['sameAliasNo']) && $item['sameAliasNo']){
  48. $selectTopicGroup[$item['id']]=$item['sameAliasNo'];
  49. }
  50. if(isset($item['basicTopicType']) && isset($item['topicId'])){
  51. $thirdBasicId[(string)$item['topicId']]=$item['basicTopicType'];
  52. if(isset($item['stemId']) && $item['topicId']!=$item['stemId']){
  53. $thirdBasicId[(string)$item['stemId']]=$item['basicTopicType'];
  54. }
  55. }
  56. }
  57. }
  58. //读取新规则
  59. if(isset($tplData['new_rules'])){
  60. $data['new_rules'] = $tplData['new_rules'];
  61. }
  62. //读取单选题更新答案记录
  63. if(isset($tplData['update_answer'])){
  64. $data['update_answer'] = $tplData['update_answer'];
  65. }
  66. //读取送分题/0分题
  67. if(isset($tplData['send_points'])){
  68. $data['send_points'] = $tplData['send_points'];
  69. }
  70. $paper=SPaper::model()->find('exam_id=:exam_id',array(':exam_id'=>$examId));
  71. $topic_data = SPaperTopicRelation::model()->findAll(array('order'=>'`type` asc ,`order` asc','condition'=>'paper_id=:paper_id','params'=>array(':paper_id'=>$paper->paper_id)));
  72. if(!$topic_data){
  73. Yii::app()->jump->error('请先创建答题卡!');
  74. }
  75. $topicIds=array();
  76. foreach ($topic_data as $item){
  77. if($item['stem_id']){
  78. $topicIds[$item['stem_id']]=$item['stem_id'];
  79. $topicTypeCount[$item['type']][]=$item['stem_id'];
  80. }else{
  81. $topicIds[$item['topic_id']]=$item['topic_id'];
  82. $topicTypeCount[$item['type']][]=$item['topic_id'];
  83. }
  84. $topicTypeScoreCount[$item['type']][]=$item['score'];
  85. $topicNumber[(string)$item['topic_id']]=array(
  86. 'topic_id'=>$item['topic_id'],
  87. 'type'=>$item['type'],
  88. 'score'=>$item['score'],
  89. 'order'=>$item['order'],
  90. );
  91. }
  92. //$topicDetail=$this->schoolManager->getTopics($topicIds,false,$examData->subject_id);
  93. $topicDetail=$this->schoolManager->getQxkPaperTopics($topicIds);
  94. //组装试题结构
  95. $arr = array(0=>'A',1=>'B',2=>'C',3=>'D',4=>'E',5=>'F',6=>'G',7=>'H',8=>'I',9=>'J',10=>'K');
  96. $topicType=array();
  97. $topicGroup=array();
  98. foreach ($topicDetail as $item){
  99. if(!isset($topicType[$item['typeId']])){
  100. $topicType[$item['typeId']]=array(
  101. 'type_name'=>$item['typeName'],
  102. 'basic_type_id'=>$item['basicType'],
  103. 'tips'=>'',
  104. 'topic'=>array()
  105. );
  106. }
  107. $topic=array();
  108. $topic['id']=(string)number_format($item['topicId'],0,'','');
  109. $topic['type_id']=$item['typeId'];
  110. $topic['basic_type_id']=$item['basicType'];
  111. $topic['type_name']=$item['typeName'];
  112. $topic['subject_id']=$item['subjectId'];
  113. $topic['subject_name']=$item['subjectName'];
  114. $topic['title']=$item['title'];
  115. $topic['parse_content']=$item['parseContent'];
  116. $topic['slave_stem_editor']=$item['noShowSlaveTitle']?false:true; //小题题干独立编辑
  117. $topic['slave_option_editor']=$item['noShowSlaveOptions']?false:true; //小题选项独立编辑
  118. if(isset($topicNumber[(string)$topic['id']])){
  119. $topic['score']=$topicNumber[(string)$topic['id']]['score'];
  120. $topic['order']=$topicNumber[(string)$topic['id']]['order'];
  121. if(isset($alias[$topic['order']])){
  122. $topic['alias']=$alias[$topic['order']];
  123. }
  124. if(!isset($topicType[$item['typeId']]['order'])){
  125. if(isset($alias[$topic['order']]) && is_numeric($alias[$topic['order']])){
  126. $topicType[$item['typeId']]['order']=$alias[$topic['order']];
  127. }else{
  128. $topicType[$item['typeId']]['order']=$topicNumber[(string)$topic['id']]['order'];
  129. }
  130. }
  131. //判断选做题
  132. if(isset($selectTopicGroup[$topicNumber[(string)$topic['id']]['order']])){
  133. $topic['group_id']=$selectTopicGroup[$topicNumber[(string)$topic['id']]['order']];
  134. }
  135. }
  136. $topicGroup[$topic['id']]=array();
  137. if(!$item['slaveList']){
  138. $topic['answer']=$item['answer'];
  139. $topic['items']=$item['optionList'];
  140. if(!$topic['title'] && !$item['optionList']){
  141. $topic['is_show']=0;
  142. }else{
  143. $topic['is_show']=1;
  144. }
  145. $topic['answer_type_id']=$item['answerType'];
  146. if(count($item['answerDtl'])>1){
  147. $topic['is_checkbox']=1;
  148. }else{
  149. $topic['is_checkbox']=0;
  150. }
  151. $topicGroup[$topic['id']][]=$topic;
  152. }else{
  153. foreach ($item['slaveList'] as $val){
  154. $slave=array();
  155. $basicTopicArr[(string)$val['topicSlaveId']][]=$val;
  156. if(isset($topicNumber[(string)$val['topicSlaveId']])){
  157. $slave['score']=$topicNumber[(string)$val['topicSlaveId']]['score'];
  158. $slave['order']=$topicNumber[(string)$val['topicSlaveId']]['order'];
  159. if(!isset($topic['order'])){
  160. $topic['order']=$slave['order'];
  161. }
  162. if(isset($alias[$slave['order']])){
  163. $slave['alias']=$alias[$slave['order']];
  164. }
  165. if(!isset($topicType[$item['typeId']]['order'])){
  166. if(isset($alias[$slave['order']]) && is_numeric($alias[$slave['order']])){
  167. $topicType[$item['typeId']]['order']=$alias[$slave['order']];
  168. }else{
  169. $topicType[$item['typeId']]['order']=$topicNumber[(string)$val['topicSlaveId']]['order'];
  170. }
  171. }
  172. //判断选做题
  173. if(isset($selectTopicGroup[$topicNumber[(string)$val['topicSlaveId']]['order']])){
  174. $topic['group_id']=$selectTopicGroup[$topicNumber[(string)$val['topicSlaveId']]['order']];
  175. }
  176. }
  177. $slave['title']=$val['title'];
  178. $slave['parse_content']=$val['parseContent'];
  179. $slave['topic_slave_id']=$val['topicSlaveId'];
  180. if(isset($val['slaveList']) && $val['slaveList']){
  181. //三级子题
  182. foreach ($val['slaveList'] as $thirdSlave){
  183. $childSlave=array();
  184. $childSlave['title']=$thirdSlave['title'];
  185. $childSlave['topic_slave_id']=$thirdSlave['topicSlaveId'];
  186. $childSlave['parse_content']=$thirdSlave['parseContent'];
  187. if(isset($topicNumber[(string)$thirdSlave['topicSlaveId']])){
  188. $childSlave['score']=$topicNumber[(string)$thirdSlave['topicSlaveId']]['score'];
  189. $childSlave['order']=$topicNumber[(string)$thirdSlave['topicSlaveId']]['order'];
  190. //判断小题别名
  191. $topicType[$item['typeId']]['last_order']=$topicNumber[(string)$thirdSlave['topicSlaveId']]['order'];
  192. if(isset($alias[$childSlave['order']])){
  193. $childSlave['alias']=$alias[$childSlave['order']];
  194. }
  195. if(!isset($topicType[$item['typeId']]['order'])){
  196. if(isset($alias[$childSlave['order']]) && is_numeric($alias[$childSlave['order']])){
  197. $topicType[$item['typeId']]['order']=$alias[$childSlave['order']];
  198. }else{
  199. $topicType[$item['typeId']]['order']=$topicNumber[(string)$thirdSlave['topicSlaveId']]['order'];
  200. }
  201. }
  202. //判断选做题
  203. if(isset($selectTopicGroup[$topicNumber[(string)$thirdSlave['topicSlaveId']]['order']])){
  204. $topic['group_id']=$selectTopicGroup[$topicNumber[(string)$thirdSlave['topicSlaveId']]['order']];
  205. }
  206. }else{
  207. continue;
  208. }
  209. $childSlave['answer']=$thirdSlave['answer'];
  210. if(!$childSlave['title'] && !$thirdSlave['options']){
  211. $childSlave['is_show']=0;
  212. }else{
  213. $childSlave['is_show']=1;
  214. }
  215. if(isset($thirdSlave['listType'])){
  216. $childSlave['list_type']=$thirdSlave['listType'];
  217. }
  218. $childSlave['items']=$thirdSlave['options'];
  219. if(isset($thirdSlave['answerType'])){
  220. $childSlave['answer_type_id']=$thirdSlave['answerType'];
  221. }else{
  222. $childSlave['answer_type_id']=0;
  223. }
  224. if(count($thirdSlave['answerDtl'])>1){
  225. $childSlave['is_checkbox']=1;
  226. }else{
  227. $childSlave['is_checkbox']=0;
  228. }
  229. if(isset($thirdSlave['words'])){
  230. $childSlave['words']=$thirdSlave['words'];
  231. }
  232. $slave['slave'][]=$childSlave;
  233. $topicGroup[$topic['id']][]=$childSlave;
  234. }
  235. }else{
  236. $slave['answer']=$val['answer'];
  237. if(!$slave['title'] && !$val['options']){
  238. $slave['is_show']=0;
  239. }else{
  240. $slave['is_show']=1;
  241. }
  242. if(isset($val['listType'])){
  243. $slave['list_type']=$val['listType'];
  244. }
  245. $slave['items']=$val['options'];
  246. if(isset($val['answerType'])){
  247. $slave['answer_type_id']=$val['answerType'];
  248. }else{
  249. $slave['answer_type_id']=0;
  250. }
  251. if(count($val['answerDtl'])>1){
  252. $slave['is_checkbox']=1;
  253. }else{
  254. $slave['is_checkbox']=0;
  255. }
  256. if(isset($val['words'])){
  257. $slave['words']=$val['words'];
  258. }
  259. $topicGroup[$topic['id']][]=$slave;
  260. }
  261. $topic['slave'][]=$slave;
  262. }
  263. }
  264. $topicType[$item['typeId']]['topic'][]=$topic;
  265. }
  266. //拆分选做题
  267. if($selectTopicGroup){
  268. $selectTopicType=array();
  269. $selectTopicType['type_name']='选做题';
  270. $selectTopicType['topic']=array();
  271. foreach ($topicType as $key => $item){
  272. foreach ($item['topic'] as $vk => $val){
  273. if(isset($val['group_id'])){
  274. $selectTopicType['topic'][]=$val;
  275. $selectTopicType['basic_type_id']=$val['basic_type_id'];
  276. if(!isset($selectTopicType['order'])){
  277. $selectTopicType['order']=$val['order'];
  278. }
  279. unset($topicType[$key]['topic'][$vk]);
  280. }
  281. }
  282. if(count($topicType[$key]['topic'])==0){
  283. unset($topicType[$key]);
  284. }else{
  285. $topicType[$key]['topic']=array_values($topicType[$key]['topic']);
  286. $topicType[$key]['order']= $topicType[$key]['topic'][0]['order'];
  287. }
  288. }
  289. $topicType[17]=$selectTopicType;
  290. }
  291. //计算小题数量
  292. foreach ($topicType as $key => $item){
  293. $topicNumber=0;
  294. $scores=0;
  295. foreach ($item['topic'] as $val){
  296. if(isset($val['slave'])){
  297. foreach ($val['slave'] as $v){
  298. if(isset($v['slave'])){
  299. foreach ($v['slave'] as $value){
  300. if(isset($value['score'])){
  301. $scores+=$value['score'];
  302. }
  303. $topicNumber++;
  304. }
  305. }else{
  306. if(isset($v['score'])){
  307. $scores+=$v['score'];
  308. }
  309. $topicNumber++;
  310. }
  311. }
  312. }else{
  313. if($key==17){
  314. $scores=$val['score'];
  315. }else{
  316. $scores+=$val['score'];
  317. }
  318. $topicNumber++;
  319. }
  320. }
  321. $topicType[$key]['tips']='本大题共'.$topicNumber.'小题,共'.$scores.'分';
  322. $topicType[$key]['total_score']=$scores;
  323. $lastOrder = $this->_array_column($item['topic'],'order');
  324. array_multisort($lastOrder,SORT_ASC,$topicType[$key]['topic']);
  325. }
  326. //按组卷排序
  327. $lastOrder = $this->_array_column($topicType,'order');
  328. array_multisort($lastOrder,SORT_ASC,$topicType);
  329. //计算大题号
  330. foreach ($topicType as $key =>$value){
  331. $topicType[$key]['questionNumber']=numToUpper($key+1);
  332. }
  333. //题型对应
  334. $singleChoice=array(1,2,12); //单选,小题单选
  335. $multipleChoices=array(3,4); //多选,小题多选
  336. $slaveAnswer=array(7,9); //多选,小题多选
  337. $data['singleChoice']=$singleChoice;
  338. $data['multipleChoices']=$multipleChoices;
  339. $data['slaveAnswer']=$slaveAnswer;
  340. $data['topic']=$topicType;
  341. $data['subject']=$examData->subject_id;
  342. $data['paper_id']=$paper->paper_id;
  343. $data['is_third']=$examGroup->is_third;
  344. $data['topic_group']=$topicGroup;
  345. $data['exam_id']=$examId;
  346. $data['alias']=$alias;
  347. $this->renderPartial("all_subject",$data);
  348. }
  349. //试题操作页面
  350. public function actionOperate(){
  351. $examId = Req::get('eid');
  352. $examData= Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$examId));
  353. if(!$examData) Yii::app()->jump->error('考试id不正确!');
  354. $examGroup=ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examData->exam_group_id));
  355. if(!$examGroup->qxk_paper_id){
  356. $this->redirect('paper/index?eid='.$examId);
  357. }
  358. $tplData=json_decode($examData->tpl_data,true);
  359. $alias=array();
  360. $stemAlias=array();
  361. $newRules=array();
  362. $thirdBasicId=array();
  363. $scoresType=array(); //小问小空类型
  364. if(isset($tplData['new_items'])){
  365. foreach ($tplData['new_items'] as $item){
  366. if(isset($item['fullAlias'])){
  367. $alias[$item['id']]=$item['fullAlias'];
  368. }else{
  369. $alias[$item['id']]=$item['alias'];
  370. if($item['stemId']==$item['topicId']){
  371. $stemAlias[$item['id']]=$item['alias'];
  372. }else{
  373. $stemAlias[$item['id']]=$item['stemAlias'].$item['alias'];
  374. }
  375. }
  376. if(isset($item['sameAliasNo']) && $item['sameAliasNo']){
  377. $selectTopicGroup[$item['id']]=$item['sameAliasNo'];
  378. }
  379. if(isset($item['basicTopicType']) && isset($item['topicId'])){
  380. $thirdBasicId[$item['topicId']]=$item['basicTopicType'];
  381. if(isset($item['stemId']) && $item['topicId']!=$item['stemId']){
  382. $thirdBasicId[$item['stemId']]=$item['basicTopicType'];
  383. }
  384. }
  385. if(isset($item['scoresType'])){
  386. $scoresType[$item['topicId']]=$item['scoresType'];
  387. }
  388. }
  389. }
  390. //读取新规则
  391. if(isset($tplData['new_rules'])){
  392. $paperData['new_rules'] = $tplData['new_rules'];
  393. }
  394. //读取单选题更新答案记录
  395. if(isset($tplData['update_answer'])){
  396. $paperData['update_answer'] = $tplData['update_answer'];
  397. }
  398. //读取送分题/0分题
  399. if(isset($tplData['send_points'])){
  400. $paperData['send_points'] = $tplData['send_points'];
  401. }
  402. $paper=SPaper::model()->find('exam_id=:exam_id',array(':exam_id'=>$examId));
  403. $topic_data = SPaperTopicRelation::model()->findAll(array('order'=>'`type` asc ,`order` asc','condition'=>'paper_id=:paper_id','params'=>array(':paper_id'=>$paper->paper_id)));
  404. if(!$topic_data){
  405. Yii::app()->jump->error('请先创建答题卡!');
  406. }
  407. $multipleBlank=array(); //多空题
  408. foreach ($topic_data as $item){
  409. $topicIds[$item['stem_id']]=$item['stem_id'];
  410. $topicTypeCount[$item['type']][]=$item['stem_id'];
  411. $topicTypeScoreCount[$item['type']][]=$item['score'];
  412. if($item['question_count']>1){
  413. $questionScore=explode(',',$item['question_score_str']);
  414. $multipleBlank[(string)$item['topic_id']]=$questionScore;
  415. }
  416. $topicNumber[(string)$item['topic_id']]=array(
  417. 'topic_id'=>$item['topic_id'],
  418. 'type'=>$item['type'],
  419. 'score'=>$item['score'],
  420. 'order'=>$item['order'],
  421. );
  422. }
  423. //$topicDetail=$this->schoolManager->getTopics($topicIds,false,$examData->subject_id);
  424. $topicDetail=$this->schoolManager->getQxkPaperTopics($topicIds);
  425. // debug($topicDetail);
  426. //组装试题结构
  427. $arr = array(0=>'A',1=>'B',2=>'C',3=>'D',4=>'E',5=>'F',6=>'G',7=>'H',8=>'I',9=>'J',10=>'K');
  428. $topicType=array();
  429. foreach ($topicDetail as $item){
  430. if(isset($item['slaveList']) && $item['slaveList']){
  431. foreach ($item['slaveList'] as $val){
  432. if(isset($val['slaveList']) && $val['slaveList']){
  433. foreach ($val['slaveList'] as $third){
  434. $topic=array();
  435. $topic['id']=(string)number_format($third['topicSlaveId'],0,'','');
  436. if(isset($topicNumber[(string)$topic['id']])){
  437. $topic['score']=$topicNumber[(string)$topic['id']]['score'];
  438. $topic['order']=$topicNumber[(string)$topic['id']]['order'];
  439. if(isset($alias[$topic['order']])){
  440. $topic['alias']=$alias[$topic['order']];
  441. }
  442. }
  443. $topic['answer']=$third['answer'];
  444. if(isset($paperData['new_rules'][$topic['order']])){
  445. $topic['rule_type']=$paperData['new_rules'][$topic['order']]['rule_type'];
  446. $topic['rule_answer']=$paperData['new_rules'][$topic['order']]['rule_answer'];
  447. $topic['rule_score']=$paperData['new_rules'][$topic['order']]['rule_score'];
  448. $topic['rule_score_half']=$paperData['new_rules'][$topic['order']]['rule_score_half'];
  449. }
  450. if(isset($tplData['update_answer'][$topic['order']])){
  451. $topic['update_answer']=$tplData['update_answer'][$topic['order']]['update_answer'];
  452. }
  453. if(isset($tplData['send_points'][$topic['order']])){
  454. $topic['send_points_type']=$tplData['send_points'][$topic['order']]['actionType'];
  455. }
  456. if(isset($third['answerType'])){
  457. $answerTypeId=$third['answerType'];
  458. }else{
  459. $answerTypeId=0;
  460. }
  461. if(count($third['answerDtl'])>1){
  462. $isCheckBox=1;
  463. }else{
  464. $isCheckBox=0;
  465. }
  466. $topicTypeId=$this->TransformTopicType($item['basicType'],$answerTypeId,$isCheckBox);
  467. if(isset($selectTopicGroup[$topicNumber[(string)$topic['id']]['order']]) && $selectTopicGroup[$topicNumber[(string)$topic['id']]['order']] ){
  468. $topicTypeId=17;
  469. }
  470. $topic['option_count']=count($third['options']);
  471. $topicType[$topicTypeId][]=$topic;
  472. }
  473. }else{
  474. //无三级小题
  475. $topic=array();
  476. $topic['id']=(string)number_format($val['topicSlaveId'],0,'','');
  477. if(isset($topicNumber[(string)$topic['id']])){
  478. $topic['score']=$topicNumber[(string)$topic['id']]['score'];
  479. $topic['order']=$topicNumber[(string)$topic['id']]['order'];
  480. if(isset($alias[$topic['order']])){
  481. $topic['alias']=$alias[$topic['order']];
  482. }
  483. }
  484. $topic['answer']=$val['answer'];
  485. if(isset($paperData['new_rules'][$topic['order']])){
  486. $topic['rule_type']=$paperData['new_rules'][$topic['order']]['rule_type'];
  487. $topic['rule_answer']=$paperData['new_rules'][$topic['order']]['rule_answer'];
  488. $topic['rule_score']=$paperData['new_rules'][$topic['order']]['rule_score'];
  489. $topic['rule_score_half']=$paperData['new_rules'][$topic['order']]['rule_score_half'];
  490. }
  491. if(isset($tplData['update_answer'][$topic['order']])){
  492. $topic['update_answer']=$tplData['update_answer'][$topic['order']]['update_answer'];
  493. }
  494. if(isset($tplData['send_points'][$topic['order']])){
  495. $topic['send_points_type']=$tplData['send_points'][$topic['order']]['actionType'];
  496. }
  497. if(isset($val['answerType'])){
  498. $answerTypeId=$val['answerType'];
  499. }else{
  500. $answerTypeId=0;
  501. }
  502. if(count($val['answerDtl'])>1){
  503. $isCheckBox=1;
  504. }else{
  505. $isCheckBox=0;
  506. }
  507. $topic['option_count']=count($val['options']);
  508. $topicTypeId=$this->TransformTopicType($item['basicType'],$answerTypeId,$isCheckBox);
  509. if(isset($selectTopicGroup[$topicNumber[(string)$topic['id']]['order']]) && $selectTopicGroup[$topicNumber[(string)$topic['id']]['order']] ){
  510. $topicTypeId=17;
  511. }
  512. $topicType[$topicTypeId][]=$topic;
  513. }
  514. }
  515. }else{
  516. $topic=array();
  517. $topic['id']=(string)number_format($item['topicId'],0,'','');
  518. //无小题
  519. if(isset($topicNumber[(string)$topic['id']])){
  520. $topic['score']=$topicNumber[(string)$topic['id']]['score'];
  521. $topic['order']=$topicNumber[(string)$topic['id']]['order'];
  522. if(isset($alias[$topic['order']])){
  523. $topic['alias']=$alias[$topic['order']];
  524. }
  525. }
  526. $topic['answer']=$item['answer'];
  527. if(isset($paperData['new_rules'][$topic['order']])){
  528. $topic['rule_type']=$paperData['new_rules'][$topic['order']]['rule_type'];
  529. $topic['rule_answer']=$paperData['new_rules'][$topic['order']]['rule_answer'];
  530. $topic['rule_score']=$paperData['new_rules'][$topic['order']]['rule_score'];
  531. $topic['rule_score_half']=$paperData['new_rules'][$topic['order']]['rule_score_half'];
  532. }
  533. if(isset($tplData['update_answer'][$topic['order']])){
  534. $topic['update_answer']=$tplData['update_answer'][$topic['order']]['update_answer'];
  535. }
  536. if(isset($tplData['send_points'][$topic['order']])){
  537. $topic['send_points_type']=$tplData['send_points'][$topic['order']]['actionType'];
  538. }
  539. if(isset($item['answerType'])){
  540. $answerTypeId=$item['answerType'];
  541. }else{
  542. $answerTypeId=0;
  543. }
  544. if(count($item['answerDtl'])>1){
  545. $isCheckBox=1;
  546. }else{
  547. $isCheckBox=0;
  548. }
  549. $topicTypeId=$this->TransformTopicType($item['basicType'],$answerTypeId,$isCheckBox);
  550. if(isset($selectTopicGroup[$topicNumber[(string)$topic['id']]['order']]) && $selectTopicGroup[$topicNumber[(string)$topic['id']]['order']] ){
  551. $topicTypeId=17;
  552. }
  553. $topic['option_count']=count($item['optionList']);
  554. $topicType[$topicTypeId][]=$topic;
  555. }
  556. }
  557. foreach ($topicType as $key =>$val){
  558. $lastOrder = $this->_array_column($val,'order');
  559. array_multisort($lastOrder,SORT_ASC,$topicType[$key]);
  560. }
  561. $menu=array();
  562. foreach ($topicType as $k =>$v){
  563. $menu[$k]=$this->oldTopicType[$k];
  564. }
  565. $data['exam_id']=$examId;
  566. $data['paper_id']=$paper['paper_id'];
  567. $data['topic']=$topicType;
  568. $data['menu']=$menu;
  569. $data['exam_name']=$examData->name;
  570. $data['subject_id']=$examData->subject_id;
  571. $data['multiple_blank']=$multipleBlank;
  572. $data['scores_type']=$scoresType;
  573. $this->renderPartial("operate",$data);
  574. }
  575. //批量更新分数
  576. public function actionUpdateScoreBatch(){
  577. $scores = Req::post('scores');
  578. $paper_id = Req::post('paper_id');
  579. $multiple_score = Req::post('multiple_score');
  580. $topicType=0;
  581. $paper_topic_data = SPaperTopicRelation::model()->findAll(array('order'=>'`no` asc ,`type` asc ,`order` asc','condition'=>'`paper_id`=:paper_id ','params'=>array(':paper_id'=>$paper_id)));
  582. $oldTopicScores=0; //原总分
  583. $newTopicScores=array(); //修改后总分
  584. $update_score=array(); //需要修改分数的topic
  585. $update_score_order=array(); //修改分数的序号
  586. $choiseTYpeArr=array(1,2,3,4,12);
  587. $isChoice=true; //修改的题型是选择?
  588. if($paper_topic_data)
  589. {
  590. foreach($paper_topic_data as $v)
  591. {
  592. $oldTopicScores+=$v['score'];
  593. if(isset($scores[$v['order']])){
  594. if($v['score']!=$scores[$v['order']] || isset($multiple_score[$v['topic_id']])){
  595. $update_score[$v->topic_id] = $scores[$v->order];
  596. $update_score_order[$v->order] = $scores[$v->order];
  597. $score_diff[$v->topic_id]=intval($scores[$v->order]-$v['score']);
  598. $topicType=$v['type'];
  599. if(!in_array($topicType,$choiseTYpeArr)){
  600. $isChoice=false;
  601. }
  602. }
  603. $newTopicScores[]=$scores[$v['order']];
  604. }else{
  605. $newTopicScores[]=$v['score'];
  606. }
  607. }
  608. }
  609. if(!$update_score){
  610. echo json_encode(array('status'=>0,'msg'=>'分数与原试题分数一致'));exit;
  611. }
  612. $paper_data = SPaper::model()->find('paper_id=:paper_id',array(':paper_id'=>$paper_id));
  613. $exam_ids = array();
  614. $paper_ids = array();
  615. if($paper_data)
  616. {
  617. $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$paper_data->exam_id));
  618. if($exam_data)
  619. {
  620. $tpl_data = json_decode($exam_data->tpl_data,true);
  621. if(isset($tpl_data['items'])){
  622. $objectiveTplData=array(
  623. 'total'=>count($scores),
  624. 'totalScore'=>array_sum($newTopicScores),
  625. 'perScores'=>array_values($newTopicScores)
  626. );
  627. $tpl_data['items'][$topicType]=$objectiveTplData;
  628. }
  629. $paper_score=$tpl_data['scores']=$tpl_data['total_score']=$tpl_data['scores']-$oldTopicScores+array_sum($newTopicScores);
  630. //修改new_items
  631. if(isset($tpl_data['new_items'])){
  632. foreach ($tpl_data['new_items'] as $key =>$val){
  633. if(isset($update_score_order[$val['id']])){
  634. $tpl_data['new_items'][$key]['score']=$update_score_order[$val['id']];
  635. }
  636. }
  637. }
  638. $json_tpl_data = jsonEncode($tpl_data);
  639. $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id));
  640. if($exam_group_data)
  641. {
  642. foreach($exam_group_data as $v)
  643. {
  644. $exam_ids[$v->exam_id] = $v->exam_id;
  645. }
  646. if($exam_ids)
  647. {
  648. $criteria = new CDbCriteria();
  649. $criteria->addInCondition('exam_id',$exam_ids);
  650. $paper_data = SPaper::model()->findAll($criteria);
  651. if($paper_data)
  652. {
  653. foreach($paper_data as $v)
  654. {
  655. $paper_ids[$v->paper_id] = $v->paper_id;
  656. }
  657. $trans = $this->sConn->beginTransaction();
  658. try{
  659. foreach ($update_score as $topic_id => $score){
  660. if(isset($multiple_score[$topic_id])){
  661. $sql='update `paper_topic_relation` set `score` = '.$score.',question_count='.count($multiple_score[$topic_id]).',question_score_str="'.implode(',',$multiple_score[$topic_id]).'" where paper_id in ('.implode(',',$paper_ids).') and `topic_id` ='.$topic_id;
  662. }else{
  663. $sql='update `paper_topic_relation` set `score` = '.$score.' where paper_id in ('.implode(',',$paper_ids).') and `topic_id` ='.$topic_id;
  664. }
  665. $this->sConn->createCommand($sql)->execute();
  666. if($isChoice){
  667. //修改学生得分
  668. $updateStudentSql="select student_id from student_paper_topic_rs where paper_id in (".implode(',',$paper_ids).") and `topic_id` = '".$topic_id."' and is_right=1 ";
  669. $students=$this->sConn->createCommand($updateStudentSql)->queryAll();
  670. if($students){
  671. $studentIds=array();
  672. foreach ($students as $v){
  673. $studentIds[]=$v['student_id'];
  674. }
  675. $sql="update student_paper_topic_rs set scoring='".$score."' where paper_id in (".implode(',',$paper_ids).") and `topic_id` = '".$topic_id."' and is_right=1 ";
  676. $this->sConn->createCommand($sql)->execute();
  677. $sql="update student_paper_relation set scoring=scoring+".$score_diff[$topic_id]." where paper_id in (".implode(',',$paper_ids).") and student_id in(".implode(',',$studentIds).") ";
  678. $this->sConn->createCommand($sql)->execute();
  679. }
  680. }
  681. }
  682. $sql='update `paper` set `score` = '.($paper_score).' where paper_id in ('.implode(',',$paper_ids).')';
  683. $this->sConn->createCommand($sql)->execute();
  684. $sql="update `exam` set `tpl_data` = '".($json_tpl_data)."' where exam_id in (".implode(',',$exam_ids).")";
  685. $this->sConn->createCommand($sql)->execute();
  686. $trans->commit();
  687. }
  688. catch(Exception $e){
  689. $trans->rollBack();
  690. echo json_encode(array('status'=>0));exit;
  691. }
  692. $sendParam=array(
  693. 'school_id'=>$this->schoolId,
  694. 'exam_group_id'=>$exam_data->exam_group_id
  695. );
  696. sendZsystNotic($sendParam);
  697. $kafkaData=array(
  698. 'schoolId'=>$this->schoolId,
  699. 'examGroupId'=>$exam_data->exam_group_id,
  700. 'generateTime'=>time()*1000
  701. );
  702. sendDataToKafka("xbkc-academic-generate-report",$kafkaData);
  703. $this->sendNoticeToReport($exam_data->exam_group_id);
  704. sendDataToKafka("zsy-marking-update-topic",$exam_data->exam_group_id,false);
  705. $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id));
  706. if($exam_group_data->homework==1){
  707. //发送学生端消息
  708. $sendJsonArr=array(
  709. 'school_id'=>$this->schoolId,
  710. 'send_type'=>'zsyas',
  711. 'update_type'=>0,
  712. 'exam_group_id'=>$exam_group_data->exam_group_id,
  713. );
  714. sendStudentCacheQueue($sendJsonArr);
  715. }
  716. if(Yii::app()->params['handle_log_on_off'])
  717. {
  718. Curl::post(Yii::app()->params['handle_log_api'], array(
  719. "exam_group_id" => 0,
  720. "operate_project" => 'zsyas2',
  721. "school_id" => $this->schoolId,
  722. "title" => '修改分数',
  723. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  724. "operate_method" => $this->action,
  725. "operate_url" => $this->getRoute(),
  726. "operate_sql" =>'',
  727. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  728. ));
  729. }
  730. echo json_encode(array('status'=>1,'msg'=>'修改成功'));exit;
  731. }
  732. }
  733. }
  734. }
  735. }
  736. }
  737. /*批量修改多选题规则*/
  738. public function actionChangeMultiRuleBatch(){
  739. ini_set('memory_limit', '500M');
  740. $exam_id = Req::post('exam_id');
  741. $topic_id = Req::post('topic_id');
  742. $type = Req::post('type');
  743. $rule = Req::post('rule');
  744. $score_m = Req::post('score_m');
  745. $score_half_m = Req::post('score_half_m');
  746. $answer = Req::post('answer');
  747. $result=array(
  748. 'status'=>0
  749. );
  750. if(!$exam_id || !$topic_id || !$type || !$rule) {
  751. exit(json_encode($result));
  752. }
  753. // if(!$score_m){
  754. // $result['msg']='分数不能为空';
  755. // exit(json_encode($result));
  756. // };
  757. if(!$score_half_m && $rule!=1){
  758. $result['msg']='半对分数不能为空';
  759. exit(json_encode($result));
  760. };
  761. // if($score_half_m>$score_m){
  762. // $result['msg']='半对分数不能大于满分';
  763. // exit(json_encode($result));
  764. // };
  765. if(!in_array($rule,array(1,2,3,4,5))){
  766. $result['msg']='评分规则错误';
  767. exit(json_encode($result));
  768. }
  769. $topicIdArr=explode('///',$topic_id);
  770. $topicAnswerArr=explode('///',$answer);
  771. $topicHalfScoreArr=explode('///',$score_half_m);
  772. if(!$topicIdArr || !$topicAnswerArr){
  773. $result['msg']='批量读取试题异常';
  774. exit(json_encode($result));
  775. }
  776. $topicIdAnswer=array();
  777. $topicIdHalfScore=array();
  778. $topicHalfScoreRelation=array();
  779. foreach ($topicIdArr as $key => $val){
  780. if(!isset($topicAnswerArr[$key])){
  781. $result['msg']='批量读取试题答案异常';
  782. exit(json_encode($result));
  783. }else{
  784. $topicIdAnswer[$val]=$topicAnswerArr[$key];
  785. $topicIdHalfScore[$val]=$topicHalfScoreArr[$key];
  786. }
  787. }
  788. $ExamModel=new SExam();
  789. $ExamInfo=$ExamModel->getDetailByExamId($exam_id);
  790. if(!$ExamInfo){
  791. $result['msg']='考试ID错误1';
  792. exit(json_encode($result));
  793. }
  794. $Exam_GroupId=$ExamInfo['exam_group_id'];
  795. $AllExam=Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$Exam_GroupId));
  796. $AllExamIds=array();
  797. $tplData=array();
  798. if($AllExam){
  799. foreach($AllExam as $val){
  800. if($val){
  801. $AllExamIds[]=$val['exam_id'];
  802. if(!$tplData){
  803. $tplData=json_decode($val['tpl_data'],true);
  804. }
  805. }
  806. }
  807. }
  808. if(!$AllExamIds){
  809. $result['msg']='考试ID错误2';
  810. exit(json_encode($result));
  811. }
  812. $AllPaperIds=array();
  813. $paperScore=array();
  814. $AllPaper=SPaper::model()->findAll('exam_id in('.implode(',',$AllExamIds).')');
  815. if($AllPaper){
  816. foreach ($AllPaper as $val){
  817. $AllPaperIds[]=$val['paper_id'];
  818. $paperScore[$val['paper_id']]=$val['score'];
  819. }
  820. }
  821. if(!$AllPaperIds){
  822. $result['msg']='考试ID错误3';
  823. exit(json_encode($result));
  824. }
  825. $paperTopicRelation=$this->sConn->createCommand("select `topic_id`,`order`,`type`,`score` from paper_topic_relation where paper_id='{$AllPaperIds[0]}' and topic_id in(".implode(',',$topicIdArr).") ")->queryAll();
  826. if(!$paperTopicRelation){
  827. $result['msg']='试卷试题有误';
  828. exit(json_encode($result));
  829. }
  830. $Rs=array();
  831. $topicScoreArr=array();
  832. $topicHalfScoreArr=array();
  833. foreach ($paperTopicRelation as $value){
  834. if($topicIdHalfScore[(string)$value['topic_id']]>$value['score']){
  835. $result['msg']='半对分数不能大于满分';
  836. exit(json_encode($result));
  837. }
  838. $topicScoreArr[$value['topic_id']]=$value['score'];
  839. }
  840. foreach ($AllPaperIds as $pid){
  841. $tempData=SStudentPaperTopicRs::model()->findAll("paper_id ='".$pid."' and topic_id in(".implode(',',$topicIdArr).")");
  842. if($tempData){
  843. foreach ($tempData as $v){
  844. $Rs[]=array(
  845. 'topic_id' =>$v['topic_id'],
  846. 'answer' =>$v['answer'],
  847. 'paper_id' =>$v['paper_id'],
  848. 'student_id' =>$v['student_id'],
  849. );
  850. }
  851. }
  852. }
  853. $updateRightData=array();
  854. $updateScoreData=array();
  855. $updateStudentPaperRelation=array();
  856. if($Rs){
  857. if(!$answer){
  858. $result['msg']='答案不能为空';
  859. exit(json_encode($result));
  860. }
  861. foreach ($Rs as $k=> $v){
  862. if(!isset($topicIdAnswer[$v['topic_id']])){
  863. continue;
  864. }
  865. $answer=$topicIdAnswer[$v['topic_id']];
  866. if(!$v['answer']){
  867. $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  868. $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  869. }else{
  870. if($v['answer'] == $answer){
  871. $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=1;
  872. $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=$topicScoreArr[$v['topic_id']];
  873. }else{
  874. switch ($rule){
  875. case 1: //规则A 最严格规则
  876. $update_data['scoring']=0;
  877. $update_data['is_right']=0;
  878. $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  879. $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  880. break;
  881. case 2://规则B 半对规则
  882. //查找错误选择
  883. $answerArr=explode(',',$answer);
  884. $tempAnswer = explode(',', $v['answer']);
  885. $FindWrong=false;
  886. foreach ($tempAnswer as $av) {
  887. if(!in_array($av,$answerArr)){
  888. $FindWrong=true;
  889. break;
  890. }
  891. }
  892. if($FindWrong){
  893. $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  894. $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  895. }else{
  896. $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;//半对算错
  897. $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=$topicIdHalfScore[$v['topic_id']];
  898. }
  899. break;
  900. case 3://规则C 宽松半对规则
  901. //查找正确选择
  902. $answerArr=explode(',',$answer);
  903. $tempAnswer = explode(',', $v['answer']);
  904. $IsWrong=true;
  905. if(count($tempAnswer)<=count($answerArr)){
  906. foreach ($tempAnswer as $av) {
  907. if (false !== strpos($answer, $av)) {
  908. $IsWrong=false;
  909. break;
  910. }
  911. }
  912. }
  913. //错误答案情况
  914. if($IsWrong){
  915. $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  916. $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  917. }else{
  918. $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;//半对算错
  919. $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=$topicIdHalfScore[$v['topic_id']];
  920. }
  921. break;
  922. case 4:
  923. $answerArr=explode(',',$answer);
  924. $tempAnswer = explode(',', $v['answer']);
  925. $IsWrong=true;
  926. if(count($tempAnswer)<=count($answerArr)){
  927. foreach ($tempAnswer as $av) {
  928. if (false !== strpos($answer, $av)) {
  929. $IsWrong=false;
  930. break;
  931. }
  932. }
  933. }
  934. //错误答案情况
  935. if($IsWrong){
  936. $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  937. $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  938. }else{
  939. //没有错误答案,且不全对,几个答案几分
  940. $score_half_m=count($tempAnswer);
  941. $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  942. $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=$score_half_m;
  943. }
  944. break;
  945. case 5:
  946. $answerArr=explode(',',$answer);
  947. $tempAnswer = explode(',', $v['answer']);
  948. $rightAnswerCount=0;
  949. if(count($tempAnswer)<=count($answerArr)){
  950. foreach ($tempAnswer as $av) {
  951. if (false !== strpos($answer, $av)) {
  952. $rightAnswerCount++;
  953. }
  954. }
  955. }
  956. $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  957. $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=$rightAnswerCount;
  958. break;
  959. }
  960. }
  961. }
  962. //更新总分queryAll
  963. $updateStudentPaperRelation[$v['student_id']]=$v['paper_id'];
  964. }
  965. }
  966. $updateStudentPaperRelationSql=array();
  967. if($updateRightData){
  968. $sqlIsRight=array();
  969. $sqlScore=array();
  970. foreach ($updateRightData as $paperId=>$val){
  971. foreach ($val as $topicId=>$v){
  972. $sql=" update `student_paper_topic_rs` set `is_right`= case `student_id` ";
  973. foreach ($v as $studentId=>$isRight){
  974. $sql.=" WHEN ".$studentId." THEN '".$isRight."' ";
  975. }
  976. $sql.=" Else `is_right`";
  977. $sql.=" End ";
  978. $sql.=" where paper_id='{$paperId}' and topic_id='{$topicId}'";
  979. $sqlIsRight[]=$sql;
  980. }
  981. }
  982. foreach ($updateScoreData as $paperId=>$val){
  983. foreach ($val as $topicId=>$v){
  984. $sql=" update `student_paper_topic_rs` set `scoring`= case `student_id` ";
  985. foreach ($v as $studentId=>$score){
  986. $sql.=" WHEN ".$studentId." THEN '".$score."' ";
  987. }
  988. $sql.=" Else `scoring`";
  989. $sql.=" End ";
  990. $sql.=" where paper_id='{$paperId}' and topic_id='{$topicId}'";
  991. $sqlScore[]=$sql;
  992. }
  993. }
  994. $transaction = $this->sConn->beginTransaction();
  995. try {
  996. if($sqlIsRight){
  997. foreach ($sqlIsRight as $sql){
  998. $this->sConn->createCommand($sql)->execute();
  999. }
  1000. }
  1001. if($sqlScore){
  1002. foreach ($sqlScore as $sql){
  1003. $this->sConn->createCommand($sql)->execute();
  1004. }
  1005. }
  1006. $transaction->commit();
  1007. } catch (Exception $e) {
  1008. //如果操作失败, 数据回滚
  1009. $transaction->rollback();
  1010. $result['status']=0;
  1011. $result['msg']=' 报告更新失败';
  1012. exit(json_encode($result));
  1013. }
  1014. if($updateStudentPaperRelation){
  1015. foreach ($updateStudentPaperRelation as $studentId =>$paperId){
  1016. $TotalScore = $paperScore[$paperId];
  1017. $StudentAllTopicSql="select `is_right`,`scoring` from `student_paper_topic_rs` where `paper_id`='".$paperId."' and student_id='".$studentId."' ";
  1018. $StudentAllTopic=$this->sConn->createCommand($StudentAllTopicSql)->queryAll();
  1019. $right_count = 0;
  1020. $partial_right_count = 0;
  1021. $wrong_count = 0;
  1022. $scoring = 0;
  1023. $lost_score = 0;
  1024. foreach ($StudentAllTopic as $value) {
  1025. if ($value['is_right'] == 1) {
  1026. $right_count++;
  1027. } elseif ($value['is_right'] == 2) {
  1028. $partial_right_count++;
  1029. } else {
  1030. $wrong_count++;
  1031. }
  1032. $scoring = bcadd($scoring, $value['scoring'], 1);
  1033. }
  1034. unset($StudentAllTopic);
  1035. $lost_score = bcsub($TotalScore, $scoring, 1);
  1036. $paperRelattionSql="update `student_paper_relation` set `right_count`='".$right_count."',`partial_right_count`='".$partial_right_count."',`wrong_count`='".$wrong_count."',`scoring`='".$scoring."',`lost_score`='".$lost_score."'";
  1037. $paperRelattionSql.=" where `paper_id`='".$paperId."' and `student_id`='".$studentId."'";
  1038. $updateStudentPaperRelationSql[]=$paperRelattionSql;
  1039. }
  1040. }
  1041. $transaction = $this->sConn->beginTransaction();
  1042. try {
  1043. if($updateStudentPaperRelationSql){
  1044. foreach ($updateStudentPaperRelationSql as $sql){
  1045. $this->sConn->createCommand($sql)->execute();
  1046. }
  1047. }
  1048. $sendParam=array(
  1049. 'school_id'=>$this->schoolId,
  1050. 'exam_group_id'=>$Exam_GroupId
  1051. );
  1052. $transaction->commit();
  1053. sendZsystNotic($sendParam);
  1054. $kafkaData=array(
  1055. 'schoolId'=>$this->schoolId,
  1056. 'examGroupId'=>$Exam_GroupId,
  1057. 'generateTime'=>time()*1000
  1058. );
  1059. sendDataToKafka("xbkc-academic-offline-generate-report",$kafkaData);
  1060. } catch (Exception $e) {
  1061. //如果操作失败, 数据回滚
  1062. $transaction->rollback();
  1063. $result['status']=0;
  1064. $result['msg']=' 报告更新失败';
  1065. exit(json_encode($result));
  1066. }
  1067. }
  1068. //记录新判分规则
  1069. $tplRules=array();
  1070. if(isset($tplData['new_rules'])){
  1071. $tplRules=$tplData['new_rules'];
  1072. }
  1073. foreach ($paperTopicRelation as $value){
  1074. if(in_array($value['topic_id'],$topicIdArr)){
  1075. if(isset($tplRules[$value['order']])){
  1076. $tplRules[$value['order']]['rule_type']=(int)$rule;
  1077. }else{
  1078. $rule_answer=isset($topicIdAnswer[$value['topic_id']])?$topicIdAnswer[$value['topic_id']]:'';
  1079. $rule_half_score=isset($topicIdHalfScore[$value['topic_id']])?$topicIdHalfScore[$value['topic_id']]:'0';
  1080. $tplRules[$value['order']]=array(
  1081. 'topicNo'=>$value['order'],
  1082. 'topic_id'=>$value['topic_id'],
  1083. 'rule_type'=>(int)$rule,
  1084. 'rule_answer'=>$rule_answer,
  1085. 'rule_score'=>'',
  1086. 'rule_score_half'=>$rule_half_score
  1087. );
  1088. }
  1089. }
  1090. }
  1091. if($tplRules){
  1092. $tplData['new_rules']=$tplRules;
  1093. $this->sConn->createCommand("update exam set tpl_data='".jsonEncode($tplData)."' where exam_group_id = '{$Exam_GroupId}'")->execute();
  1094. }
  1095. $this->sendNoticeToReport($Exam_GroupId);
  1096. if(Yii::app()->params['handle_log_on_off'])
  1097. {
  1098. Curl::post(Yii::app()->params['handle_log_api'], array(
  1099. "exam_group_id" => 0,
  1100. "operate_project" => 'zsyas2',
  1101. "school_id" => $this->schoolId,
  1102. "title" => '批量更新多选题报告',
  1103. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  1104. "operate_method" => $this->action,
  1105. "operate_url" => $this->getRoute(),
  1106. "operate_sql" =>'',
  1107. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  1108. ));
  1109. }
  1110. $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$Exam_GroupId));
  1111. if(isset($exam_group_data) && $exam_group_data->homework==1){
  1112. //发送学生端消息
  1113. $sendJsonArr=array(
  1114. 'school_id'=>$this->schoolId,
  1115. 'send_type'=>'zsyas',
  1116. 'update_type'=>0,
  1117. 'exam_group_id'=>$Exam_GroupId,
  1118. );
  1119. sendStudentCacheQueue($sendJsonArr);
  1120. }
  1121. $result['status']=1;
  1122. $result['msg']='报告更新完成';
  1123. exit(json_encode($result));
  1124. }
  1125. function _array_column(array $array, $column_key, $index_key=null){
  1126. $result = array();
  1127. foreach($array as $arr) {
  1128. if(!is_array($arr)) continue;
  1129. if(is_null($column_key)){
  1130. $value = $arr;
  1131. }else{
  1132. $value = $arr[$column_key];
  1133. }
  1134. if(!is_numeric($value)){
  1135. $value=intval($value);
  1136. }
  1137. if(!is_null($index_key)){
  1138. $key = $arr[$index_key];
  1139. $result[$key] = $value;
  1140. }else{
  1141. $result[] = $value;
  1142. }
  1143. }
  1144. return $result;
  1145. }
  1146. //更新报告后发送通知
  1147. private function sendNoticeToReport($examGroupId){
  1148. $url = Yii::app()->params['zsy_api_url'].'/qxk/academic/hm/report/external/exam/group/clear-cache/'.$examGroupId;
  1149. $username = $this->schoolInfo->school_id;
  1150. $password = md5($this->schoolId.Yii::app()->params['zsy_api_key']);
  1151. $curl = @curl_init();
  1152. $response=null;
  1153. if ($curl) {
  1154. curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  1155. curl_setopt($curl, CURLOPT_USERPWD, $username .':'. $password);
  1156. curl_setopt($curl, CURLOPT_HEADER, 0);
  1157. curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
  1158. curl_setopt($curl, CURLOPT_TIMEOUT, 10);
  1159. curl_setopt($curl, CURLOPT_URL, $url);
  1160. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
  1161. curl_setopt($curl, CURLOPT_HTTPHEADER, array(
  1162. 'Content-Type: application/json',
  1163. ));
  1164. $response = curl_exec($curl);
  1165. curl_close($curl);
  1166. }
  1167. return $response;
  1168. }
  1169. public function TransformTopicType($basicId,$answerTypeId,$checkBox){
  1170. $topicTypeId=0;
  1171. if(in_array($basicId,$this->topicTypeRelation['single'])){
  1172. $topicTypeId=1;
  1173. }elseif(in_array($basicId,$this->topicTypeRelation['multiple'])){
  1174. $topicTypeId=2;
  1175. }elseif(in_array($basicId,$this->topicTypeRelation['tian'])){
  1176. $topicTypeId=5;
  1177. }elseif(in_array($basicId,$this->topicTypeRelation['jie'])){
  1178. $topicTypeId=7;
  1179. }elseif(in_array($basicId,$this->topicTypeRelation['pan'])){
  1180. $topicTypeId=3;
  1181. }elseif ($basicId==13){
  1182. if($answerTypeId==1){
  1183. if($checkBox==1){
  1184. $topicTypeId=2;
  1185. }else{
  1186. $topicTypeId=1;
  1187. }
  1188. }elseif($answerTypeId==2){
  1189. $topicTypeId=5;
  1190. }elseif($answerTypeId==3){
  1191. $topicTypeId=7;
  1192. }elseif($answerTypeId==4){
  1193. $topicTypeId=3;
  1194. }else{
  1195. $topicTypeId=7;
  1196. }
  1197. }
  1198. return $topicTypeId;
  1199. }
  1200. //批量更新分数答案
  1201. public function actionUpdateScoreAnswerBatch(){
  1202. $changes = Req::post('change_data');
  1203. $paper_id = Req::post('paper_id');
  1204. // $changes=array(
  1205. // [
  1206. // 'answer'=>'A',
  1207. // 'score'=>'',
  1208. // 'topic_id'=>'201511100026379'
  1209. // ]
  1210. // );
  1211. if(!$changes){
  1212. echo json_encode(array('status'=>0,'msg'=>'参数异常'));exit;
  1213. }
  1214. $changeTopicData=array();
  1215. $topicIds=array();
  1216. foreach ($changes as $change){
  1217. $topicIds[]=$change['topic_id'];
  1218. $changeTopicData[(string)$change['topic_id']]=array();
  1219. if($change['answer']){
  1220. if($change['answer']=='√'){
  1221. $change['answer']='T';
  1222. }elseif($change['answer']=='×'){
  1223. $change['answer']='F';
  1224. }
  1225. $changeTopicData[(string)$change['topic_id']]['answer']=$change['answer'];
  1226. }else{
  1227. $changeTopicData[(string)$change['topic_id']]['answer']='';
  1228. }
  1229. if($change['score']){
  1230. $changeTopicData[(string)$change['topic_id']]['score']=$change['score'];
  1231. }else{
  1232. $changeTopicData[(string)$change['topic_id']]['score']='';
  1233. }
  1234. }
  1235. $topicType=0;
  1236. $paper_topic_data = SPaperTopicRelation::model()->findAll(array('order'=>'`no` asc ,`type` asc ,`order` asc','condition'=>'`paper_id`=:paper_id ','params'=>array(':paper_id'=>$paper_id)));
  1237. $oldTopicScores=0; //原总分
  1238. $newTopicScores=array(); //修改后总分
  1239. $update_score=array(); //需要修改分数的topic
  1240. $update_score_order=array(); //修改分数的序号
  1241. $oldTopicScore=array();
  1242. $changeTopicOrder=array();
  1243. $choiseTYpeArr=array(1,2,3,4,12);
  1244. $isChoice=true; //修改的题型是选择?
  1245. $updateAnswer=array();
  1246. if($paper_topic_data)
  1247. {
  1248. foreach($paper_topic_data as $v)
  1249. {
  1250. if(isset($changeTopicData[(string)$v['topic_id']])){
  1251. $changeTopicOrder[$v['order']]=$changeTopicData[(string)$v['topic_id']];
  1252. if($changeTopicData[$v['topic_id']]['score']){
  1253. $update_score[$v->topic_id] = $changeTopicData[(string)$v['topic_id']]['score'];
  1254. $update_score_order[$v->order] = $changeTopicData[(string)$v['topic_id']]['score'];
  1255. }else{
  1256. $oldTopicScore[(string)$v['topic_id']]=$v['score'];
  1257. }
  1258. if($changeTopicData[(string)$v['topic_id']]['answer']){
  1259. $updateAnswer[$v['order']]=array(
  1260. 'order'=>$v['order'],
  1261. 'topic_id'=>$v['topic_id'],
  1262. 'update_answer'=>$changeTopicData[(string)$v['topic_id']]['answer']
  1263. );
  1264. }
  1265. }else{
  1266. $newTopicScores[]=$v['score'];
  1267. }
  1268. }
  1269. }
  1270. $paper_data = SPaper::model()->find('paper_id=:paper_id',array(':paper_id'=>$paper_id));
  1271. $exam_ids = array();
  1272. $paper_ids = array();
  1273. if($paper_data)
  1274. {
  1275. $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$paper_data->exam_id));
  1276. if($exam_data)
  1277. {
  1278. $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id));
  1279. $tpl_data = json_decode($exam_data->tpl_data,true);
  1280. $exam_all_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id));
  1281. //修改new_items
  1282. if(isset($tpl_data['new_items'])){
  1283. foreach ($tpl_data['new_items'] as $key =>$val){
  1284. if(isset($changeTopicOrder[$val['id']]) && $changeTopicOrder[$val['id']]['score']){
  1285. $tpl_data['new_items'][$key]['score']=$changeTopicOrder[$val['id']]['score'];
  1286. }
  1287. }
  1288. }
  1289. //修改答案记录
  1290. if($updateAnswer){
  1291. foreach ($updateAnswer as $order=>$item){
  1292. if(!isset($tpl_data['update_answer'])){
  1293. $tpl_data['update_answer']=array();
  1294. }
  1295. $tpl_data['update_answer'][$order]=$item;
  1296. if($exam_group_data['is_third']==1){
  1297. $this->UpdateTopicAnswer($item['topic_id'],$item['update_answer'],1);
  1298. }
  1299. }
  1300. }
  1301. $paper_score=$this->sumTplDataScores($tpl_data,0);
  1302. $tpl_data['scores']=$paper_score;
  1303. $tpl_data['total_score']=$paper_score;
  1304. $json_tpl_data = jsonEncode($tpl_data);
  1305. if($exam_all_data)
  1306. {
  1307. foreach($exam_all_data as $v)
  1308. {
  1309. $exam_ids[$v->exam_id] = $v->exam_id;
  1310. }
  1311. if($exam_ids)
  1312. {
  1313. $criteria = new CDbCriteria();
  1314. $criteria->addInCondition('exam_id',$exam_ids);
  1315. $paper_data = SPaper::model()->findAll($criteria);
  1316. if($paper_data)
  1317. {
  1318. foreach($paper_data as $v)
  1319. {
  1320. $paper_ids[$v->paper_id] = $v->paper_id;
  1321. }
  1322. $trans = $this->sConn->beginTransaction();
  1323. try{
  1324. foreach ($changeTopicData as $topic_id => $item){
  1325. if(isset($item['score']) && $item['score']){
  1326. $sql='update `paper_topic_relation` set `score` = '.$item['score'].' where paper_id in ('.implode(',',$paper_ids).') and `topic_id` ='.$topic_id;
  1327. $this->sConn->createCommand($sql)->execute();
  1328. }
  1329. if(isset($item['answer']) && $item['answer']){
  1330. //查询选旧答案,得分的学生
  1331. $updateStudentSql="select student_id,scoring from student_paper_topic_rs where paper_id in (".implode(',',$paper_ids).") and `topic_id` = '".$topic_id."' and is_right=1 ";
  1332. $students=$this->sConn->createCommand($updateStudentSql)->queryAll();
  1333. if($students){
  1334. $studentIds=array();
  1335. $oldScore=0;
  1336. foreach ($students as $v){
  1337. $studentIds[]=$v['student_id'];
  1338. if(!$oldScore){
  1339. $oldScore=$v['scoring'];
  1340. }
  1341. }
  1342. $sql="update student_paper_topic_rs set scoring='0',is_right=0 where paper_id in (".implode(',',$paper_ids).") and `topic_id` = '".$topic_id."' and is_right=1 ";
  1343. $this->sConn->createCommand($sql)->execute();
  1344. $sql="update student_paper_relation set scoring=scoring-".$oldScore." where paper_id in (".implode(',',$paper_ids).") and student_id in(".implode(',',$studentIds).") ";
  1345. $this->sConn->createCommand($sql)->execute();
  1346. }
  1347. //查询选新答案的学生
  1348. $updateStudentSql="select student_id from student_paper_topic_rs where paper_id in (".implode(',',$paper_ids).") and `topic_id` = '".$topic_id."' and answer='".$item['answer']."' ";
  1349. $students=$this->sConn->createCommand($updateStudentSql)->queryAll();
  1350. if($students){
  1351. $studentIds=array();
  1352. foreach ($students as $v){
  1353. $studentIds[]=$v['student_id'];
  1354. }
  1355. $score=0;
  1356. if(isset($item['score']) && $item['score']){
  1357. $score=$item['score'];
  1358. }else{
  1359. $score=$oldTopicScore[$topic_id];
  1360. }
  1361. $sql="update student_paper_topic_rs set scoring='".$score."',is_right=1 where paper_id in (".implode(',',$paper_ids).") and `topic_id` = '".$topic_id."' and student_id in(".implode(',',$studentIds).")";
  1362. $this->sConn->createCommand($sql)->execute();
  1363. $sql="update student_paper_relation set scoring=scoring+".$score." where paper_id in (".implode(',',$paper_ids).") and student_id in(".implode(',',$studentIds).") ";
  1364. $this->sConn->createCommand($sql)->execute();
  1365. }
  1366. }elseif(isset($item['score']) && $item['score']){
  1367. //查询选旧答案,得分的学生
  1368. $updateStudentSql="select student_id,scoring from student_paper_topic_rs where paper_id in (".implode(',',$paper_ids).") and `topic_id` = '".$topic_id."' and is_right=1 ";
  1369. $students=$this->sConn->createCommand($updateStudentSql)->queryAll();
  1370. if($students){
  1371. $studentIds=array();
  1372. $oldScore=0;
  1373. foreach ($students as $v){
  1374. $studentIds[]=$v['student_id'];
  1375. if(!$oldScore){
  1376. $oldScore=$v['scoring'];
  1377. }
  1378. }
  1379. $sql="update student_paper_topic_rs set scoring='".$item['score']."' where paper_id in (".implode(',',$paper_ids).") and `topic_id` = '".$topic_id."' and is_right=1 ";
  1380. $this->sConn->createCommand($sql)->execute();
  1381. $sql="update student_paper_relation set scoring=scoring+".($item['score']-$oldScore)." where paper_id in (".implode(',',$paper_ids).") and student_id in(".implode(',',$studentIds).") ";
  1382. $this->sConn->createCommand($sql)->execute();
  1383. }
  1384. }
  1385. }
  1386. $sql='update `paper` set `score` = '.($paper_score).' where paper_id in ('.implode(',',$paper_ids).')';
  1387. $this->sConn->createCommand($sql)->execute();
  1388. $sql="update `exam` set `tpl_data` = '".($json_tpl_data)."' where exam_id in (".implode(',',$exam_ids).")";
  1389. $this->sConn->createCommand($sql)->execute();
  1390. $trans->commit();
  1391. }
  1392. catch(Exception $e){
  1393. $trans->rollBack();
  1394. echo json_encode(array('status'=>0));exit;
  1395. }
  1396. //学生端接口
  1397. $sendParam=array(
  1398. 'school_id'=>$this->schoolId,
  1399. 'exam_group_id'=>$exam_data->exam_group_id
  1400. );
  1401. sendZsystNotic($sendParam);
  1402. $kafkaData=array(
  1403. 'schoolId'=>$this->schoolId,
  1404. 'examGroupId'=>$exam_data->exam_group_id,
  1405. 'generateTime'=>time()*1000
  1406. );
  1407. sendDataToKafka("xbkc-academic-generate-report",$kafkaData);
  1408. $this->sendNoticeToReport($exam_data->exam_group_id);
  1409. sendDataToKafka("zsy-marking-update-topic",$exam_data->exam_group_id,false);
  1410. if($exam_group_data->homework==1){
  1411. //发送学生端消息
  1412. $sendJsonArr=array(
  1413. 'school_id'=>$this->schoolId,
  1414. 'send_type'=>'zsyas',
  1415. 'update_type'=>0,
  1416. 'exam_group_id'=>$exam_group_data->exam_group_id,
  1417. );
  1418. sendStudentCacheQueue($sendJsonArr);
  1419. }
  1420. if(Yii::app()->params['handle_log_on_off'])
  1421. {
  1422. Curl::post(Yii::app()->params['handle_log_api'], array(
  1423. "exam_group_id" => 0,
  1424. "operate_project" => 'zsyas2',
  1425. "school_id" => $this->schoolId,
  1426. "title" => '修改分数',
  1427. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  1428. "operate_method" => $this->action,
  1429. "operate_url" => $this->getRoute(),
  1430. "operate_sql" =>'',
  1431. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  1432. ));
  1433. }
  1434. echo json_encode(array('status'=>1,'msg'=>'修改成功'));exit;
  1435. }
  1436. }
  1437. }
  1438. }
  1439. }
  1440. }
  1441. //处理tpl_data,计算部分
  1442. private function sumTplDataScores($select_info,$is_third){
  1443. $TotalScore = 0; //计算可能多分组情况总分
  1444. $sameGroupTopic=array();
  1445. $groupScoreArr=array();
  1446. $required=1;
  1447. $qxk=0;
  1448. if(isset($select_info['required'])){
  1449. $required=$select_info['required'];
  1450. }elseif(isset($select_info['items'][17])){
  1451. $required=$select_info['items'][17]['required'];
  1452. }
  1453. if ($select_info) {
  1454. if ($select_info && isset($select_info['new_items']) && !empty($select_info['new_items'])) {
  1455. $nowGroupId = 0; //分组标志
  1456. foreach ($select_info['new_items'] as $k => $sc) {
  1457. if(isset($sc['basicTopicType']) && $sc['basicTopicType'] && !$qxk){
  1458. $qxk=1;
  1459. }
  1460. //分组判断
  1461. if(($sc['topic_type']==17 || (isset($sc['sameAliasNo']) && $sc['sameAliasNo'])) && !$sc['group_id']){
  1462. $sc['group_id']=1000;
  1463. }
  1464. if (!isset($sc['group_id']) || !$sc['group_id']) {
  1465. $TotalScore += $sc['score'];
  1466. } else{
  1467. if(isset($sc['smTopicLen']) && $sc['smTopicLen'] && !$qxk){
  1468. //在线多组,另计
  1469. }else{
  1470. $groupScoreArr[$sc['group_id']][]=$sc['score'];
  1471. }
  1472. }
  1473. if(isset($sc['sameAliasNo']) && $sc['sameAliasNo'] && !$qxk){
  1474. $sameGroupTopic[$sc['group_id']][$sc['sameAliasNo']][]=$sc['score'];
  1475. }
  1476. }
  1477. if($sameGroupTopic){
  1478. foreach ($sameGroupTopic as $gid =>$value){
  1479. $value=array_values($value);
  1480. $TotalScore+=array_sum($value[0]);
  1481. }
  1482. }
  1483. if($groupScoreArr){
  1484. if($is_third){
  1485. //多组,多选一
  1486. foreach ($groupScoreArr as $gid =>$item){
  1487. $TotalScore+=$item[0];
  1488. }
  1489. }else{
  1490. //一组,多选多
  1491. $groupScoreArr=array_values($groupScoreArr);
  1492. $TotalScore+=array_sum(array_slice($groupScoreArr[0],0,$required));
  1493. }
  1494. }
  1495. }
  1496. }
  1497. return $TotalScore;
  1498. }
  1499. /*批量修改多选题规则*/
  1500. public function actionChangeMultiRuleBatchNew(){
  1501. ini_set('memory_limit', '500M');
  1502. $exam_id = Req::post('exam_id');
  1503. $topicData = Req::post('topic_data');
  1504. $result=array(
  1505. 'status'=>0
  1506. );
  1507. if(!$exam_id || !$topicData ) {
  1508. exit(json_encode($result));
  1509. }
  1510. $topicIds=array();
  1511. $topicIdArr=array();
  1512. foreach ($topicData as $item){
  1513. $topicIds[]=$item['topic_id'];
  1514. // if($item['rule']!=1 && !$item['half_score']){
  1515. // $result['msg']='半对分数不能为空';
  1516. // exit(json_encode($result));
  1517. // }
  1518. if(!in_array($item['rule'],array(1,2,3,4,5))){
  1519. $result['msg']='评分规则错误';
  1520. exit(json_encode($result));
  1521. }
  1522. if($item['half_score']>$item['score']){
  1523. $result['msg']='半对分数不能大于满分';
  1524. exit(json_encode($result));
  1525. }
  1526. $topicIdArr[(string)$item['topic_id']]=$item;
  1527. if($item['answer']){
  1528. $this->UpdateTopicAnswer($item['topic_id'],$item['answer'],1);
  1529. }
  1530. }
  1531. if(!$topicIdArr){
  1532. $result['msg']='批量读取试题异常';
  1533. exit(json_encode($result));
  1534. }
  1535. $ExamModel=new SExam();
  1536. $ExamInfo=$ExamModel->getDetailByExamId($exam_id);
  1537. if(!$ExamInfo){
  1538. $result['msg']='考试ID错误1';
  1539. exit(json_encode($result));
  1540. }
  1541. $Exam_GroupId=$ExamInfo['exam_group_id'];
  1542. $AllExam=Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$Exam_GroupId));
  1543. $AllExamIds=array();
  1544. $tplData=array();
  1545. if($AllExam){
  1546. foreach($AllExam as $val){
  1547. if($val){
  1548. $AllExamIds[]=$val['exam_id'];
  1549. if(!$tplData){
  1550. $tplData=json_decode($val['tpl_data'],true);
  1551. }
  1552. }
  1553. }
  1554. }
  1555. if(!$AllExamIds){
  1556. $result['msg']='考试ID错误2';
  1557. exit(json_encode($result));
  1558. }
  1559. $AllPaperIds=array();
  1560. $paperScore=array();
  1561. $AllPaper=SPaper::model()->findAll('exam_id in('.implode(',',$AllExamIds).')');
  1562. if($AllPaper){
  1563. foreach ($AllPaper as $val){
  1564. $AllPaperIds[]=$val['paper_id'];
  1565. $paperScore[$val['paper_id']]=$val['score'];
  1566. }
  1567. }
  1568. if(!$AllPaperIds){
  1569. $result['msg']='考试ID错误3';
  1570. exit(json_encode($result));
  1571. }
  1572. $paperTopicRelation=$this->sConn->createCommand("select `topic_id`,`order`,`type`,`score` from paper_topic_relation where paper_id='{$AllPaperIds[0]}' and topic_id in(".implode(',',$topicIds).") ")->queryAll();
  1573. if(!$paperTopicRelation){
  1574. $result['msg']='试卷试题有误';
  1575. exit(json_encode($result));
  1576. }
  1577. //更新规则
  1578. $tplRules=array();
  1579. if(isset($tplData['new_rules'])){
  1580. $tplRules=$tplData['new_rules'];
  1581. }
  1582. $updatePaperScoreSql=array();
  1583. foreach ($paperTopicRelation as $value){
  1584. if(isset($topicIdArr[(string)$value['topic_id']])){
  1585. $order=$value['order'];
  1586. $newScore=$topicIdArr[(string)$value['topic_id']]['score'];
  1587. $tplRules[$value['order']]=array(
  1588. 'topicNo'=>$value['order'],
  1589. 'topic_id'=>$value['topic_id'],
  1590. 'rule_type'=>(int)$topicIdArr[(string)$value['topic_id']]['rule'],
  1591. 'rule_answer'=>$topicIdArr[(string)$value['topic_id']]['answer'],
  1592. 'rule_score'=>$newScore,
  1593. 'rule_score_half'=>$topicIdArr[(string)$value['topic_id']]['half_score'],
  1594. );
  1595. if($value['score']!==$newScore){
  1596. if(isset($tplData['new_items'])){
  1597. foreach ($tplData['new_items'] as $key => $val){
  1598. if($val['id']==$order){
  1599. $tplData['new_items'][$key]['score']=$newScore;
  1600. }
  1601. }
  1602. }
  1603. $updatePaperScoreSql[] = 'update `paper_topic_relation` set `score` = ' . $newScore . ' where paper_id in (' . implode(',', $AllPaperIds) . ') and `topic_id` =' . $value['topic_id'];
  1604. }
  1605. }
  1606. }
  1607. $tplData['new_rules']=$tplRules;
  1608. $paperScore=$this->sumTplDataScores($tplData,0);
  1609. $Rs=array();
  1610. $tplData['scores']=$paperScore;
  1611. $tplData['total_score']=$paperScore;
  1612. foreach ($AllPaperIds as $pid){
  1613. $tempData=SStudentPaperTopicRs::model()->findAll("paper_id ='".$pid."' and topic_id in(".implode(',',$topicIds).")");
  1614. if($tempData){
  1615. foreach ($tempData as $v){
  1616. $Rs[]=array(
  1617. 'topic_id' =>$v['topic_id'],
  1618. 'answer' =>$v['answer'],
  1619. 'paper_id' =>$v['paper_id'],
  1620. 'student_id' =>$v['student_id'],
  1621. );
  1622. }
  1623. }
  1624. }
  1625. $updateRightData=array();
  1626. $updateScoreData=array();
  1627. $updateStudentPaperRelation=array();
  1628. if($Rs){
  1629. foreach ($Rs as $k=> $v){
  1630. $answer=$topicIdArr[(string)$v['topic_id']]['answer'];
  1631. $rule=$topicIdArr[(string)$v['topic_id']]['rule'];
  1632. if(!$v['answer']){
  1633. $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  1634. $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  1635. }else{
  1636. if($v['answer'] == $answer){
  1637. $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=1;
  1638. $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=$topicIdArr[$v['topic_id']]['score'];
  1639. }else{
  1640. switch ($rule){
  1641. case 1: //规则A 最严格规则
  1642. $update_data['scoring']=0;
  1643. $update_data['is_right']=0;
  1644. $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  1645. $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  1646. break;
  1647. case 2://规则B 半对规则
  1648. //查找错误选择
  1649. $answerArr=explode(',',$answer);
  1650. $tempAnswer = explode(',', $v['answer']);
  1651. $FindWrong=false;
  1652. foreach ($tempAnswer as $av) {
  1653. if(!in_array($av,$answerArr)){
  1654. $FindWrong=true;
  1655. break;
  1656. }
  1657. }
  1658. if($FindWrong){
  1659. $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  1660. $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  1661. }else{
  1662. $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;//半对算错
  1663. $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=$topicIdArr[$v['topic_id']]['half_score'];
  1664. }
  1665. break;
  1666. case 3://规则C 宽松半对规则
  1667. //查找正确选择
  1668. $answerArr=explode(',',$answer);
  1669. $tempAnswer = explode(',', $v['answer']);
  1670. $IsWrong=true;
  1671. if(count($tempAnswer)<=count($answerArr)){
  1672. foreach ($tempAnswer as $av) {
  1673. if (false !== strpos($answer, $av)) {
  1674. $IsWrong=false;
  1675. break;
  1676. }
  1677. }
  1678. }
  1679. //错误答案情况
  1680. if($IsWrong){
  1681. $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  1682. $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
  1683. }else{
  1684. $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;//半对算错
  1685. $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=$topicIdArr[$v['topic_id']]['half_score'];
  1686. }
  1687. break;
  1688. }
  1689. }
  1690. }
  1691. //更新总分queryAll
  1692. $updateStudentPaperRelation[$v['student_id']]=$v['paper_id'];
  1693. }
  1694. }
  1695. $updateStudentPaperRelationSql=array();
  1696. if($updateRightData){
  1697. $sqlIsRight=array();
  1698. $sqlScore=array();
  1699. foreach ($updateRightData as $paperId=>$val){
  1700. foreach ($val as $topicId=>$v){
  1701. $sql=" update `student_paper_topic_rs` set `is_right`= case `student_id` ";
  1702. foreach ($v as $studentId=>$isRight){
  1703. $sql.=" WHEN ".$studentId." THEN '".$isRight."' ";
  1704. }
  1705. $sql.=" Else `is_right`";
  1706. $sql.=" End ";
  1707. $sql.=" where paper_id='{$paperId}' and topic_id='{$topicId}'";
  1708. $sqlIsRight[]=$sql;
  1709. }
  1710. }
  1711. foreach ($updateScoreData as $paperId=>$val){
  1712. foreach ($val as $topicId=>$v){
  1713. $sql=" update `student_paper_topic_rs` set `scoring`= case `student_id` ";
  1714. foreach ($v as $studentId=>$score){
  1715. $sql.=" WHEN ".$studentId." THEN '".$score."' ";
  1716. }
  1717. $sql.=" Else `scoring`";
  1718. $sql.=" End ";
  1719. $sql.=" where paper_id='{$paperId}' and topic_id='{$topicId}'";
  1720. $sqlScore[]=$sql;
  1721. }
  1722. }
  1723. $transaction = $this->sConn->beginTransaction();
  1724. try {
  1725. if($sqlIsRight){
  1726. foreach ($sqlIsRight as $sql){
  1727. $this->sConn->createCommand($sql)->execute();
  1728. }
  1729. }
  1730. if($sqlScore){
  1731. foreach ($sqlScore as $sql){
  1732. $this->sConn->createCommand($sql)->execute();
  1733. }
  1734. }
  1735. $transaction->commit();
  1736. } catch (Exception $e) {
  1737. //如果操作失败, 数据回滚
  1738. $transaction->rollback();
  1739. $result['status']=0;
  1740. $result['msg']=' 报告更新失败';
  1741. exit(json_encode($result));
  1742. }
  1743. if($updateStudentPaperRelation){
  1744. foreach ($updateStudentPaperRelation as $studentId =>$paperId){
  1745. $TotalScore = $paperScore[$paperId];
  1746. $StudentAllTopicSql="select `is_right`,`scoring` from `student_paper_topic_rs` where `paper_id`='".$paperId."' and student_id='".$studentId."' ";
  1747. $StudentAllTopic=$this->sConn->createCommand($StudentAllTopicSql)->queryAll();
  1748. $right_count = 0;
  1749. $partial_right_count = 0;
  1750. $wrong_count = 0;
  1751. $scoring = 0;
  1752. $lost_score = 0;
  1753. foreach ($StudentAllTopic as $value) {
  1754. if ($value['is_right'] == 1) {
  1755. $right_count++;
  1756. } elseif ($value['is_right'] == 2) {
  1757. $partial_right_count++;
  1758. } else {
  1759. $wrong_count++;
  1760. }
  1761. $scoring = bcadd($scoring, $value['scoring'], 1);
  1762. }
  1763. unset($StudentAllTopic);
  1764. $lost_score = bcsub($TotalScore, $scoring, 1);
  1765. $paperRelattionSql="update `student_paper_relation` set `right_count`='".$right_count."',`partial_right_count`='".$partial_right_count."',`wrong_count`='".$wrong_count."',`scoring`='".$scoring."',`lost_score`='".$lost_score."'";
  1766. $paperRelattionSql.=" where `paper_id`='".$paperId."' and `student_id`='".$studentId."'";
  1767. $updateStudentPaperRelationSql[]=$paperRelattionSql;
  1768. }
  1769. }
  1770. $transaction = $this->sConn->beginTransaction();
  1771. try {
  1772. if($updateStudentPaperRelationSql){
  1773. foreach ($updateStudentPaperRelationSql as $sql){
  1774. $this->sConn->createCommand($sql)->execute();
  1775. }
  1776. }
  1777. $sendParam=array(
  1778. 'school_id'=>$this->schoolId,
  1779. 'exam_group_id'=>$Exam_GroupId
  1780. );
  1781. $transaction->commit();
  1782. //学生端接口
  1783. $sendParam=array(
  1784. 'school_id'=>$this->schoolId,
  1785. 'exam_group_id'=>$Exam_GroupId
  1786. );
  1787. sendZsystNotic($sendParam);
  1788. $kafkaData=array(
  1789. 'schoolId'=>$this->schoolId,
  1790. 'examGroupId'=>$Exam_GroupId,
  1791. 'generateTime'=>time()*1000
  1792. );
  1793. sendDataToKafka("xbkc-academic-generate-report",$kafkaData);
  1794. $this->sendNoticeToReport($Exam_GroupId);
  1795. sendDataToKafka("zsy-marking-update-topic",$Exam_GroupId,false);
  1796. $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$Exam_GroupId));
  1797. if($exam_group_data->homework==1){
  1798. //发送学生端消息
  1799. $sendJsonArr=array(
  1800. 'school_id'=>$this->schoolId,
  1801. 'send_type'=>'zsyas',
  1802. 'update_type'=>0,
  1803. 'exam_group_id'=>$exam_group_data->exam_group_id,
  1804. );
  1805. sendStudentCacheQueue($sendJsonArr);
  1806. }
  1807. } catch (Exception $e) {
  1808. //如果操作失败, 数据回滚
  1809. $transaction->rollback();
  1810. $result['status']=0;
  1811. $result['msg']=' 报告更新失败';
  1812. exit(json_encode($result));
  1813. }
  1814. }
  1815. if($updatePaperScoreSql){
  1816. foreach ($updatePaperScoreSql as $sql){
  1817. $this->sConn->createCommand($sql)->execute();
  1818. }
  1819. }
  1820. $sql = 'update `paper` set `score` = ' . $tplData['scores'] . ' where paper_id in (' . implode(',', $AllPaperIds) . ')';
  1821. $this->sConn->createCommand($sql)->execute();
  1822. $this->sConn->createCommand("update exam set tpl_data='" . jsonEncode($tplData) . "' where exam_group_id = '{$Exam_GroupId}'")->execute();
  1823. $this->sendNoticeToReport($Exam_GroupId);
  1824. if(Yii::app()->params['handle_log_on_off'])
  1825. {
  1826. Curl::post(Yii::app()->params['handle_log_api'], array(
  1827. "exam_group_id" => 0,
  1828. "operate_project" => 'zsyas2',
  1829. "school_id" => $this->schoolId,
  1830. "title" => '批量更新多选题报告',
  1831. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  1832. "operate_method" => $this->action,
  1833. "operate_url" => $this->getRoute(),
  1834. "operate_sql" =>'',
  1835. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  1836. ));
  1837. }
  1838. $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$Exam_GroupId));
  1839. if(isset($exam_group_data) && $exam_group_data->homework==1){
  1840. //发送学生端消息
  1841. $sendJsonArr=array(
  1842. 'school_id'=>$this->schoolId,
  1843. 'send_type'=>'zsyas',
  1844. 'update_type'=>0,
  1845. 'exam_group_id'=>$Exam_GroupId,
  1846. );
  1847. sendStudentCacheQueue($sendJsonArr);
  1848. }
  1849. $result['status']=1;
  1850. $result['msg']='报告更新完成';
  1851. exit(json_encode($result));
  1852. }
  1853. //更新选做题分数
  1854. public function actionUpdateScoreXuan(){
  1855. $scores = Req::post('scores');
  1856. $paper_id = Req::post('paper_id');
  1857. if(!$scores) {
  1858. echo json_encode(array('status'=>0,'msg'=>'试题参数错误 '));
  1859. exit;
  1860. }
  1861. $paper_data = SPaper::model()->find('paper_id=:paper_id',array(':paper_id'=>$paper_id));
  1862. if(!$paper_data){
  1863. echo json_encode(array('status'=>0,'msg'=>'试卷Id参数错误 '));exit;
  1864. }
  1865. $exam_data=Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$paper_data->exam_id));
  1866. $xuan_topic=array();
  1867. $tpl_data = json_decode($exam_data->tpl_data,true);
  1868. foreach ($tpl_data['new_items'] as $val){
  1869. if(isset($val['sameAliasNo']) && $val['sameAliasNo']) {
  1870. $xuan_topic[$val['id']] = $val['id'];
  1871. }
  1872. }
  1873. $topicType=17;
  1874. $paper_topic_data = SPaperTopicRelation::model()->findAll(array('order'=>'`no` asc ,`type` asc ,`order` asc','condition'=>'`paper_id`=:paper_id ','params'=>array(':paper_id'=>$paper_id)));
  1875. $oldTopicScores=0; //原总分
  1876. $newTopicScores=array(); //修改后总分
  1877. $update_score=array(); //需要修改分数的topic
  1878. $update_score_order=array(); //修改分数的序号
  1879. if($paper_topic_data)
  1880. {
  1881. foreach($paper_topic_data as $v)
  1882. {
  1883. $oldTopicScores+=$v['score'];
  1884. if(isset($xuan_topic[$v['order']])){
  1885. if(isset($scores[$v['order']])){
  1886. if($v['score']!=$scores[$v['order']]){
  1887. $update_score[$v->topic_id] = $scores[$v->order];
  1888. $update_score_order[$v->order] = $scores[$v->order];
  1889. }
  1890. $newTopicScores[]=$scores[$v['order']];
  1891. }else{
  1892. $newTopicScores[]=$v['score'];
  1893. }
  1894. }
  1895. }
  1896. }
  1897. if(!$update_score){
  1898. echo json_encode(array('status'=>0,'msg'=>'分数与原试题分数一致'));exit;
  1899. }
  1900. $paper_data = SPaper::model()->find('paper_id=:paper_id',array(':paper_id'=>$paper_id));
  1901. $exam_ids = array();
  1902. $paper_ids = array();
  1903. if($paper_data)
  1904. {
  1905. if(isset($tpl_data['items'])){
  1906. $objectiveTplData=array(
  1907. 'total'=>count($scores),
  1908. 'totalScore'=>array_sum($newTopicScores),
  1909. 'perScores'=>array_values($newTopicScores)
  1910. );
  1911. $tpl_data['items'][$topicType]=$objectiveTplData;
  1912. }
  1913. //修改new_items
  1914. if(isset($tpl_data['new_items'])){
  1915. foreach ($tpl_data['new_items'] as $key =>$val){
  1916. if(isset($update_score_order[$val['id']])){
  1917. $tpl_data['new_items'][$key]['score']=$update_score_order[$val['id']];
  1918. }
  1919. }
  1920. }
  1921. $paper_score=$this->sumTplDataScores($tpl_data,0);
  1922. $tpl_data['scores']= $tpl_data['total_score']=$paper_score;
  1923. $json_tpl_data = jsonEncode($tpl_data);
  1924. $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id));
  1925. if($exam_group_data)
  1926. {
  1927. foreach($exam_group_data as $v)
  1928. {
  1929. $exam_ids[$v->exam_id] = $v->exam_id;
  1930. }
  1931. if($exam_ids)
  1932. {
  1933. $criteria = new CDbCriteria();
  1934. $criteria->addInCondition('exam_id',$exam_ids);
  1935. $paper_data = SPaper::model()->findAll($criteria);
  1936. if($paper_data)
  1937. {
  1938. foreach($paper_data as $v)
  1939. {
  1940. $paper_ids[$v->paper_id] = $v->paper_id;
  1941. }
  1942. $trans = $this->sConn->beginTransaction();
  1943. try{
  1944. foreach ($update_score as $topic_id => $score){
  1945. $sql='update `paper_topic_relation` set `score` = '.$score.' where paper_id in ('.implode(',',$paper_ids).') and `topic_id` ='.$topic_id;
  1946. $this->sConn->createCommand($sql)->execute();
  1947. }
  1948. $sql='update `paper` set `score` = '.($paper_score).' where paper_id in ('.implode(',',$paper_ids).')';
  1949. $this->sConn->createCommand($sql)->execute();
  1950. $sql="update `exam` set `tpl_data` = '".($json_tpl_data)."' where exam_id in (".implode(',',$exam_ids).")";
  1951. $this->sConn->createCommand($sql)->execute();
  1952. $trans->commit();
  1953. }
  1954. catch(Exception $e){
  1955. $trans->rollBack();
  1956. echo json_encode(array('status'=>0));exit;
  1957. }
  1958. $sendParam=array(
  1959. 'school_id'=>$this->schoolId,
  1960. 'exam_group_id'=>$exam_data->exam_group_id
  1961. );
  1962. sendZsystNotic($sendParam);
  1963. $kafkaData=array(
  1964. 'schoolId'=>$this->schoolId,
  1965. 'examGroupId'=>$exam_data->exam_group_id,
  1966. 'generateTime'=>time()*1000
  1967. );
  1968. sendDataToKafka("xbkc-academic-offline-generate-report",$kafkaData);
  1969. $this->sendNoticeToReport($exam_data->exam_group_id);
  1970. sendDataToKafka("zsy-marking-update-topic",$exam_data->exam_group_id,false);
  1971. $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id));
  1972. if($exam_group_data->homework==1){
  1973. //发送学生端消息
  1974. $sendJsonArr=array(
  1975. 'school_id'=>$this->schoolId,
  1976. 'send_type'=>'zsyas',
  1977. 'update_type'=>0,
  1978. 'exam_group_id'=>$exam_group_data->exam_group_id,
  1979. );
  1980. sendStudentCacheQueue($sendJsonArr);
  1981. }
  1982. if(Yii::app()->params['handle_log_on_off'])
  1983. {
  1984. Curl::post(Yii::app()->params['handle_log_api'], array(
  1985. "exam_group_id" => 0,
  1986. "operate_project" => 'zsyas2',
  1987. "school_id" => $this->schoolId,
  1988. "title" => '修改分数',
  1989. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  1990. "operate_method" => $this->action,
  1991. "operate_url" => $this->getRoute(),
  1992. "operate_sql" =>'',
  1993. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  1994. ));
  1995. }
  1996. echo json_encode(array('status'=>1,'msg'=>'修改成功'));exit;
  1997. }
  1998. }
  1999. }
  2000. }
  2001. }
  2002. //修改试题答案
  2003. private function UpdateTopicAnswer($topicId,$answer,$type){
  2004. if(!in_array($type,array(1,2,3,4,12))) return false;
  2005. if(!preg_match('/^[A-Z,]+$/u',$answer)){
  2006. return false;
  2007. }
  2008. $answers=explode(',',$answer);
  2009. if(!$answers){
  2010. return false;
  2011. }
  2012. $answer_type=array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T');
  2013. foreach ($answers as $a){
  2014. $a=strtoupper($a);
  2015. $sort_order[] = array_search($a,$answer_type);
  2016. }
  2017. $topic_data = STopic::model()->find('topic_id=:topic_id ',array(':topic_id'=>$topicId));
  2018. if(!$topic_data)
  2019. {
  2020. return -1; //不是校本题库的题
  2021. }
  2022. $topic_option_data = STopicItemOption::model()->findAll(array('order'=>'sort_order asc','condition'=>'topic_id=:topic_id','params'=>array(':topic_id'=>$topicId)));
  2023. if($topic_option_data)
  2024. {
  2025. //判断答案范围
  2026. $sortOrderArr=array();
  2027. foreach ($sort_order as $st){
  2028. if(($st+1)>count($topic_option_data)){
  2029. return false;
  2030. }
  2031. if($st!==false){
  2032. $sortOrderArr[]=$st;
  2033. }
  2034. }
  2035. if(!$sortOrderArr){
  2036. return false;
  2037. }
  2038. //异常情况,试题没有答案情况判断
  2039. $NoAnswer=true;
  2040. foreach ($topic_option_data as $datum){
  2041. if($datum->option_correct==1){
  2042. $NoAnswer=false;
  2043. break;
  2044. }
  2045. }
  2046. $flags = 1;
  2047. if(!$NoAnswer){
  2048. $flags = STopicItemOption::model()->updateAll(array('option_correct'=>0),'topic_id=:topic_id',array(':topic_id'=>$topicId));
  2049. }
  2050. if($flags && $sortOrderArr){
  2051. $flags = 0;
  2052. $flags = STopicItemOption::model()->updateAll(array('option_correct'=>1),'topic_id=:topic_id and sort_order in ('.implode(',',$sortOrderArr).')',array(':topic_id'=>$topicId));
  2053. $topic_item_option = STopicItemOption::model()->findAll('topic_id=:topic_id',array(':topic_id'=>$topicId));
  2054. if($topic_item_option)
  2055. {
  2056. //清缓存
  2057. Yii::app()->school_topic_cache->hmset('content:school_topic:'.$topicId,array('id' => 0));
  2058. if($topic_data->stem_id){
  2059. Yii::app()->school_topic_cache->hmset('content:school_topic:'.$topic_data->stem_id,array('id' => 0));
  2060. }
  2061. }
  2062. if($flags){
  2063. return true;
  2064. }
  2065. }
  2066. }
  2067. return false;
  2068. }
  2069. }