AllSubjectController.php 105 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377
  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. }