1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377 |
- <?php
- class AllSubjectController extends Controller{
- public $topicTypeRelation=array(
- 'ke'=>array(1,2,3,4,12),
- 'zhu'=>array(5,6,7,8,9,10,11),
- 'jie'=>array(8,9,10,11),
- 'tian'=>array(5,6,7),
- 'single'=>array(1,2),
- 'multiple'=>array(3,4),
- 'pan'=>array(12)
- );
- public $oldTopicType=array(
- 1=>'单选题',
- 2=>"多选题",
- 3=>'判断题',
- 5=>'填空题',
- 7=>'解答题',
- 17=>'选做题'
- );
- // 打印列表
- public function actionIndex()
- {
- $examId = Req::get('eid');
- $examData= Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$examId));
- if(!$examData) Yii::app()->jump->error('考试id不正确!');
- $examGroup=ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examData->exam_group_id));
- if(!$examGroup->qxk_paper_id){
- $this->redirect('paper/index?eid='.$examId);
- }
- $tplData=json_decode($examData->tpl_data,true);
- $alias=array();
- $stemAlias=array();
- $newRules=array();
- $selectTopicGroup=array();
- if(isset($tplData['new_items'])){
- foreach ($tplData['new_items'] as $item){
- if(isset($item['fullAlias'])){
- $alias[$item['id']]=$item['fullAlias'];
- }else{
- $alias[$item['id']]=$item['alias'];
- if($item['stemId']==$item['topicId']){
- $stemAlias[$item['id']]=$item['alias'];
- }else{
- $stemAlias[$item['id']]=$item['stemAlias'].$item['alias'];
- }
- }
- if(isset($item['sameAliasNo']) && $item['sameAliasNo']){
- $selectTopicGroup[$item['id']]=$item['sameAliasNo'];
- }
- if(isset($item['basicTopicType']) && isset($item['topicId'])){
- $thirdBasicId[(string)$item['topicId']]=$item['basicTopicType'];
- if(isset($item['stemId']) && $item['topicId']!=$item['stemId']){
- $thirdBasicId[(string)$item['stemId']]=$item['basicTopicType'];
- }
- }
- }
- }
- //读取新规则
- if(isset($tplData['new_rules'])){
- $data['new_rules'] = $tplData['new_rules'];
- }
- //读取单选题更新答案记录
- if(isset($tplData['update_answer'])){
- $data['update_answer'] = $tplData['update_answer'];
- }
- //读取送分题/0分题
- if(isset($tplData['send_points'])){
- $data['send_points'] = $tplData['send_points'];
- }
- $paper=SPaper::model()->find('exam_id=:exam_id',array(':exam_id'=>$examId));
- $topic_data = SPaperTopicRelation::model()->findAll(array('order'=>'`type` asc ,`order` asc','condition'=>'paper_id=:paper_id','params'=>array(':paper_id'=>$paper->paper_id)));
- if(!$topic_data){
- Yii::app()->jump->error('请先创建答题卡!');
- }
- $topicIds=array();
- foreach ($topic_data as $item){
- if($item['stem_id']){
- $topicIds[$item['stem_id']]=$item['stem_id'];
- $topicTypeCount[$item['type']][]=$item['stem_id'];
- }else{
- $topicIds[$item['topic_id']]=$item['topic_id'];
- $topicTypeCount[$item['type']][]=$item['topic_id'];
- }
- $topicTypeScoreCount[$item['type']][]=$item['score'];
- $topicNumber[(string)$item['topic_id']]=array(
- 'topic_id'=>$item['topic_id'],
- 'type'=>$item['type'],
- 'score'=>$item['score'],
- 'order'=>$item['order'],
- );
- }
- //$topicDetail=$this->schoolManager->getTopics($topicIds,false,$examData->subject_id);
- $topicDetail=$this->schoolManager->getQxkPaperTopics($topicIds);
- //组装试题结构
- $arr = array(0=>'A',1=>'B',2=>'C',3=>'D',4=>'E',5=>'F',6=>'G',7=>'H',8=>'I',9=>'J',10=>'K');
- $topicType=array();
- $topicGroup=array();
- foreach ($topicDetail as $item){
- if(!isset($topicType[$item['typeId']])){
- $topicType[$item['typeId']]=array(
- 'type_name'=>$item['typeName'],
- 'basic_type_id'=>$item['basicType'],
- 'tips'=>'',
- 'topic'=>array()
- );
- }
- $topic=array();
- $topic['id']=(string)number_format($item['topicId'],0,'','');
- $topic['type_id']=$item['typeId'];
- $topic['basic_type_id']=$item['basicType'];
- $topic['type_name']=$item['typeName'];
- $topic['subject_id']=$item['subjectId'];
- $topic['subject_name']=$item['subjectName'];
- $topic['title']=$item['title'];
- $topic['parse_content']=$item['parseContent'];
- $topic['slave_stem_editor']=$item['noShowSlaveTitle']?false:true; //小题题干独立编辑
- $topic['slave_option_editor']=$item['noShowSlaveOptions']?false:true; //小题选项独立编辑
- if(isset($topicNumber[(string)$topic['id']])){
- $topic['score']=$topicNumber[(string)$topic['id']]['score'];
- $topic['order']=$topicNumber[(string)$topic['id']]['order'];
- if(isset($alias[$topic['order']])){
- $topic['alias']=$alias[$topic['order']];
- }
- if(!isset($topicType[$item['typeId']]['order'])){
- if(isset($alias[$topic['order']]) && is_numeric($alias[$topic['order']])){
- $topicType[$item['typeId']]['order']=$alias[$topic['order']];
- }else{
- $topicType[$item['typeId']]['order']=$topicNumber[(string)$topic['id']]['order'];
- }
- }
- //判断选做题
- if(isset($selectTopicGroup[$topicNumber[(string)$topic['id']]['order']])){
- $topic['group_id']=$selectTopicGroup[$topicNumber[(string)$topic['id']]['order']];
- }
- }
- $topicGroup[$topic['id']]=array();
- if(!$item['slaveList']){
- $topic['answer']=$item['answer'];
- $topic['items']=$item['optionList'];
- if(!$topic['title'] && !$item['optionList']){
- $topic['is_show']=0;
- }else{
- $topic['is_show']=1;
- }
- $topic['answer_type_id']=$item['answerType'];
- if(count($item['answerDtl'])>1){
- $topic['is_checkbox']=1;
- }else{
- $topic['is_checkbox']=0;
- }
- $topicGroup[$topic['id']][]=$topic;
- }else{
- foreach ($item['slaveList'] as $val){
- $slave=array();
- $basicTopicArr[(string)$val['topicSlaveId']][]=$val;
- if(isset($topicNumber[(string)$val['topicSlaveId']])){
- $slave['score']=$topicNumber[(string)$val['topicSlaveId']]['score'];
- $slave['order']=$topicNumber[(string)$val['topicSlaveId']]['order'];
- if(!isset($topic['order'])){
- $topic['order']=$slave['order'];
- }
- if(isset($alias[$slave['order']])){
- $slave['alias']=$alias[$slave['order']];
- }
- if(!isset($topicType[$item['typeId']]['order'])){
- if(isset($alias[$slave['order']]) && is_numeric($alias[$slave['order']])){
- $topicType[$item['typeId']]['order']=$alias[$slave['order']];
- }else{
- $topicType[$item['typeId']]['order']=$topicNumber[(string)$val['topicSlaveId']]['order'];
- }
- }
- //判断选做题
- if(isset($selectTopicGroup[$topicNumber[(string)$val['topicSlaveId']]['order']])){
- $topic['group_id']=$selectTopicGroup[$topicNumber[(string)$val['topicSlaveId']]['order']];
- }
- }
- $slave['title']=$val['title'];
- $slave['parse_content']=$val['parseContent'];
- $slave['topic_slave_id']=$val['topicSlaveId'];
- if(isset($val['slaveList']) && $val['slaveList']){
- //三级子题
- foreach ($val['slaveList'] as $thirdSlave){
- $childSlave=array();
- $childSlave['title']=$thirdSlave['title'];
- $childSlave['topic_slave_id']=$thirdSlave['topicSlaveId'];
- $childSlave['parse_content']=$thirdSlave['parseContent'];
- if(isset($topicNumber[(string)$thirdSlave['topicSlaveId']])){
- $childSlave['score']=$topicNumber[(string)$thirdSlave['topicSlaveId']]['score'];
- $childSlave['order']=$topicNumber[(string)$thirdSlave['topicSlaveId']]['order'];
- //判断小题别名
- $topicType[$item['typeId']]['last_order']=$topicNumber[(string)$thirdSlave['topicSlaveId']]['order'];
- if(isset($alias[$childSlave['order']])){
- $childSlave['alias']=$alias[$childSlave['order']];
- }
- if(!isset($topicType[$item['typeId']]['order'])){
- if(isset($alias[$childSlave['order']]) && is_numeric($alias[$childSlave['order']])){
- $topicType[$item['typeId']]['order']=$alias[$childSlave['order']];
- }else{
- $topicType[$item['typeId']]['order']=$topicNumber[(string)$thirdSlave['topicSlaveId']]['order'];
- }
- }
- //判断选做题
- if(isset($selectTopicGroup[$topicNumber[(string)$thirdSlave['topicSlaveId']]['order']])){
- $topic['group_id']=$selectTopicGroup[$topicNumber[(string)$thirdSlave['topicSlaveId']]['order']];
- }
- }else{
- continue;
- }
- $childSlave['answer']=$thirdSlave['answer'];
- if(!$childSlave['title'] && !$thirdSlave['options']){
- $childSlave['is_show']=0;
- }else{
- $childSlave['is_show']=1;
- }
- if(isset($thirdSlave['listType'])){
- $childSlave['list_type']=$thirdSlave['listType'];
- }
- $childSlave['items']=$thirdSlave['options'];
- if(isset($thirdSlave['answerType'])){
- $childSlave['answer_type_id']=$thirdSlave['answerType'];
- }else{
- $childSlave['answer_type_id']=0;
- }
- if(count($thirdSlave['answerDtl'])>1){
- $childSlave['is_checkbox']=1;
- }else{
- $childSlave['is_checkbox']=0;
- }
- if(isset($thirdSlave['words'])){
- $childSlave['words']=$thirdSlave['words'];
- }
- $slave['slave'][]=$childSlave;
- $topicGroup[$topic['id']][]=$childSlave;
- }
- }else{
- $slave['answer']=$val['answer'];
- if(!$slave['title'] && !$val['options']){
- $slave['is_show']=0;
- }else{
- $slave['is_show']=1;
- }
- if(isset($val['listType'])){
- $slave['list_type']=$val['listType'];
- }
- $slave['items']=$val['options'];
- if(isset($val['answerType'])){
- $slave['answer_type_id']=$val['answerType'];
- }else{
- $slave['answer_type_id']=0;
- }
- if(count($val['answerDtl'])>1){
- $slave['is_checkbox']=1;
- }else{
- $slave['is_checkbox']=0;
- }
- if(isset($val['words'])){
- $slave['words']=$val['words'];
- }
- $topicGroup[$topic['id']][]=$slave;
- }
- $topic['slave'][]=$slave;
- }
- }
- $topicType[$item['typeId']]['topic'][]=$topic;
- }
- //拆分选做题
- if($selectTopicGroup){
- $selectTopicType=array();
- $selectTopicType['type_name']='选做题';
- $selectTopicType['topic']=array();
- foreach ($topicType as $key => $item){
- foreach ($item['topic'] as $vk => $val){
- if(isset($val['group_id'])){
- $selectTopicType['topic'][]=$val;
- $selectTopicType['basic_type_id']=$val['basic_type_id'];
- if(!isset($selectTopicType['order'])){
- $selectTopicType['order']=$val['order'];
- }
- unset($topicType[$key]['topic'][$vk]);
- }
- }
- if(count($topicType[$key]['topic'])==0){
- unset($topicType[$key]);
- }else{
- $topicType[$key]['topic']=array_values($topicType[$key]['topic']);
- $topicType[$key]['order']= $topicType[$key]['topic'][0]['order'];
- }
- }
- $topicType[17]=$selectTopicType;
- }
- //计算小题数量
- foreach ($topicType as $key => $item){
- $topicNumber=0;
- $scores=0;
- foreach ($item['topic'] as $val){
- if(isset($val['slave'])){
- foreach ($val['slave'] as $v){
- if(isset($v['slave'])){
- foreach ($v['slave'] as $value){
- if(isset($value['score'])){
- $scores+=$value['score'];
- }
- $topicNumber++;
- }
- }else{
- if(isset($v['score'])){
- $scores+=$v['score'];
- }
- $topicNumber++;
- }
- }
- }else{
- if($key==17){
- $scores=$val['score'];
- }else{
- $scores+=$val['score'];
- }
- $topicNumber++;
- }
- }
- $topicType[$key]['tips']='本大题共'.$topicNumber.'小题,共'.$scores.'分';
- $topicType[$key]['total_score']=$scores;
- $lastOrder = $this->_array_column($item['topic'],'order');
- array_multisort($lastOrder,SORT_ASC,$topicType[$key]['topic']);
- }
- //按组卷排序
- $lastOrder = $this->_array_column($topicType,'order');
- array_multisort($lastOrder,SORT_ASC,$topicType);
- //计算大题号
- foreach ($topicType as $key =>$value){
- $topicType[$key]['questionNumber']=numToUpper($key+1);
- }
- //题型对应
- $singleChoice=array(1,2,12); //单选,小题单选
- $multipleChoices=array(3,4); //多选,小题多选
- $slaveAnswer=array(7,9); //多选,小题多选
- $data['singleChoice']=$singleChoice;
- $data['multipleChoices']=$multipleChoices;
- $data['slaveAnswer']=$slaveAnswer;
- $data['topic']=$topicType;
- $data['subject']=$examData->subject_id;
- $data['paper_id']=$paper->paper_id;
- $data['is_third']=$examGroup->is_third;
- $data['topic_group']=$topicGroup;
- $data['exam_id']=$examId;
- $data['alias']=$alias;
- $this->renderPartial("all_subject",$data);
- }
- //试题操作页面
- public function actionOperate(){
- $examId = Req::get('eid');
- $examData= Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$examId));
- if(!$examData) Yii::app()->jump->error('考试id不正确!');
- $examGroup=ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$examData->exam_group_id));
- if(!$examGroup->qxk_paper_id){
- $this->redirect('paper/index?eid='.$examId);
- }
- $tplData=json_decode($examData->tpl_data,true);
- $alias=array();
- $stemAlias=array();
- $newRules=array();
- $thirdBasicId=array();
- $scoresType=array(); //小问小空类型
- if(isset($tplData['new_items'])){
- foreach ($tplData['new_items'] as $item){
- if(isset($item['fullAlias'])){
- $alias[$item['id']]=$item['fullAlias'];
- }else{
- $alias[$item['id']]=$item['alias'];
- if($item['stemId']==$item['topicId']){
- $stemAlias[$item['id']]=$item['alias'];
- }else{
- $stemAlias[$item['id']]=$item['stemAlias'].$item['alias'];
- }
- }
- if(isset($item['sameAliasNo']) && $item['sameAliasNo']){
- $selectTopicGroup[$item['id']]=$item['sameAliasNo'];
- }
- if(isset($item['basicTopicType']) && isset($item['topicId'])){
- $thirdBasicId[$item['topicId']]=$item['basicTopicType'];
- if(isset($item['stemId']) && $item['topicId']!=$item['stemId']){
- $thirdBasicId[$item['stemId']]=$item['basicTopicType'];
- }
- }
- if(isset($item['scoresType'])){
- $scoresType[$item['topicId']]=$item['scoresType'];
- }
- }
- }
- //读取新规则
- if(isset($tplData['new_rules'])){
- $paperData['new_rules'] = $tplData['new_rules'];
- }
- //读取单选题更新答案记录
- if(isset($tplData['update_answer'])){
- $paperData['update_answer'] = $tplData['update_answer'];
- }
- //读取送分题/0分题
- if(isset($tplData['send_points'])){
- $paperData['send_points'] = $tplData['send_points'];
- }
- $paper=SPaper::model()->find('exam_id=:exam_id',array(':exam_id'=>$examId));
- $topic_data = SPaperTopicRelation::model()->findAll(array('order'=>'`type` asc ,`order` asc','condition'=>'paper_id=:paper_id','params'=>array(':paper_id'=>$paper->paper_id)));
- if(!$topic_data){
- Yii::app()->jump->error('请先创建答题卡!');
- }
- $multipleBlank=array(); //多空题
- foreach ($topic_data as $item){
- $topicIds[$item['stem_id']]=$item['stem_id'];
- $topicTypeCount[$item['type']][]=$item['stem_id'];
- $topicTypeScoreCount[$item['type']][]=$item['score'];
- if($item['question_count']>1){
- $questionScore=explode(',',$item['question_score_str']);
- $multipleBlank[(string)$item['topic_id']]=$questionScore;
- }
- $topicNumber[(string)$item['topic_id']]=array(
- 'topic_id'=>$item['topic_id'],
- 'type'=>$item['type'],
- 'score'=>$item['score'],
- 'order'=>$item['order'],
- );
- }
- //$topicDetail=$this->schoolManager->getTopics($topicIds,false,$examData->subject_id);
- $topicDetail=$this->schoolManager->getQxkPaperTopics($topicIds);
- // debug($topicDetail);
- //组装试题结构
- $arr = array(0=>'A',1=>'B',2=>'C',3=>'D',4=>'E',5=>'F',6=>'G',7=>'H',8=>'I',9=>'J',10=>'K');
- $topicType=array();
- foreach ($topicDetail as $item){
- if(isset($item['slaveList']) && $item['slaveList']){
- foreach ($item['slaveList'] as $val){
- if(isset($val['slaveList']) && $val['slaveList']){
- foreach ($val['slaveList'] as $third){
- $topic=array();
- $topic['id']=(string)number_format($third['topicSlaveId'],0,'','');
- if(isset($topicNumber[(string)$topic['id']])){
- $topic['score']=$topicNumber[(string)$topic['id']]['score'];
- $topic['order']=$topicNumber[(string)$topic['id']]['order'];
- if(isset($alias[$topic['order']])){
- $topic['alias']=$alias[$topic['order']];
- }
- }
- $topic['answer']=$third['answer'];
- if(isset($paperData['new_rules'][$topic['order']])){
- $topic['rule_type']=$paperData['new_rules'][$topic['order']]['rule_type'];
- $topic['rule_answer']=$paperData['new_rules'][$topic['order']]['rule_answer'];
- $topic['rule_score']=$paperData['new_rules'][$topic['order']]['rule_score'];
- $topic['rule_score_half']=$paperData['new_rules'][$topic['order']]['rule_score_half'];
- }
- if(isset($tplData['update_answer'][$topic['order']])){
- $topic['update_answer']=$tplData['update_answer'][$topic['order']]['update_answer'];
- }
- if(isset($tplData['send_points'][$topic['order']])){
- $topic['send_points_type']=$tplData['send_points'][$topic['order']]['actionType'];
- }
- if(isset($third['answerType'])){
- $answerTypeId=$third['answerType'];
- }else{
- $answerTypeId=0;
- }
- if(count($third['answerDtl'])>1){
- $isCheckBox=1;
- }else{
- $isCheckBox=0;
- }
- $topicTypeId=$this->TransformTopicType($item['basicType'],$answerTypeId,$isCheckBox);
- if(isset($selectTopicGroup[$topicNumber[(string)$topic['id']]['order']]) && $selectTopicGroup[$topicNumber[(string)$topic['id']]['order']] ){
- $topicTypeId=17;
- }
- $topic['option_count']=count($third['options']);
- $topicType[$topicTypeId][]=$topic;
- }
- }else{
- //无三级小题
- $topic=array();
- $topic['id']=(string)number_format($val['topicSlaveId'],0,'','');
- if(isset($topicNumber[(string)$topic['id']])){
- $topic['score']=$topicNumber[(string)$topic['id']]['score'];
- $topic['order']=$topicNumber[(string)$topic['id']]['order'];
- if(isset($alias[$topic['order']])){
- $topic['alias']=$alias[$topic['order']];
- }
- }
- $topic['answer']=$val['answer'];
- if(isset($paperData['new_rules'][$topic['order']])){
- $topic['rule_type']=$paperData['new_rules'][$topic['order']]['rule_type'];
- $topic['rule_answer']=$paperData['new_rules'][$topic['order']]['rule_answer'];
- $topic['rule_score']=$paperData['new_rules'][$topic['order']]['rule_score'];
- $topic['rule_score_half']=$paperData['new_rules'][$topic['order']]['rule_score_half'];
- }
- if(isset($tplData['update_answer'][$topic['order']])){
- $topic['update_answer']=$tplData['update_answer'][$topic['order']]['update_answer'];
- }
- if(isset($tplData['send_points'][$topic['order']])){
- $topic['send_points_type']=$tplData['send_points'][$topic['order']]['actionType'];
- }
- if(isset($val['answerType'])){
- $answerTypeId=$val['answerType'];
- }else{
- $answerTypeId=0;
- }
- if(count($val['answerDtl'])>1){
- $isCheckBox=1;
- }else{
- $isCheckBox=0;
- }
- $topic['option_count']=count($val['options']);
- $topicTypeId=$this->TransformTopicType($item['basicType'],$answerTypeId,$isCheckBox);
- if(isset($selectTopicGroup[$topicNumber[(string)$topic['id']]['order']]) && $selectTopicGroup[$topicNumber[(string)$topic['id']]['order']] ){
- $topicTypeId=17;
- }
- $topicType[$topicTypeId][]=$topic;
- }
- }
- }else{
- $topic=array();
- $topic['id']=(string)number_format($item['topicId'],0,'','');
- //无小题
- if(isset($topicNumber[(string)$topic['id']])){
- $topic['score']=$topicNumber[(string)$topic['id']]['score'];
- $topic['order']=$topicNumber[(string)$topic['id']]['order'];
- if(isset($alias[$topic['order']])){
- $topic['alias']=$alias[$topic['order']];
- }
- }
- $topic['answer']=$item['answer'];
- if(isset($paperData['new_rules'][$topic['order']])){
- $topic['rule_type']=$paperData['new_rules'][$topic['order']]['rule_type'];
- $topic['rule_answer']=$paperData['new_rules'][$topic['order']]['rule_answer'];
- $topic['rule_score']=$paperData['new_rules'][$topic['order']]['rule_score'];
- $topic['rule_score_half']=$paperData['new_rules'][$topic['order']]['rule_score_half'];
- }
- if(isset($tplData['update_answer'][$topic['order']])){
- $topic['update_answer']=$tplData['update_answer'][$topic['order']]['update_answer'];
- }
- if(isset($tplData['send_points'][$topic['order']])){
- $topic['send_points_type']=$tplData['send_points'][$topic['order']]['actionType'];
- }
- if(isset($item['answerType'])){
- $answerTypeId=$item['answerType'];
- }else{
- $answerTypeId=0;
- }
- if(count($item['answerDtl'])>1){
- $isCheckBox=1;
- }else{
- $isCheckBox=0;
- }
- $topicTypeId=$this->TransformTopicType($item['basicType'],$answerTypeId,$isCheckBox);
- if(isset($selectTopicGroup[$topicNumber[(string)$topic['id']]['order']]) && $selectTopicGroup[$topicNumber[(string)$topic['id']]['order']] ){
- $topicTypeId=17;
- }
- $topic['option_count']=count($item['optionList']);
- $topicType[$topicTypeId][]=$topic;
- }
- }
- foreach ($topicType as $key =>$val){
- $lastOrder = $this->_array_column($val,'order');
- array_multisort($lastOrder,SORT_ASC,$topicType[$key]);
- }
- $menu=array();
- foreach ($topicType as $k =>$v){
- $menu[$k]=$this->oldTopicType[$k];
- }
- $data['exam_id']=$examId;
- $data['paper_id']=$paper['paper_id'];
- $data['topic']=$topicType;
- $data['menu']=$menu;
- $data['exam_name']=$examData->name;
- $data['subject_id']=$examData->subject_id;
- $data['multiple_blank']=$multipleBlank;
- $data['scores_type']=$scoresType;
- $this->renderPartial("operate",$data);
- }
- //批量更新分数
- public function actionUpdateScoreBatch(){
- $scores = Req::post('scores');
- $paper_id = Req::post('paper_id');
- $multiple_score = Req::post('multiple_score');
- $topicType=0;
- $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)));
- $oldTopicScores=0; //原总分
- $newTopicScores=array(); //修改后总分
- $update_score=array(); //需要修改分数的topic
- $update_score_order=array(); //修改分数的序号
- $choiseTYpeArr=array(1,2,3,4,12);
- $isChoice=true; //修改的题型是选择?
- if($paper_topic_data)
- {
- foreach($paper_topic_data as $v)
- {
- $oldTopicScores+=$v['score'];
- if(isset($scores[$v['order']])){
- if($v['score']!=$scores[$v['order']] || isset($multiple_score[$v['topic_id']])){
- $update_score[$v->topic_id] = $scores[$v->order];
- $update_score_order[$v->order] = $scores[$v->order];
- $score_diff[$v->topic_id]=intval($scores[$v->order]-$v['score']);
- $topicType=$v['type'];
- if(!in_array($topicType,$choiseTYpeArr)){
- $isChoice=false;
- }
- }
- $newTopicScores[]=$scores[$v['order']];
- }else{
- $newTopicScores[]=$v['score'];
- }
- }
- }
- if(!$update_score){
- echo json_encode(array('status'=>0,'msg'=>'分数与原试题分数一致'));exit;
- }
- $paper_data = SPaper::model()->find('paper_id=:paper_id',array(':paper_id'=>$paper_id));
- $exam_ids = array();
- $paper_ids = array();
- if($paper_data)
- {
- $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$paper_data->exam_id));
- if($exam_data)
- {
- $tpl_data = json_decode($exam_data->tpl_data,true);
- if(isset($tpl_data['items'])){
- $objectiveTplData=array(
- 'total'=>count($scores),
- 'totalScore'=>array_sum($newTopicScores),
- 'perScores'=>array_values($newTopicScores)
- );
- $tpl_data['items'][$topicType]=$objectiveTplData;
- }
- $paper_score=$tpl_data['scores']=$tpl_data['total_score']=$tpl_data['scores']-$oldTopicScores+array_sum($newTopicScores);
- //修改new_items
- if(isset($tpl_data['new_items'])){
- foreach ($tpl_data['new_items'] as $key =>$val){
- if(isset($update_score_order[$val['id']])){
- $tpl_data['new_items'][$key]['score']=$update_score_order[$val['id']];
- }
- }
- }
- $json_tpl_data = jsonEncode($tpl_data);
- $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id));
- if($exam_group_data)
- {
- foreach($exam_group_data as $v)
- {
- $exam_ids[$v->exam_id] = $v->exam_id;
- }
- if($exam_ids)
- {
- $criteria = new CDbCriteria();
- $criteria->addInCondition('exam_id',$exam_ids);
- $paper_data = SPaper::model()->findAll($criteria);
- if($paper_data)
- {
- foreach($paper_data as $v)
- {
- $paper_ids[$v->paper_id] = $v->paper_id;
- }
- $trans = $this->sConn->beginTransaction();
- try{
- foreach ($update_score as $topic_id => $score){
- if(isset($multiple_score[$topic_id])){
- $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;
- }else{
- $sql='update `paper_topic_relation` set `score` = '.$score.' where paper_id in ('.implode(',',$paper_ids).') and `topic_id` ='.$topic_id;
- }
- $this->sConn->createCommand($sql)->execute();
- if($isChoice){
- //修改学生得分
- $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 ";
- $students=$this->sConn->createCommand($updateStudentSql)->queryAll();
- if($students){
- $studentIds=array();
- foreach ($students as $v){
- $studentIds[]=$v['student_id'];
- }
- $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 ";
- $this->sConn->createCommand($sql)->execute();
- $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).") ";
- $this->sConn->createCommand($sql)->execute();
- }
- }
- }
- $sql='update `paper` set `score` = '.($paper_score).' where paper_id in ('.implode(',',$paper_ids).')';
- $this->sConn->createCommand($sql)->execute();
- $sql="update `exam` set `tpl_data` = '".($json_tpl_data)."' where exam_id in (".implode(',',$exam_ids).")";
- $this->sConn->createCommand($sql)->execute();
- $trans->commit();
- }
- catch(Exception $e){
- $trans->rollBack();
- echo json_encode(array('status'=>0));exit;
- }
- $sendParam=array(
- 'school_id'=>$this->schoolId,
- 'exam_group_id'=>$exam_data->exam_group_id
- );
- sendZsystNotic($sendParam);
- $kafkaData=array(
- 'schoolId'=>$this->schoolId,
- 'examGroupId'=>$exam_data->exam_group_id,
- 'generateTime'=>time()*1000
- );
- sendDataToKafka("xbkc-academic-generate-report",$kafkaData);
- $this->sendNoticeToReport($exam_data->exam_group_id);
- sendDataToKafka("zsy-marking-update-topic",$exam_data->exam_group_id,false);
- $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id));
- if($exam_group_data->homework==1){
- //发送学生端消息
- $sendJsonArr=array(
- 'school_id'=>$this->schoolId,
- 'send_type'=>'zsyas',
- 'update_type'=>0,
- 'exam_group_id'=>$exam_group_data->exam_group_id,
- );
- sendStudentCacheQueue($sendJsonArr);
- }
- if(Yii::app()->params['handle_log_on_off'])
- {
- Curl::post(Yii::app()->params['handle_log_api'], array(
- "exam_group_id" => 0,
- "operate_project" => 'zsyas2',
- "school_id" => $this->schoolId,
- "title" => '修改分数',
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $this->getRoute(),
- "operate_sql" =>'',
- "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
- ));
- }
- echo json_encode(array('status'=>1,'msg'=>'修改成功'));exit;
- }
- }
- }
- }
- }
- }
- /*批量修改多选题规则*/
- public function actionChangeMultiRuleBatch(){
- ini_set('memory_limit', '500M');
- $exam_id = Req::post('exam_id');
- $topic_id = Req::post('topic_id');
- $type = Req::post('type');
- $rule = Req::post('rule');
- $score_m = Req::post('score_m');
- $score_half_m = Req::post('score_half_m');
- $answer = Req::post('answer');
- $result=array(
- 'status'=>0
- );
- if(!$exam_id || !$topic_id || !$type || !$rule) {
- exit(json_encode($result));
- }
- // if(!$score_m){
- // $result['msg']='分数不能为空';
- // exit(json_encode($result));
- // };
- if(!$score_half_m && $rule!=1){
- $result['msg']='半对分数不能为空';
- exit(json_encode($result));
- };
- // if($score_half_m>$score_m){
- // $result['msg']='半对分数不能大于满分';
- // exit(json_encode($result));
- // };
- if(!in_array($rule,array(1,2,3,4,5))){
- $result['msg']='评分规则错误';
- exit(json_encode($result));
- }
- $topicIdArr=explode('///',$topic_id);
- $topicAnswerArr=explode('///',$answer);
- $topicHalfScoreArr=explode('///',$score_half_m);
- if(!$topicIdArr || !$topicAnswerArr){
- $result['msg']='批量读取试题异常';
- exit(json_encode($result));
- }
- $topicIdAnswer=array();
- $topicIdHalfScore=array();
- $topicHalfScoreRelation=array();
- foreach ($topicIdArr as $key => $val){
- if(!isset($topicAnswerArr[$key])){
- $result['msg']='批量读取试题答案异常';
- exit(json_encode($result));
- }else{
- $topicIdAnswer[$val]=$topicAnswerArr[$key];
- $topicIdHalfScore[$val]=$topicHalfScoreArr[$key];
- }
- }
- $ExamModel=new SExam();
- $ExamInfo=$ExamModel->getDetailByExamId($exam_id);
- if(!$ExamInfo){
- $result['msg']='考试ID错误1';
- exit(json_encode($result));
- }
- $Exam_GroupId=$ExamInfo['exam_group_id'];
- $AllExam=Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$Exam_GroupId));
- $AllExamIds=array();
- $tplData=array();
- if($AllExam){
- foreach($AllExam as $val){
- if($val){
- $AllExamIds[]=$val['exam_id'];
- if(!$tplData){
- $tplData=json_decode($val['tpl_data'],true);
- }
- }
- }
- }
- if(!$AllExamIds){
- $result['msg']='考试ID错误2';
- exit(json_encode($result));
- }
- $AllPaperIds=array();
- $paperScore=array();
- $AllPaper=SPaper::model()->findAll('exam_id in('.implode(',',$AllExamIds).')');
- if($AllPaper){
- foreach ($AllPaper as $val){
- $AllPaperIds[]=$val['paper_id'];
- $paperScore[$val['paper_id']]=$val['score'];
- }
- }
- if(!$AllPaperIds){
- $result['msg']='考试ID错误3';
- exit(json_encode($result));
- }
- $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();
- if(!$paperTopicRelation){
- $result['msg']='试卷试题有误';
- exit(json_encode($result));
- }
- $Rs=array();
- $topicScoreArr=array();
- $topicHalfScoreArr=array();
- foreach ($paperTopicRelation as $value){
- if($topicIdHalfScore[(string)$value['topic_id']]>$value['score']){
- $result['msg']='半对分数不能大于满分';
- exit(json_encode($result));
- }
- $topicScoreArr[$value['topic_id']]=$value['score'];
- }
- foreach ($AllPaperIds as $pid){
- $tempData=SStudentPaperTopicRs::model()->findAll("paper_id ='".$pid."' and topic_id in(".implode(',',$topicIdArr).")");
- if($tempData){
- foreach ($tempData as $v){
- $Rs[]=array(
- 'topic_id' =>$v['topic_id'],
- 'answer' =>$v['answer'],
- 'paper_id' =>$v['paper_id'],
- 'student_id' =>$v['student_id'],
- );
- }
- }
- }
- $updateRightData=array();
- $updateScoreData=array();
- $updateStudentPaperRelation=array();
- if($Rs){
- if(!$answer){
- $result['msg']='答案不能为空';
- exit(json_encode($result));
- }
- foreach ($Rs as $k=> $v){
- if(!isset($topicIdAnswer[$v['topic_id']])){
- continue;
- }
- $answer=$topicIdAnswer[$v['topic_id']];
- if(!$v['answer']){
- $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
- $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
- }else{
- if($v['answer'] == $answer){
- $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=1;
- $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=$topicScoreArr[$v['topic_id']];
- }else{
- switch ($rule){
- case 1: //规则A 最严格规则
- $update_data['scoring']=0;
- $update_data['is_right']=0;
- $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
- $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
- break;
- case 2://规则B 半对规则
- //查找错误选择
- $answerArr=explode(',',$answer);
- $tempAnswer = explode(',', $v['answer']);
- $FindWrong=false;
- foreach ($tempAnswer as $av) {
- if(!in_array($av,$answerArr)){
- $FindWrong=true;
- break;
- }
- }
- if($FindWrong){
- $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
- $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
- }else{
- $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;//半对算错
- $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=$topicIdHalfScore[$v['topic_id']];
- }
- break;
- case 3://规则C 宽松半对规则
- //查找正确选择
- $answerArr=explode(',',$answer);
- $tempAnswer = explode(',', $v['answer']);
- $IsWrong=true;
- if(count($tempAnswer)<=count($answerArr)){
- foreach ($tempAnswer as $av) {
- if (false !== strpos($answer, $av)) {
- $IsWrong=false;
- break;
- }
- }
- }
- //错误答案情况
- if($IsWrong){
- $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
- $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
- }else{
- $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;//半对算错
- $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=$topicIdHalfScore[$v['topic_id']];
- }
- break;
- case 4:
- $answerArr=explode(',',$answer);
- $tempAnswer = explode(',', $v['answer']);
- $IsWrong=true;
- if(count($tempAnswer)<=count($answerArr)){
- foreach ($tempAnswer as $av) {
- if (false !== strpos($answer, $av)) {
- $IsWrong=false;
- break;
- }
- }
- }
- //错误答案情况
- if($IsWrong){
- $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
- $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
- }else{
- //没有错误答案,且不全对,几个答案几分
- $score_half_m=count($tempAnswer);
- $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
- $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=$score_half_m;
- }
- break;
- case 5:
- $answerArr=explode(',',$answer);
- $tempAnswer = explode(',', $v['answer']);
- $rightAnswerCount=0;
- if(count($tempAnswer)<=count($answerArr)){
- foreach ($tempAnswer as $av) {
- if (false !== strpos($answer, $av)) {
- $rightAnswerCount++;
- }
- }
- }
- $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
- $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=$rightAnswerCount;
- break;
- }
- }
- }
- //更新总分queryAll
- $updateStudentPaperRelation[$v['student_id']]=$v['paper_id'];
- }
- }
- $updateStudentPaperRelationSql=array();
- if($updateRightData){
- $sqlIsRight=array();
- $sqlScore=array();
- foreach ($updateRightData as $paperId=>$val){
- foreach ($val as $topicId=>$v){
- $sql=" update `student_paper_topic_rs` set `is_right`= case `student_id` ";
- foreach ($v as $studentId=>$isRight){
- $sql.=" WHEN ".$studentId." THEN '".$isRight."' ";
- }
- $sql.=" Else `is_right`";
- $sql.=" End ";
- $sql.=" where paper_id='{$paperId}' and topic_id='{$topicId}'";
- $sqlIsRight[]=$sql;
- }
- }
- foreach ($updateScoreData as $paperId=>$val){
- foreach ($val as $topicId=>$v){
- $sql=" update `student_paper_topic_rs` set `scoring`= case `student_id` ";
- foreach ($v as $studentId=>$score){
- $sql.=" WHEN ".$studentId." THEN '".$score."' ";
- }
- $sql.=" Else `scoring`";
- $sql.=" End ";
- $sql.=" where paper_id='{$paperId}' and topic_id='{$topicId}'";
- $sqlScore[]=$sql;
- }
- }
- $transaction = $this->sConn->beginTransaction();
- try {
- if($sqlIsRight){
- foreach ($sqlIsRight as $sql){
- $this->sConn->createCommand($sql)->execute();
- }
- }
- if($sqlScore){
- foreach ($sqlScore as $sql){
- $this->sConn->createCommand($sql)->execute();
- }
- }
- $transaction->commit();
- } catch (Exception $e) {
- //如果操作失败, 数据回滚
- $transaction->rollback();
- $result['status']=0;
- $result['msg']=' 报告更新失败';
- exit(json_encode($result));
- }
- if($updateStudentPaperRelation){
- foreach ($updateStudentPaperRelation as $studentId =>$paperId){
- $TotalScore = $paperScore[$paperId];
- $StudentAllTopicSql="select `is_right`,`scoring` from `student_paper_topic_rs` where `paper_id`='".$paperId."' and student_id='".$studentId."' ";
- $StudentAllTopic=$this->sConn->createCommand($StudentAllTopicSql)->queryAll();
- $right_count = 0;
- $partial_right_count = 0;
- $wrong_count = 0;
- $scoring = 0;
- $lost_score = 0;
- foreach ($StudentAllTopic as $value) {
- if ($value['is_right'] == 1) {
- $right_count++;
- } elseif ($value['is_right'] == 2) {
- $partial_right_count++;
- } else {
- $wrong_count++;
- }
- $scoring = bcadd($scoring, $value['scoring'], 1);
- }
- unset($StudentAllTopic);
- $lost_score = bcsub($TotalScore, $scoring, 1);
- $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."'";
- $paperRelattionSql.=" where `paper_id`='".$paperId."' and `student_id`='".$studentId."'";
- $updateStudentPaperRelationSql[]=$paperRelattionSql;
- }
- }
- $transaction = $this->sConn->beginTransaction();
- try {
- if($updateStudentPaperRelationSql){
- foreach ($updateStudentPaperRelationSql as $sql){
- $this->sConn->createCommand($sql)->execute();
- }
- }
- $sendParam=array(
- 'school_id'=>$this->schoolId,
- 'exam_group_id'=>$Exam_GroupId
- );
- $transaction->commit();
- sendZsystNotic($sendParam);
- $kafkaData=array(
- 'schoolId'=>$this->schoolId,
- 'examGroupId'=>$Exam_GroupId,
- 'generateTime'=>time()*1000
- );
- sendDataToKafka("xbkc-academic-offline-generate-report",$kafkaData);
- } catch (Exception $e) {
- //如果操作失败, 数据回滚
- $transaction->rollback();
- $result['status']=0;
- $result['msg']=' 报告更新失败';
- exit(json_encode($result));
- }
- }
- //记录新判分规则
- $tplRules=array();
- if(isset($tplData['new_rules'])){
- $tplRules=$tplData['new_rules'];
- }
- foreach ($paperTopicRelation as $value){
- if(in_array($value['topic_id'],$topicIdArr)){
- if(isset($tplRules[$value['order']])){
- $tplRules[$value['order']]['rule_type']=(int)$rule;
- }else{
- $rule_answer=isset($topicIdAnswer[$value['topic_id']])?$topicIdAnswer[$value['topic_id']]:'';
- $rule_half_score=isset($topicIdHalfScore[$value['topic_id']])?$topicIdHalfScore[$value['topic_id']]:'0';
- $tplRules[$value['order']]=array(
- 'topicNo'=>$value['order'],
- 'topic_id'=>$value['topic_id'],
- 'rule_type'=>(int)$rule,
- 'rule_answer'=>$rule_answer,
- 'rule_score'=>'',
- 'rule_score_half'=>$rule_half_score
- );
- }
- }
- }
- if($tplRules){
- $tplData['new_rules']=$tplRules;
- $this->sConn->createCommand("update exam set tpl_data='".jsonEncode($tplData)."' where exam_group_id = '{$Exam_GroupId}'")->execute();
- }
- $this->sendNoticeToReport($Exam_GroupId);
- if(Yii::app()->params['handle_log_on_off'])
- {
- Curl::post(Yii::app()->params['handle_log_api'], array(
- "exam_group_id" => 0,
- "operate_project" => 'zsyas2',
- "school_id" => $this->schoolId,
- "title" => '批量更新多选题报告',
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $this->getRoute(),
- "operate_sql" =>'',
- "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
- ));
- }
- $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$Exam_GroupId));
- if(isset($exam_group_data) && $exam_group_data->homework==1){
- //发送学生端消息
- $sendJsonArr=array(
- 'school_id'=>$this->schoolId,
- 'send_type'=>'zsyas',
- 'update_type'=>0,
- 'exam_group_id'=>$Exam_GroupId,
- );
- sendStudentCacheQueue($sendJsonArr);
- }
- $result['status']=1;
- $result['msg']='报告更新完成';
- exit(json_encode($result));
- }
- function _array_column(array $array, $column_key, $index_key=null){
- $result = array();
- foreach($array as $arr) {
- if(!is_array($arr)) continue;
- if(is_null($column_key)){
- $value = $arr;
- }else{
- $value = $arr[$column_key];
- }
- if(!is_numeric($value)){
- $value=intval($value);
- }
- if(!is_null($index_key)){
- $key = $arr[$index_key];
- $result[$key] = $value;
- }else{
- $result[] = $value;
- }
- }
- return $result;
- }
- //更新报告后发送通知
- private function sendNoticeToReport($examGroupId){
- $url = Yii::app()->params['zsy_api_url'].'/qxk/academic/hm/report/external/exam/group/clear-cache/'.$examGroupId;
- $username = $this->schoolInfo->school_id;
- $password = md5($this->schoolId.Yii::app()->params['zsy_api_key']);
- $curl = @curl_init();
- $response=null;
- if ($curl) {
- curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
- curl_setopt($curl, CURLOPT_USERPWD, $username .':'. $password);
- curl_setopt($curl, CURLOPT_HEADER, 0);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
- curl_setopt($curl, CURLOPT_TIMEOUT, 10);
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
- curl_setopt($curl, CURLOPT_HTTPHEADER, array(
- 'Content-Type: application/json',
- ));
- $response = curl_exec($curl);
- curl_close($curl);
- }
- return $response;
- }
- public function TransformTopicType($basicId,$answerTypeId,$checkBox){
- $topicTypeId=0;
- if(in_array($basicId,$this->topicTypeRelation['single'])){
- $topicTypeId=1;
- }elseif(in_array($basicId,$this->topicTypeRelation['multiple'])){
- $topicTypeId=2;
- }elseif(in_array($basicId,$this->topicTypeRelation['tian'])){
- $topicTypeId=5;
- }elseif(in_array($basicId,$this->topicTypeRelation['jie'])){
- $topicTypeId=7;
- }elseif(in_array($basicId,$this->topicTypeRelation['pan'])){
- $topicTypeId=3;
- }elseif ($basicId==13){
- if($answerTypeId==1){
- if($checkBox==1){
- $topicTypeId=2;
- }else{
- $topicTypeId=1;
- }
- }elseif($answerTypeId==2){
- $topicTypeId=5;
- }elseif($answerTypeId==3){
- $topicTypeId=7;
- }elseif($answerTypeId==4){
- $topicTypeId=3;
- }else{
- $topicTypeId=7;
- }
- }
- return $topicTypeId;
- }
- //批量更新分数答案
- public function actionUpdateScoreAnswerBatch(){
- $changes = Req::post('change_data');
- $paper_id = Req::post('paper_id');
- // $changes=array(
- // [
- // 'answer'=>'A',
- // 'score'=>'',
- // 'topic_id'=>'201511100026379'
- // ]
- // );
- if(!$changes){
- echo json_encode(array('status'=>0,'msg'=>'参数异常'));exit;
- }
- $changeTopicData=array();
- $topicIds=array();
- foreach ($changes as $change){
- $topicIds[]=$change['topic_id'];
- $changeTopicData[(string)$change['topic_id']]=array();
- if($change['answer']){
- if($change['answer']=='√'){
- $change['answer']='T';
- }elseif($change['answer']=='×'){
- $change['answer']='F';
- }
- $changeTopicData[(string)$change['topic_id']]['answer']=$change['answer'];
- }else{
- $changeTopicData[(string)$change['topic_id']]['answer']='';
- }
- if($change['score']){
- $changeTopicData[(string)$change['topic_id']]['score']=$change['score'];
- }else{
- $changeTopicData[(string)$change['topic_id']]['score']='';
- }
- }
- $topicType=0;
- $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)));
- $oldTopicScores=0; //原总分
- $newTopicScores=array(); //修改后总分
- $update_score=array(); //需要修改分数的topic
- $update_score_order=array(); //修改分数的序号
- $oldTopicScore=array();
- $changeTopicOrder=array();
- $choiseTYpeArr=array(1,2,3,4,12);
- $isChoice=true; //修改的题型是选择?
- $updateAnswer=array();
- if($paper_topic_data)
- {
- foreach($paper_topic_data as $v)
- {
- if(isset($changeTopicData[(string)$v['topic_id']])){
- $changeTopicOrder[$v['order']]=$changeTopicData[(string)$v['topic_id']];
- if($changeTopicData[$v['topic_id']]['score']){
- $update_score[$v->topic_id] = $changeTopicData[(string)$v['topic_id']]['score'];
- $update_score_order[$v->order] = $changeTopicData[(string)$v['topic_id']]['score'];
- }else{
- $oldTopicScore[(string)$v['topic_id']]=$v['score'];
- }
- if($changeTopicData[(string)$v['topic_id']]['answer']){
- $updateAnswer[$v['order']]=array(
- 'order'=>$v['order'],
- 'topic_id'=>$v['topic_id'],
- 'update_answer'=>$changeTopicData[(string)$v['topic_id']]['answer']
- );
- }
- }else{
- $newTopicScores[]=$v['score'];
- }
- }
- }
- $paper_data = SPaper::model()->find('paper_id=:paper_id',array(':paper_id'=>$paper_id));
- $exam_ids = array();
- $paper_ids = array();
- if($paper_data)
- {
- $exam_data = Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$paper_data->exam_id));
- if($exam_data)
- {
- $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id));
- $tpl_data = json_decode($exam_data->tpl_data,true);
- $exam_all_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id));
- //修改new_items
- if(isset($tpl_data['new_items'])){
- foreach ($tpl_data['new_items'] as $key =>$val){
- if(isset($changeTopicOrder[$val['id']]) && $changeTopicOrder[$val['id']]['score']){
- $tpl_data['new_items'][$key]['score']=$changeTopicOrder[$val['id']]['score'];
- }
- }
- }
- //修改答案记录
- if($updateAnswer){
- foreach ($updateAnswer as $order=>$item){
- if(!isset($tpl_data['update_answer'])){
- $tpl_data['update_answer']=array();
- }
- $tpl_data['update_answer'][$order]=$item;
- if($exam_group_data['is_third']==1){
- $this->UpdateTopicAnswer($item['topic_id'],$item['update_answer'],1);
- }
- }
- }
- $paper_score=$this->sumTplDataScores($tpl_data,0);
- $tpl_data['scores']=$paper_score;
- $tpl_data['total_score']=$paper_score;
- $json_tpl_data = jsonEncode($tpl_data);
- if($exam_all_data)
- {
- foreach($exam_all_data as $v)
- {
- $exam_ids[$v->exam_id] = $v->exam_id;
- }
- if($exam_ids)
- {
- $criteria = new CDbCriteria();
- $criteria->addInCondition('exam_id',$exam_ids);
- $paper_data = SPaper::model()->findAll($criteria);
- if($paper_data)
- {
- foreach($paper_data as $v)
- {
- $paper_ids[$v->paper_id] = $v->paper_id;
- }
- $trans = $this->sConn->beginTransaction();
- try{
- foreach ($changeTopicData as $topic_id => $item){
- if(isset($item['score']) && $item['score']){
- $sql='update `paper_topic_relation` set `score` = '.$item['score'].' where paper_id in ('.implode(',',$paper_ids).') and `topic_id` ='.$topic_id;
- $this->sConn->createCommand($sql)->execute();
- }
- if(isset($item['answer']) && $item['answer']){
- //查询选旧答案,得分的学生
- $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 ";
- $students=$this->sConn->createCommand($updateStudentSql)->queryAll();
- if($students){
- $studentIds=array();
- $oldScore=0;
- foreach ($students as $v){
- $studentIds[]=$v['student_id'];
- if(!$oldScore){
- $oldScore=$v['scoring'];
- }
- }
- $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 ";
- $this->sConn->createCommand($sql)->execute();
- $sql="update student_paper_relation set scoring=scoring-".$oldScore." where paper_id in (".implode(',',$paper_ids).") and student_id in(".implode(',',$studentIds).") ";
- $this->sConn->createCommand($sql)->execute();
- }
- //查询选新答案的学生
- $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']."' ";
- $students=$this->sConn->createCommand($updateStudentSql)->queryAll();
- if($students){
- $studentIds=array();
- foreach ($students as $v){
- $studentIds[]=$v['student_id'];
- }
- $score=0;
- if(isset($item['score']) && $item['score']){
- $score=$item['score'];
- }else{
- $score=$oldTopicScore[$topic_id];
- }
- $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).")";
- $this->sConn->createCommand($sql)->execute();
- $sql="update student_paper_relation set scoring=scoring+".$score." where paper_id in (".implode(',',$paper_ids).") and student_id in(".implode(',',$studentIds).") ";
- $this->sConn->createCommand($sql)->execute();
- }
- }elseif(isset($item['score']) && $item['score']){
- //查询选旧答案,得分的学生
- $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 ";
- $students=$this->sConn->createCommand($updateStudentSql)->queryAll();
- if($students){
- $studentIds=array();
- $oldScore=0;
- foreach ($students as $v){
- $studentIds[]=$v['student_id'];
- if(!$oldScore){
- $oldScore=$v['scoring'];
- }
- }
- $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 ";
- $this->sConn->createCommand($sql)->execute();
- $sql="update student_paper_relation set scoring=scoring+".($item['score']-$oldScore)." where paper_id in (".implode(',',$paper_ids).") and student_id in(".implode(',',$studentIds).") ";
- $this->sConn->createCommand($sql)->execute();
- }
- }
- }
- $sql='update `paper` set `score` = '.($paper_score).' where paper_id in ('.implode(',',$paper_ids).')';
- $this->sConn->createCommand($sql)->execute();
- $sql="update `exam` set `tpl_data` = '".($json_tpl_data)."' where exam_id in (".implode(',',$exam_ids).")";
- $this->sConn->createCommand($sql)->execute();
- $trans->commit();
- }
- catch(Exception $e){
- $trans->rollBack();
- echo json_encode(array('status'=>0));exit;
- }
- //学生端接口
- $sendParam=array(
- 'school_id'=>$this->schoolId,
- 'exam_group_id'=>$exam_data->exam_group_id
- );
- sendZsystNotic($sendParam);
- $kafkaData=array(
- 'schoolId'=>$this->schoolId,
- 'examGroupId'=>$exam_data->exam_group_id,
- 'generateTime'=>time()*1000
- );
- sendDataToKafka("xbkc-academic-generate-report",$kafkaData);
- $this->sendNoticeToReport($exam_data->exam_group_id);
- sendDataToKafka("zsy-marking-update-topic",$exam_data->exam_group_id,false);
- if($exam_group_data->homework==1){
- //发送学生端消息
- $sendJsonArr=array(
- 'school_id'=>$this->schoolId,
- 'send_type'=>'zsyas',
- 'update_type'=>0,
- 'exam_group_id'=>$exam_group_data->exam_group_id,
- );
- sendStudentCacheQueue($sendJsonArr);
- }
- if(Yii::app()->params['handle_log_on_off'])
- {
- Curl::post(Yii::app()->params['handle_log_api'], array(
- "exam_group_id" => 0,
- "operate_project" => 'zsyas2',
- "school_id" => $this->schoolId,
- "title" => '修改分数',
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $this->getRoute(),
- "operate_sql" =>'',
- "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
- ));
- }
- echo json_encode(array('status'=>1,'msg'=>'修改成功'));exit;
- }
- }
- }
- }
- }
- }
- //处理tpl_data,计算部分
- private function sumTplDataScores($select_info,$is_third){
- $TotalScore = 0; //计算可能多分组情况总分
- $sameGroupTopic=array();
- $groupScoreArr=array();
- $required=1;
- $qxk=0;
- if(isset($select_info['required'])){
- $required=$select_info['required'];
- }elseif(isset($select_info['items'][17])){
- $required=$select_info['items'][17]['required'];
- }
- if ($select_info) {
- if ($select_info && isset($select_info['new_items']) && !empty($select_info['new_items'])) {
- $nowGroupId = 0; //分组标志
- foreach ($select_info['new_items'] as $k => $sc) {
- if(isset($sc['basicTopicType']) && $sc['basicTopicType'] && !$qxk){
- $qxk=1;
- }
- //分组判断
- if(($sc['topic_type']==17 || (isset($sc['sameAliasNo']) && $sc['sameAliasNo'])) && !$sc['group_id']){
- $sc['group_id']=1000;
- }
- if (!isset($sc['group_id']) || !$sc['group_id']) {
- $TotalScore += $sc['score'];
- } else{
- if(isset($sc['smTopicLen']) && $sc['smTopicLen'] && !$qxk){
- //在线多组,另计
- }else{
- $groupScoreArr[$sc['group_id']][]=$sc['score'];
- }
- }
- if(isset($sc['sameAliasNo']) && $sc['sameAliasNo'] && !$qxk){
- $sameGroupTopic[$sc['group_id']][$sc['sameAliasNo']][]=$sc['score'];
- }
- }
- if($sameGroupTopic){
- foreach ($sameGroupTopic as $gid =>$value){
- $value=array_values($value);
- $TotalScore+=array_sum($value[0]);
- }
- }
- if($groupScoreArr){
- if($is_third){
- //多组,多选一
- foreach ($groupScoreArr as $gid =>$item){
- $TotalScore+=$item[0];
- }
- }else{
- //一组,多选多
- $groupScoreArr=array_values($groupScoreArr);
- $TotalScore+=array_sum(array_slice($groupScoreArr[0],0,$required));
- }
- }
- }
- }
- return $TotalScore;
- }
- /*批量修改多选题规则*/
- public function actionChangeMultiRuleBatchNew(){
- ini_set('memory_limit', '500M');
- $exam_id = Req::post('exam_id');
- $topicData = Req::post('topic_data');
- $result=array(
- 'status'=>0
- );
- if(!$exam_id || !$topicData ) {
- exit(json_encode($result));
- }
- $topicIds=array();
- $topicIdArr=array();
- foreach ($topicData as $item){
- $topicIds[]=$item['topic_id'];
- // if($item['rule']!=1 && !$item['half_score']){
- // $result['msg']='半对分数不能为空';
- // exit(json_encode($result));
- // }
- if(!in_array($item['rule'],array(1,2,3,4,5))){
- $result['msg']='评分规则错误';
- exit(json_encode($result));
- }
- if($item['half_score']>$item['score']){
- $result['msg']='半对分数不能大于满分';
- exit(json_encode($result));
- }
- $topicIdArr[(string)$item['topic_id']]=$item;
- if($item['answer']){
- $this->UpdateTopicAnswer($item['topic_id'],$item['answer'],1);
- }
- }
- if(!$topicIdArr){
- $result['msg']='批量读取试题异常';
- exit(json_encode($result));
- }
- $ExamModel=new SExam();
- $ExamInfo=$ExamModel->getDetailByExamId($exam_id);
- if(!$ExamInfo){
- $result['msg']='考试ID错误1';
- exit(json_encode($result));
- }
- $Exam_GroupId=$ExamInfo['exam_group_id'];
- $AllExam=Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$Exam_GroupId));
- $AllExamIds=array();
- $tplData=array();
- if($AllExam){
- foreach($AllExam as $val){
- if($val){
- $AllExamIds[]=$val['exam_id'];
- if(!$tplData){
- $tplData=json_decode($val['tpl_data'],true);
- }
- }
- }
- }
- if(!$AllExamIds){
- $result['msg']='考试ID错误2';
- exit(json_encode($result));
- }
- $AllPaperIds=array();
- $paperScore=array();
- $AllPaper=SPaper::model()->findAll('exam_id in('.implode(',',$AllExamIds).')');
- if($AllPaper){
- foreach ($AllPaper as $val){
- $AllPaperIds[]=$val['paper_id'];
- $paperScore[$val['paper_id']]=$val['score'];
- }
- }
- if(!$AllPaperIds){
- $result['msg']='考试ID错误3';
- exit(json_encode($result));
- }
- $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();
- if(!$paperTopicRelation){
- $result['msg']='试卷试题有误';
- exit(json_encode($result));
- }
- //更新规则
- $tplRules=array();
- if(isset($tplData['new_rules'])){
- $tplRules=$tplData['new_rules'];
- }
- $updatePaperScoreSql=array();
- foreach ($paperTopicRelation as $value){
- if(isset($topicIdArr[(string)$value['topic_id']])){
- $order=$value['order'];
- $newScore=$topicIdArr[(string)$value['topic_id']]['score'];
- $tplRules[$value['order']]=array(
- 'topicNo'=>$value['order'],
- 'topic_id'=>$value['topic_id'],
- 'rule_type'=>(int)$topicIdArr[(string)$value['topic_id']]['rule'],
- 'rule_answer'=>$topicIdArr[(string)$value['topic_id']]['answer'],
- 'rule_score'=>$newScore,
- 'rule_score_half'=>$topicIdArr[(string)$value['topic_id']]['half_score'],
- );
- if($value['score']!==$newScore){
- if(isset($tplData['new_items'])){
- foreach ($tplData['new_items'] as $key => $val){
- if($val['id']==$order){
- $tplData['new_items'][$key]['score']=$newScore;
- }
- }
- }
- $updatePaperScoreSql[] = 'update `paper_topic_relation` set `score` = ' . $newScore . ' where paper_id in (' . implode(',', $AllPaperIds) . ') and `topic_id` =' . $value['topic_id'];
- }
- }
- }
- $tplData['new_rules']=$tplRules;
- $paperScore=$this->sumTplDataScores($tplData,0);
- $Rs=array();
- $tplData['scores']=$paperScore;
- $tplData['total_score']=$paperScore;
- foreach ($AllPaperIds as $pid){
- $tempData=SStudentPaperTopicRs::model()->findAll("paper_id ='".$pid."' and topic_id in(".implode(',',$topicIds).")");
- if($tempData){
- foreach ($tempData as $v){
- $Rs[]=array(
- 'topic_id' =>$v['topic_id'],
- 'answer' =>$v['answer'],
- 'paper_id' =>$v['paper_id'],
- 'student_id' =>$v['student_id'],
- );
- }
- }
- }
- $updateRightData=array();
- $updateScoreData=array();
- $updateStudentPaperRelation=array();
- if($Rs){
- foreach ($Rs as $k=> $v){
- $answer=$topicIdArr[(string)$v['topic_id']]['answer'];
- $rule=$topicIdArr[(string)$v['topic_id']]['rule'];
- if(!$v['answer']){
- $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
- $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
- }else{
- if($v['answer'] == $answer){
- $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=1;
- $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=$topicIdArr[$v['topic_id']]['score'];
- }else{
- switch ($rule){
- case 1: //规则A 最严格规则
- $update_data['scoring']=0;
- $update_data['is_right']=0;
- $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
- $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
- break;
- case 2://规则B 半对规则
- //查找错误选择
- $answerArr=explode(',',$answer);
- $tempAnswer = explode(',', $v['answer']);
- $FindWrong=false;
- foreach ($tempAnswer as $av) {
- if(!in_array($av,$answerArr)){
- $FindWrong=true;
- break;
- }
- }
- if($FindWrong){
- $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
- $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
- }else{
- $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;//半对算错
- $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=$topicIdArr[$v['topic_id']]['half_score'];
- }
- break;
- case 3://规则C 宽松半对规则
- //查找正确选择
- $answerArr=explode(',',$answer);
- $tempAnswer = explode(',', $v['answer']);
- $IsWrong=true;
- if(count($tempAnswer)<=count($answerArr)){
- foreach ($tempAnswer as $av) {
- if (false !== strpos($answer, $av)) {
- $IsWrong=false;
- break;
- }
- }
- }
- //错误答案情况
- if($IsWrong){
- $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
- $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;
- }else{
- $updateRightData[$v['paper_id']][$v['topic_id']][$v['student_id']]=0;//半对算错
- $updateScoreData[$v['paper_id']][$v['topic_id']][$v['student_id']]=$topicIdArr[$v['topic_id']]['half_score'];
- }
- break;
- }
- }
- }
- //更新总分queryAll
- $updateStudentPaperRelation[$v['student_id']]=$v['paper_id'];
- }
- }
- $updateStudentPaperRelationSql=array();
- if($updateRightData){
- $sqlIsRight=array();
- $sqlScore=array();
- foreach ($updateRightData as $paperId=>$val){
- foreach ($val as $topicId=>$v){
- $sql=" update `student_paper_topic_rs` set `is_right`= case `student_id` ";
- foreach ($v as $studentId=>$isRight){
- $sql.=" WHEN ".$studentId." THEN '".$isRight."' ";
- }
- $sql.=" Else `is_right`";
- $sql.=" End ";
- $sql.=" where paper_id='{$paperId}' and topic_id='{$topicId}'";
- $sqlIsRight[]=$sql;
- }
- }
- foreach ($updateScoreData as $paperId=>$val){
- foreach ($val as $topicId=>$v){
- $sql=" update `student_paper_topic_rs` set `scoring`= case `student_id` ";
- foreach ($v as $studentId=>$score){
- $sql.=" WHEN ".$studentId." THEN '".$score."' ";
- }
- $sql.=" Else `scoring`";
- $sql.=" End ";
- $sql.=" where paper_id='{$paperId}' and topic_id='{$topicId}'";
- $sqlScore[]=$sql;
- }
- }
- $transaction = $this->sConn->beginTransaction();
- try {
- if($sqlIsRight){
- foreach ($sqlIsRight as $sql){
- $this->sConn->createCommand($sql)->execute();
- }
- }
- if($sqlScore){
- foreach ($sqlScore as $sql){
- $this->sConn->createCommand($sql)->execute();
- }
- }
- $transaction->commit();
- } catch (Exception $e) {
- //如果操作失败, 数据回滚
- $transaction->rollback();
- $result['status']=0;
- $result['msg']=' 报告更新失败';
- exit(json_encode($result));
- }
- if($updateStudentPaperRelation){
- foreach ($updateStudentPaperRelation as $studentId =>$paperId){
- $TotalScore = $paperScore[$paperId];
- $StudentAllTopicSql="select `is_right`,`scoring` from `student_paper_topic_rs` where `paper_id`='".$paperId."' and student_id='".$studentId."' ";
- $StudentAllTopic=$this->sConn->createCommand($StudentAllTopicSql)->queryAll();
- $right_count = 0;
- $partial_right_count = 0;
- $wrong_count = 0;
- $scoring = 0;
- $lost_score = 0;
- foreach ($StudentAllTopic as $value) {
- if ($value['is_right'] == 1) {
- $right_count++;
- } elseif ($value['is_right'] == 2) {
- $partial_right_count++;
- } else {
- $wrong_count++;
- }
- $scoring = bcadd($scoring, $value['scoring'], 1);
- }
- unset($StudentAllTopic);
- $lost_score = bcsub($TotalScore, $scoring, 1);
- $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."'";
- $paperRelattionSql.=" where `paper_id`='".$paperId."' and `student_id`='".$studentId."'";
- $updateStudentPaperRelationSql[]=$paperRelattionSql;
- }
- }
- $transaction = $this->sConn->beginTransaction();
- try {
- if($updateStudentPaperRelationSql){
- foreach ($updateStudentPaperRelationSql as $sql){
- $this->sConn->createCommand($sql)->execute();
- }
- }
- $sendParam=array(
- 'school_id'=>$this->schoolId,
- 'exam_group_id'=>$Exam_GroupId
- );
- $transaction->commit();
- //学生端接口
- $sendParam=array(
- 'school_id'=>$this->schoolId,
- 'exam_group_id'=>$Exam_GroupId
- );
- sendZsystNotic($sendParam);
- $kafkaData=array(
- 'schoolId'=>$this->schoolId,
- 'examGroupId'=>$Exam_GroupId,
- 'generateTime'=>time()*1000
- );
- sendDataToKafka("xbkc-academic-generate-report",$kafkaData);
- $this->sendNoticeToReport($Exam_GroupId);
- sendDataToKafka("zsy-marking-update-topic",$Exam_GroupId,false);
- $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$Exam_GroupId));
- if($exam_group_data->homework==1){
- //发送学生端消息
- $sendJsonArr=array(
- 'school_id'=>$this->schoolId,
- 'send_type'=>'zsyas',
- 'update_type'=>0,
- 'exam_group_id'=>$exam_group_data->exam_group_id,
- );
- sendStudentCacheQueue($sendJsonArr);
- }
- } catch (Exception $e) {
- //如果操作失败, 数据回滚
- $transaction->rollback();
- $result['status']=0;
- $result['msg']=' 报告更新失败';
- exit(json_encode($result));
- }
- }
- if($updatePaperScoreSql){
- foreach ($updatePaperScoreSql as $sql){
- $this->sConn->createCommand($sql)->execute();
- }
- }
- $sql = 'update `paper` set `score` = ' . $tplData['scores'] . ' where paper_id in (' . implode(',', $AllPaperIds) . ')';
- $this->sConn->createCommand($sql)->execute();
- $this->sConn->createCommand("update exam set tpl_data='" . jsonEncode($tplData) . "' where exam_group_id = '{$Exam_GroupId}'")->execute();
- $this->sendNoticeToReport($Exam_GroupId);
- if(Yii::app()->params['handle_log_on_off'])
- {
- Curl::post(Yii::app()->params['handle_log_api'], array(
- "exam_group_id" => 0,
- "operate_project" => 'zsyas2',
- "school_id" => $this->schoolId,
- "title" => '批量更新多选题报告',
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $this->getRoute(),
- "operate_sql" =>'',
- "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
- ));
- }
- $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$Exam_GroupId));
- if(isset($exam_group_data) && $exam_group_data->homework==1){
- //发送学生端消息
- $sendJsonArr=array(
- 'school_id'=>$this->schoolId,
- 'send_type'=>'zsyas',
- 'update_type'=>0,
- 'exam_group_id'=>$Exam_GroupId,
- );
- sendStudentCacheQueue($sendJsonArr);
- }
- $result['status']=1;
- $result['msg']='报告更新完成';
- exit(json_encode($result));
- }
- //更新选做题分数
- public function actionUpdateScoreXuan(){
- $scores = Req::post('scores');
- $paper_id = Req::post('paper_id');
- if(!$scores) {
- echo json_encode(array('status'=>0,'msg'=>'试题参数错误 '));
- exit;
- }
- $paper_data = SPaper::model()->find('paper_id=:paper_id',array(':paper_id'=>$paper_id));
- if(!$paper_data){
- echo json_encode(array('status'=>0,'msg'=>'试卷Id参数错误 '));exit;
- }
- $exam_data=Exam::model()->find('exam_id=:exam_id',array(':exam_id'=>$paper_data->exam_id));
- $xuan_topic=array();
- $tpl_data = json_decode($exam_data->tpl_data,true);
- foreach ($tpl_data['new_items'] as $val){
- if(isset($val['sameAliasNo']) && $val['sameAliasNo']) {
- $xuan_topic[$val['id']] = $val['id'];
- }
- }
- $topicType=17;
- $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)));
- $oldTopicScores=0; //原总分
- $newTopicScores=array(); //修改后总分
- $update_score=array(); //需要修改分数的topic
- $update_score_order=array(); //修改分数的序号
- if($paper_topic_data)
- {
- foreach($paper_topic_data as $v)
- {
- $oldTopicScores+=$v['score'];
- if(isset($xuan_topic[$v['order']])){
- if(isset($scores[$v['order']])){
- if($v['score']!=$scores[$v['order']]){
- $update_score[$v->topic_id] = $scores[$v->order];
- $update_score_order[$v->order] = $scores[$v->order];
- }
- $newTopicScores[]=$scores[$v['order']];
- }else{
- $newTopicScores[]=$v['score'];
- }
- }
- }
- }
- if(!$update_score){
- echo json_encode(array('status'=>0,'msg'=>'分数与原试题分数一致'));exit;
- }
- $paper_data = SPaper::model()->find('paper_id=:paper_id',array(':paper_id'=>$paper_id));
- $exam_ids = array();
- $paper_ids = array();
- if($paper_data)
- {
- if(isset($tpl_data['items'])){
- $objectiveTplData=array(
- 'total'=>count($scores),
- 'totalScore'=>array_sum($newTopicScores),
- 'perScores'=>array_values($newTopicScores)
- );
- $tpl_data['items'][$topicType]=$objectiveTplData;
- }
- //修改new_items
- if(isset($tpl_data['new_items'])){
- foreach ($tpl_data['new_items'] as $key =>$val){
- if(isset($update_score_order[$val['id']])){
- $tpl_data['new_items'][$key]['score']=$update_score_order[$val['id']];
- }
- }
- }
- $paper_score=$this->sumTplDataScores($tpl_data,0);
- $tpl_data['scores']= $tpl_data['total_score']=$paper_score;
- $json_tpl_data = jsonEncode($tpl_data);
- $exam_group_data = Exam::model()->findAll('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id));
- if($exam_group_data)
- {
- foreach($exam_group_data as $v)
- {
- $exam_ids[$v->exam_id] = $v->exam_id;
- }
- if($exam_ids)
- {
- $criteria = new CDbCriteria();
- $criteria->addInCondition('exam_id',$exam_ids);
- $paper_data = SPaper::model()->findAll($criteria);
- if($paper_data)
- {
- foreach($paper_data as $v)
- {
- $paper_ids[$v->paper_id] = $v->paper_id;
- }
- $trans = $this->sConn->beginTransaction();
- try{
- foreach ($update_score as $topic_id => $score){
- $sql='update `paper_topic_relation` set `score` = '.$score.' where paper_id in ('.implode(',',$paper_ids).') and `topic_id` ='.$topic_id;
- $this->sConn->createCommand($sql)->execute();
- }
- $sql='update `paper` set `score` = '.($paper_score).' where paper_id in ('.implode(',',$paper_ids).')';
- $this->sConn->createCommand($sql)->execute();
- $sql="update `exam` set `tpl_data` = '".($json_tpl_data)."' where exam_id in (".implode(',',$exam_ids).")";
- $this->sConn->createCommand($sql)->execute();
- $trans->commit();
- }
- catch(Exception $e){
- $trans->rollBack();
- echo json_encode(array('status'=>0));exit;
- }
- $sendParam=array(
- 'school_id'=>$this->schoolId,
- 'exam_group_id'=>$exam_data->exam_group_id
- );
- sendZsystNotic($sendParam);
- $kafkaData=array(
- 'schoolId'=>$this->schoolId,
- 'examGroupId'=>$exam_data->exam_group_id,
- 'generateTime'=>time()*1000
- );
- sendDataToKafka("xbkc-academic-offline-generate-report",$kafkaData);
- $this->sendNoticeToReport($exam_data->exam_group_id);
- sendDataToKafka("zsy-marking-update-topic",$exam_data->exam_group_id,false);
- $exam_group_data = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_data->exam_group_id));
- if($exam_group_data->homework==1){
- //发送学生端消息
- $sendJsonArr=array(
- 'school_id'=>$this->schoolId,
- 'send_type'=>'zsyas',
- 'update_type'=>0,
- 'exam_group_id'=>$exam_group_data->exam_group_id,
- );
- sendStudentCacheQueue($sendJsonArr);
- }
- if(Yii::app()->params['handle_log_on_off'])
- {
- Curl::post(Yii::app()->params['handle_log_api'], array(
- "exam_group_id" => 0,
- "operate_project" => 'zsyas2',
- "school_id" => $this->schoolId,
- "title" => '修改分数',
- "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
- "operate_method" => $this->action,
- "operate_url" => $this->getRoute(),
- "operate_sql" =>'',
- "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
- ));
- }
- echo json_encode(array('status'=>1,'msg'=>'修改成功'));exit;
- }
- }
- }
- }
- }
- //修改试题答案
- private function UpdateTopicAnswer($topicId,$answer,$type){
- if(!in_array($type,array(1,2,3,4,12))) return false;
- if(!preg_match('/^[A-Z,]+$/u',$answer)){
- return false;
- }
- $answers=explode(',',$answer);
- if(!$answers){
- return false;
- }
- $answer_type=array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T');
- foreach ($answers as $a){
- $a=strtoupper($a);
- $sort_order[] = array_search($a,$answer_type);
- }
- $topic_data = STopic::model()->find('topic_id=:topic_id ',array(':topic_id'=>$topicId));
- if(!$topic_data)
- {
- return -1; //不是校本题库的题
- }
- $topic_option_data = STopicItemOption::model()->findAll(array('order'=>'sort_order asc','condition'=>'topic_id=:topic_id','params'=>array(':topic_id'=>$topicId)));
- if($topic_option_data)
- {
- //判断答案范围
- $sortOrderArr=array();
- foreach ($sort_order as $st){
- if(($st+1)>count($topic_option_data)){
- return false;
- }
- if($st!==false){
- $sortOrderArr[]=$st;
- }
- }
- if(!$sortOrderArr){
- return false;
- }
- //异常情况,试题没有答案情况判断
- $NoAnswer=true;
- foreach ($topic_option_data as $datum){
- if($datum->option_correct==1){
- $NoAnswer=false;
- break;
- }
- }
- $flags = 1;
- if(!$NoAnswer){
- $flags = STopicItemOption::model()->updateAll(array('option_correct'=>0),'topic_id=:topic_id',array(':topic_id'=>$topicId));
- }
- if($flags && $sortOrderArr){
- $flags = 0;
- $flags = STopicItemOption::model()->updateAll(array('option_correct'=>1),'topic_id=:topic_id and sort_order in ('.implode(',',$sortOrderArr).')',array(':topic_id'=>$topicId));
- $topic_item_option = STopicItemOption::model()->findAll('topic_id=:topic_id',array(':topic_id'=>$topicId));
- if($topic_item_option)
- {
- //清缓存
- Yii::app()->school_topic_cache->hmset('content:school_topic:'.$topicId,array('id' => 0));
- if($topic_data->stem_id){
- Yii::app()->school_topic_cache->hmset('content:school_topic:'.$topic_data->stem_id,array('id' => 0));
- }
- }
- if($flags){
- return true;
- }
- }
- }
- return false;
- }
- }
|