123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144 |
- <?php
- class AcademicrBatchCommand extends CConsoleCommand {
- public $conn;
- public $sConn;
- public function init() {
- parent::init();
- @ini_set('memory_limit', '1024M');
- set_time_limit(0);
- }
- public $authUsername = '';
- private $units = array(
- 'in' => 96,
- 'cm' => 28,
- 'mm' => 2.8,
- 'pt' => 1.33,
- 'pc' => 12,
- );
- public function actionIndex($YII_ENV='development',$taskId=""){
- //echo YII_ENV;exit;
- if(YII_ENV == "production"){
- $file_html_url = "http://zsyas2.zhixinhuixue.com";
- }else{
- if(YII_ENV == 'development'){
- $file_html_url = "http://xbas2.dev.xiaoben.com";
- }else{
- $file_html_url = "http://xbas2.testing.xiaoben.com";
- }
- }
- //连接业务库
- $conn = $this->getDbConnection(Yii::app()->params["default_server"]['addr'], Yii::app()->params["default_db"]['name'], Yii::app()->params["default_server"]['username'], Yii::app()->params["default_server"]['password']);
- if($conn){
- $this->conn = $conn;
- $time = time();
- //获取要生成教师讲案的数据
- if(isset($taskId) && $taskId){
- $sql = "select id,school_id,exam_group_id,class_ids from download_table_setting where id='{$taskId}'";
- }else{
- $sql = "select id,school_id,exam_group_id,class_ids from download_table_setting where download_type = 3 and status = 1 and error_msg = '' and subject_id in (3,6,51) order by create_time asc";
- }
- $result_all = $this->conn->createCommand($sql)->queryAll();
- //超过五分钟默认生成失败
- $sql = "update download_table_setting set status = 3,error_msg ='系统错误,建议单个生成' where status = 4 and error_msg = '' and update_time <".($time-600);
- $this->conn->createCommand($sql)->execute();
-
- if($result_all){
- // $time = time();
- // $sql = "update download_table_setting set update_time = {$time},status=4 where download_type = 3 and status = 1 and error_msg = '' and subject_id in (3,6,51)";
- // $this->conn->createCommand($sql)->execute();
- // foreach($result_all as $v_data){
- foreach($result_all as $v_data_k=>$v_data){
- if($v_data_k > 0){
- break;
- }
- // var_dump($v_data);exit;
- $coach_name = "";
- $sql = "select coach_name from coach where school_id='{$v_data['school_id']}' and `status`=0";
- $coach_one = $this->conn->createCommand($sql)->queryRow();
- if($coach_one){
- $coach_name = $coach_one["coach_name"];
- }
- $sql = "select school_name from school where school_id = '{$v_data['school_id']}'";
- $school_one = $this->conn->createCommand($sql)->queryRow();
- if($school_one){
- $school_name = $school_one["school_name"];
- }else{
- $school_name = "";
- }
- $sql = "update download_table_setting set update_time = {$time},status=4 where id ={$v_data['id']}";
- $this->conn->createCommand($sql)->execute();
- $error = array();
- $pdfArr = array();
- $is_success = 0;
- //学管账号
- $coach = $this->conn->createCommand("select coach_name from coach where `status` = 0 and school_id={$v_data['school_id']};")->queryRow();
- if($coach){
- $authUsername = $v_data['school_id'].'_'.$coach['coach_name'];
- }else{
- echo $v_data['school_id']."学校获取学管信息失败\n";
- $error[] = $v_data['school_id']."学校获取学管信息失败";
- continue;
- }
- try{
- if($v_data['class_ids'] && $v_data['school_id'] && $v_data['exam_group_id']){
- //连接学校库
- $sql = "select database_host,database_user,database_password,database_name,group_id from `database` where school_id = '{$v_data['school_id']}'";
- $conn = $this->getDbConnection(Yii::app()->params["default_server"]['addr'], Yii::app()->params["default_db"]['name'], Yii::app()->params["default_server"]['username'], Yii::app()->params["default_server"]['password']);
- if($conn){
- $this->conn = $conn;
- }else{
- echo "连接业务库失败\n";
- $error[] = "连接业务库失败";
- continue;
- }
- $result_one = $this->conn->createCommand($sql)->queryRow();
- if($result_one){
- $school_group_id = $result_one["group_id"];
- if (!is_numeric($school_group_id)){
- $school_group_id = 0;
- }
- $sConn = $this->getDbConnection($result_one["database_host"],$result_one["database_name"], $result_one["database_user"],$result_one["database_password"]);
- if($sConn){
- $sql = "select * from group_server where group_id = '{$school_group_id}'";
- $group_server_data = $this->conn->createCommand($sql)->queryRow();
- $static_url_data = $group_server_data['static_url'];
- $this->sConn = $sConn;
- echo '连接学校ID'.$v_data['school_id']."成功\n";
- $null_data = 1;
- $pdfNames = array();
- echo '开始获取任务ID'.$v_data['id']."的数据\n";
- $classIds = explode(",", $v_data["class_ids"]);
- if($classIds){
- foreach($classIds as $classId){
- $this->sConn->active = false;
- $sConn = $this->getDbConnection($result_one["database_host"],$result_one["database_name"], $result_one["database_user"],$result_one["database_password"]);
- $this->sConn = $sConn;
- echo "开始获取classId=".$classId."的数据\n";
- $data = array();
- $sql = "select class_name from class where class_id = '{$classId}'";
- $data_one = $this->sConn->createCommand($sql)->queryRow();
- if($data_one){
- $className = $data_one['class_name'];
- }else{
- $className = "";
- }
- $sql = "select exam_id,name from exam where exam_group_id = '{$v_data["exam_group_id"]}' and class_id = '{$classId}'";
- $data_one = $this->sConn->createCommand($sql)->queryRow();
- if($data_one){
- $examId = $data_one["exam_id"];
- $examName = $data_one["name"];
- $codeNow = $this->getCodeByExamId($examId);//当前学期code
- if($codeNow){
- $isFromPast = 1;
- }else{
- $isFromPast = 0;
- }
- $sql = "select e.teacher_id,eg.mark_type,e.name as exam_name,e.academicr_pdf_path,e.academicr_pdf_time,p.paper_id,e.is_academicr_pdf,c.class_name,eg.import_score_type,c.grade,p.method_ids,e.semester_id from exam as e left join class as c on c.class_id=e.class_id left join exam_group as eg on e.exam_group_id=eg.exam_group_id left join paper as p on p.exam_id=e.exam_id where e.exam_id={$examId}";
- $exam_info = $this->sConn->createCommand($sql)->queryRow();
- $grade = $exam_info['grade'];
- $paper_method_ids = $exam_info['method_ids'];
- $score_type = $exam_info['import_score_type'];//成绩导入流程 0-正常扫描
- $semesterId = $exam_info['semester_id'];
- if ($exam_info['mark_type'] == 0) {
- if(empty($codeNow)){
- $sql = "SELECT feedback_time
- FROM student_paper_relation
- WHERE paper_id = '" . $exam_info['paper_id'] . "' AND is_feedback = '1' AND is_del = '0' order by feedback_time desc limit 1";
- }else{
- $sql = "SELECT feedback_time
- FROM student_paper_relation_".$codeNow."
- WHERE paper_id = '" . $exam_info['paper_id'] . "' AND is_feedback = '1' AND is_del = '0' order by feedback_time desc limit 1";
- }
- $query = $this->sConn->createCommand($sql)->queryRow();
- if ($query && $query['feedback_time'] >= $exam_info['academicr_pdf_time']) {
- if (file_exists($exam_info['academicr_pdf_path'])) {
- unlink($exam_info['academicr_pdf_path']);
- }
- $force = 1;
- }
- unset($query);
- }
- $pdfpath = str_replace("protected", "", Yii::app()->basePath) . $exam_info['academicr_pdf_path'];
- $pdfurl = $pdfpath =$exam_info['academicr_pdf_path'];
- $is_create=1;
- $force = 0;
- if(strpos($pdfurl,'http') !== false){
- if(!file_get_contents($pdfurl)){
- $force = 1;
- }
- }else{
- $force = 1;
- }
- if (!$exam_info['academicr_pdf_path'] || $exam_info['is_academicr_pdf'] == 0 || $force) {
- // if (!$exam_info['academicr_pdf_path'] || $exam_info['is_academicr_pdf'] == 0 || !$this->check_pdf($pdfpath)) {
- $is_create=0;
- $sql = "SELECT e.exam_group_id, e.exam_id, e.name AS exam_name, e.create_time AS exam_time, p.paper_id, p.score as paper_score, e.class_id,e.is_preparation_created,e.tpl_index, eg.mark_type,p.is_labelled,p.labelled_type,eg.qxk_paper_id ";
- $sql.= "FROM exam e ";
- $sql.= "JOIN paper p ON p.exam_id = e.exam_id ";
- $sql.= "JOIN exam_group eg ON eg.exam_group_id = e.exam_group_id ";
- $sql.= "WHERE e.status = '1' AND e.exam_id = '{$examId}' ";
- $data = array();
- $exam = $this->sConn->createCommand($sql)->queryRow();
- $labelled_type = $exam['labelled_type'];
- $class_id = $exam['class_id'];
- $is_qxk = $exam['qxk_paper_id']?1:0;//是否是全学科
- if($is_qxk){
- $qxkKnowledge = SPaperTopicRelation::newKnowledgeRelate();//获取全学科知识点对应老知识点的关系
- }
- if($class_id){
- $exam['show_level'] = $this->get_version($class_id);
- $exam['level_rule'] = $this->get_level_rule($class_id);
- }
- //获取显示设置
- $setting_arr = array("common"=>1,"common_wrong"=>1,"paper"=>1,"paper_wrong"=>1,"real_topic"=>1,"classmateOptimization"=>1);
- $sql = "select tt.template_id,tt.config_text from teaching_template tt join teaching_class_set tcs on tt.template_id=tcs.template_id where tt.subject_id = 3 and tcs.class_id='{$class_id}'";
- $setting_data = $this->sConn->createCommand($sql)->queryRow();
- if($setting_data){
- $setting_data_arr = json_decode($setting_data['config_text'],true);
- if(isset($setting_data_arr['common'])){
- $setting_arr['common'] = $setting_data_arr['common'];
- }
- if(isset($setting_data_arr['common_wrong'])){
- $setting_arr['common_wrong'] = $setting_data_arr['common_wrong'];
- }
- if(isset($setting_data_arr['paper'])){
- $setting_arr['paper'] = $setting_data_arr['paper'];
- }
- if(isset($setting_data_arr['paper_wrong'])){
- $setting_arr['paper_wrong'] = $setting_data_arr['paper_wrong'];
- }
- if(isset($setting_data_arr['real_topic'])){
- $setting_arr['real_topic'] = $setting_data_arr['real_topic'];
- }
- if(isset($setting_data_arr['classmateOptimization'])){
- $setting_arr['classmateOptimization'] = $setting_data_arr['classmateOptimization'];
- }
- }
- $is_same_bs = 1;//是否开启相同变式题(需要读提分宝班级定制的配置)
- $same_bs_data = array();//开启相同变式题 原题跟变式题的对应关系
- $is_same_bs = $this->getClassSet($classId, $semesterId);
- if($is_same_bs && $labelled_type == 1){
- //判断有没有订单(提分方案2,提分宝3) 如果没有订单生成教学宝 有订单没数据不能生成
- $has_order = 0;
- $table_spr = empty($codeNow)?'student_paper_relation':'student_paper_relation_'.$codeNow;
- $sql = "select student_id from {$table_spr} where exam_id = '{$examId}'";
- $spr_data = $this->sConn->createCommand($sql)->queryAll();
- $relateStudentRes = array();
- if($spr_data){
- foreach($spr_data as $spr_v){
- $relateStudentRes[]['student_id'] = $spr_v['student_id'];
- }
- }
- foreach(array(2,3) as $product_type){
- $temp_order = $this->getOrderStu($examId, $classId, $product_type, $relateStudentRes, $semesterId, $grade,$v_data['school_id'],$coach_name);
- if($temp_order && isset($temp_order['limitstu']) && $temp_order['limitstu']){
- $has_order = 1;
- break;
- }
- }
- $sql = "select preparation_plan_id,template_id,topic_id from preparation_plan_topic where preparation_plan_id='{$examId}'";
- $same_bs = $this->sConn->createCommand($sql)->queryAll();
- if($same_bs){
- foreach($same_bs as $same_k=>$same_v){
- $same_bs_data[$same_v['template_id']][] = $same_v['topic_id'];
- }
- }else{
- if($has_order){
- echo json_encode(array("status"=>1,"error"=>"变式题未生成,请等待"));
- $error[] = $className."变式题未生成";
- continue;
- // exit;
- }
- }
- $setting_arr['common'] = 0;
- }
- if($labelled_type == 2){
- $exam['show_level'] = 0;
- }else{
- $sql = "select switch from producut_set_edition";
- $switch_data = $this->sConn->createCommand($sql)->queryRow();
- if($switch_data && in_array($switch_data['switch'],array(3,4))){
- $exam['show_level'] = 0;
- $sql = "select template_id,topic_id,topic_type from product_common_topic where exam_id = '{$examId}' and is_action=0 order by topic_type asc";
- $gongxing_data = $this->sConn->createCommand($sql)->queryAll();
- if(!$gongxing_data){
- echo json_encode(array("status"=>1,"error"=>"共性问题未生成,请稍等"));
- $error[] = $className."共性问题未生成";
- continue;
- // exit;
- }
- }else{
- if ($exam && !$isFromPast && $exam['show_level'] == 1 && $exam['is_preparation_created'] != 1) { //如果选择的是分层班,教师讲案的生成条件是教师讲评题已经抽出
- echo json_encode(array("status"=>1,"error"=>"文件内容尚未生成,请等待"));
- exit;
- }elseif ($exam && !$isFromPast && $exam['show_level'] == 1 && $exam['is_preparation_created'] == 2) {
- echo json_encode(array("status"=>1,"error"=>"由于题库题目导致无法生成,请联系后台题库老师去处理题目!"));
- exit;
- }
- }
- }
- if ($exam['is_labelled']!=1) {
- echo "试卷还未标注,请先标注试卷\n";
- $error[] = $className."试卷还未标注,请先标注试卷";
- continue;
- }
- // if($switch_data && in_array($switch_data['switch'],array(3,4))){
- // $sql = "select template_id,topic_id,topic_type from product_common_topic where exam_id = '{$examId}' order by topic_type asc";
- // $gongxing_data = $this->sConn->createCommand($sql)->queryAll();
- // if(!$gongxing_data){
- // echo "共性问题未生成,请等待\n";
- // $error[] = $className."共性问题未生成,请等待";
- // continue;
- // }
- // }
- if ($exam) {
- //同学优解
- $excellent_solution = SStudentPaperTopicRs::model()->bestAnswer($exam,$codeNow,$static_url_data,$this->sConn,$is_qxk);
-
- //获取共性问题
- $has_topic_gaokao = array();//本教学宝其他题,用于抽取高考真题
- $gen_topics = array();
- $gen_topics_ids = array();//共性所有题ID集合
- $gen_topics_detail = array();//试题详情
- $gen_topics_msg = array();//题目难度、考点、挑战信息
- // $schoolId = $this->schoolId;//当前学校
- $school_province_name = "";//学校省份
- $school_province_id = 0;//学校省份Id
- $gen_origin_ids = array();//共性原题Id
- $gen_origin_methods = array();//共性原题考点集合
- // $school_msg = Yii::app()->businessDb->createCommand()->from('school')
- // ->select("province_id")
- // ->where("school_id = ".$v_data['school_id'])
- // ->queryRow();
- $this->conn->active = false;
- $conn = $this->getDbConnection(Yii::app()->params["default_server"]['addr'], Yii::app()->params["default_db"]['name'], Yii::app()->params["default_server"]['username'], Yii::app()->params["default_server"]['password']);
- $this->conn = $conn;
- $sql = "select province_id from school where school_id = '{$v_data['school_id']}'";
- $school_msg = $this->conn->createCommand($sql)->queryRow();
- if($school_msg){
- $school_province_id = $school_msg['province_id'];
- }
- if($school_province_id){
- // $region_msg = Yii::app()->businessDb->createCommand()->from('region')
- // ->select("region_name")
- // ->where("region_id = ".$school_province_id)
- // ->queryRow();
- $sql = "select region_name from region where region_id = '{$school_province_id}'";
- $region_msg = $this->conn->createCommand($sql)->queryRow();
- if($region_msg){
- $school_province_name = $region_msg["region_name"];
- }
- }
- $sql = "select template_id,topic_id,topic_type,template_no from product_common_topic where exam_id = '{$examId}' and is_action=0 order by topic_type asc";
- $gongxing_data = $this->sConn->createCommand($sql)->queryAll();
- if($gongxing_data){
- foreach($gongxing_data as $k=>$v){
- $i = 0;
- $gen_topics_ids[] = $gen_origin_ids[] = $v['template_id'];
- $gen_topics_ids[] = $v['topic_id'];
- $gen_topics[$v['topic_type']][$i]['topic_id'] = $v['template_id'];
- $gen_topics[$v['topic_type']][$i]['is_template'] = 1;
- $i++;
- $gen_topics[$v['topic_type']][$i]['topic_id'] = $v['topic_id'];
- $gen_topics[$v['topic_type']][$i]['is_template'] = 0;
- //变式训练获取地区挑战数
- if($v['topic_id']){
- $gen_topics_msg[$v['topic_id']]['school_province_name'] = $school_province_name;
- $topic_count = Yii::app()->topic_province_count->hmget('province_stat:topic:'.$school_province_id,array($v['topic_id']));
- if($topic_count && isset($topic_count[0])){
- $gen_topics_msg[$v['topic_id']]['province_count'] = empty($topic_count[0])?1000:$topic_count[0]+1000;
- }else{
- $gen_topics_msg[$v['topic_id']]['province_count'] = 1000;
- }
- $gen_topics_msg[$v['template_id']]['template_no'] = $v['template_no'];
- }
- }
- }
- $gen_topics_ids = array_values(array_unique($gen_topics_ids));
- if($gen_topics_ids){
- $topicItems_1 = $this->aipost('/topic/batchAll', array('topicIds' => $gen_topics_ids));
- //debug($topicItems_1);
- if ($topicItems_1 && !isset($topicItems_1['status'])) {
- foreach ($topicItems_1 as $topicItem) {
- $gen_topics_detail_temp[$topicItem['id']] = $topicItem;
- }
- if ($gen_topics_detail_temp) {
- foreach ($gen_topics_detail_temp as $k => $v) {
- $v=(array)$v;
- $v['id'] = (string)$v['id'];
- $teacher_tips= isset($v['teacher_tips'])?$v['teacher_tips']:"";
- if(!$teacher_tips){
- $teacher_tips = $this->dealTeacherTips($v);
- }
- $v['teacher_tips'] = $this->topicProcess($teacher_tips);
- $v['parse_content'] = $this->topicProcess($v['parse_content']);
- if($v['type_id'] == 5 || $v['type_id'] == 6){
- $v['title'] = preg_replace("/<img[^>]*[\s]+src[\s]*=[\s]*(([\'\"](\/images\/list_\d\.png)[\'\"])|(\/images\/list_\d\.png))[^>]*>/si", '__________', $v['title']);
- }
- $v['title'] = $this->topicProcess($v['title']);
- if(isset($v['items'][0])){
- $v['items'][0]=(array)$v['items'][0];
- $v['items'][0]['options']=(array)$v['items'][0]['options'];
- if (isset($v['items']) && isset($v['items'][0]) && isset($v['items'][0]['options'])) {
- foreach ($v['items'][0]['options'] as $key => $val) {
- $val=(array)$val;
- $v['items'][0]['options'][$key]=(array)$v['items'][0]['options'][$key];
- $v['items'][0]['options'][$key]['option_content'] = $this->topicProcess($val['option_content']);
- }
- }
- }
- //难度
- $gen_topics_msg[$v['id']]['difficulty'] = isset($v['difficulty_degree'])?$v['difficulty_degree']:0;
- //考点
- $gen_topics_msg[$v['id']]['methods'] = "";
- $methods_arr = array();
- if(isset($v['specials']) && $v['specials']){
- foreach($v['specials'] as $specials){
- if(isset($specials['method_name'])){
- $methods_arr[] = $specials['method_name'];
- }
- if(in_array($v['id'],$gen_origin_ids)){
- $gen_origin_methods[$specials['method_id']] = $specials['method_name'];
- }
- }
- }elseif (isset($v['kps']) && $v['kps']){
- foreach($v['kps'] as $kps){
- if(isset($kps['kp_name'])){
- $methods_arr[] = $kps['kp_name'];
- }
- if(in_array($v['id'],$gen_origin_ids)){
- $gen_origin_methods[$kps['kp_id']] = $kps['kp_name'];
- }
- }
- }
- if($methods_arr){
- $gen_topics_msg[$v['id']]['methods'] = implode(",",$methods_arr);
- }
- $gen_topics_detail[$v['id']] = $v;
- }
- }
- unset($gen_topics_detail_temp);
- }
- unset($topicItems_1);
- }
- //年级共性问题
- $grade_topics_ids = array();
- $grade_topic_data = array();
- $sql = "select topic_id from product_grade_common_topic where exam_group_id = '{$exam['exam_group_id']}'";
- $grade_data = $this->sConn->createCommand($sql)->queryAll();
- if($grade_data){
- foreach($grade_data as $k=>$v){
- $grade_topics_ids[] = $v['topic_id'];
- }
- }
- if($grade_topics_ids){
- $grade_topic_item = $this->aipost('/topic/batchAll', array('topicIds' => $grade_topics_ids));
- if ($grade_topic_item && !isset($grade_topic_item['status'])) {
- foreach ($grade_topic_item as $k => $v) {
- $v['parse_content'] = $this->topicProcess($v['parse_content']);
- if($v['type_id'] == 5 || $v['type_id'] == 6){
- $v['title'] = preg_replace("/<img[^>]*[\s]+src[\s]*=[\s]*(([\'\"](\/images\/list_\d\.png)[\'\"])|(\/images\/list_\d\.png))[^>]*>/si", '__________', $v['title']);
- }
- $v['title'] = $this->topicProcess($v['title']);
- if(isset($v['items'][0])){
- if (isset($v['items']) && isset($v['items'][0]) && isset($v['items'][0]['options'])) {
- foreach ($v['items'][0]['options'] as $key => $val) {
- $v['items'][0]['options'][$key]=(array)$v['items'][0]['options'][$key];
- $v['items'][0]['options'][$key]['option_content'] = $this->topicProcess($val['option_content']);
- }
- }
- }
- $grade_topic_item[$k] =$v;
- }
- $grade_topic_data = $grade_topic_item;
- }
- }
- $data['grade_topic_data'] = $grade_topic_data;
- $data['gen_origin_methods'] = $gen_origin_methods?implode(",",$gen_origin_methods):"";
- $data['gen_topics_msg'] = $gen_topics_msg;
- $data['gen_topics'] = $gen_topics;
- $data['gen_topics_detail'] = $gen_topics_detail;
- $data['excellent_solution'] = $excellent_solution;
- $data['wb_isp_version'] = $exam['show_level'];
- $data['level_rule'] = $exam['level_rule'];
- $data['examGroups'] = array();
- $data['examGroupIds'] = array();
- $data['exams'] = array();
- $data['examIds'] = array();
- $data['prevExams'] = array();
- $data['prevExamIds'] = array();
- $data['papers'] = array();
- $data['paperIds'] = array();
- $data['prevPapers'] = array();
- $data['prevPaperIds'] = array();
- $data['fcTopicIds'] = array();
- $data['methodIds'] = array();
- $data['methodNames'] = array();
- $data['topicIds'] = array();
- $data['noTopicIds'] = array();
- $data['topicDetails'] = array();
- $data['answer_score_details'] = array();//客观题答案明细
- if (!isset($data['examGroups'][$exam['exam_group_id']])) {
- $data['examGroups'][$exam['exam_group_id']] = array(
- 'examIds' => array(),
- 'paperIds' => array(),
- 'examName' => $exam['exam_name'],
- 'examTime' => $exam['exam_time'],
- 'fullScore' => $exam['paper_score'],
- );
- }
- $data['examGroups'][$exam['exam_group_id']]['examIds'][] = $exam['exam_id'];
- $data['examGroups'][$exam['exam_group_id']]['paperIds'][] = $exam['paper_id'];
- if (!isset($data['exams'][$exam['exam_id']])) {
- $data['exams'][$exam['exam_id']] = array(
- 'paperIds' => array(),
- 'examName' => $exam['exam_name'],
- 'examTime' => $exam['exam_time'],
- 'examGroupId' => $exam['exam_group_id'],
- 'fullScore' => $exam['paper_score'],
- );
- }
- $data['exams'][$exam['exam_id']]['paperIds'][] = $exam['paper_id'];
- if (!isset($data['papers'][$exam['paper_id']])) {
- $data['papers'][$exam['paper_id']] = array();
- }
- $data['papers'][$exam['paper_id']]['examId'] = $exam['exam_id'];
- $data['papers'][$exam['paper_id']]['examName'] = $exam['exam_name'];
- $data['papers'][$exam['paper_id']]['examTime'] = $exam['exam_time'];
- $data['papers'][$exam['paper_id']]['examGroupId'] = $exam['exam_group_id'];
- $data['papers'][$exam['paper_id']]['fullScore'] = $exam['paper_score'];
- $data['examGroupIds'][] = $exam['exam_group_id'];
- $data['examIds'][] = $exam['exam_id'];
- $data['paperIds'][] = $exam['paper_id'];
- // 上一次考试
- $sql = "SELECT e.exam_id, p.paper_id
- FROM exam e
- JOIN paper p ON p.exam_id = e.exam_id
- WHERE e.subject_id in(3,6,51) and e.class_id = '" . $exam['class_id'] . "' AND e.create_time < '" . $exam['exam_time'] . "' AND e.status = '1'
- ORDER BY e.create_time DESC
- LIMIT 1";
- $query = $this->sConn->createCommand($sql)->queryRow();
- if ($query) {
- $codePrev = $this->getCodeByExamId($query['exam_id']);
- $data['prevExamIds'][] = $query['exam_id'];
- $data['prevPaperIds'][] = $query['paper_id'];
- $data['exams'][$exam['exam_id']]['prevExamId'] = $query['exam_id'];
- $data['papers'][$exam['paper_id']]['prevPaperId'] = $query['paper_id'];
- $data['prevExams'][$query['exam_id']] = $exam['exam_id'];
- $data['prevPapers'][$query['paper_id']] = $exam['paper_id'];
- // 上次考试总分
- $prevQuery = $this->sConn->createCommand("
- SELECT score
- FROM paper
- WHERE paper_id = '" . $query['paper_id'] . "'
- ")->queryRow();
- if ($prevQuery) {
- $data['papers'][$exam['paper_id']]['prevFullScore'] = $prevQuery['score'];
- }
- unset($prevQuery);
- // 上次考试的平均得分率
- if(empty($codePrev)){
- $prevQuery = $this->sConn->createCommand("
- SELECT paper_id, COUNT(student_id) AS total_num, SUM(scoring) AS total_score, MAX(scoring) AS max_score, MIN(scoring) AS min_score
- FROM student_paper_relation
- WHERE is_feedback = '1' AND paper_id = '" . $query['paper_id'] . "'
- ")->queryRow();
- }else{
- $prevQuery = $this->sConn->createCommand("
- SELECT paper_id, COUNT(student_id) AS total_num, SUM(scoring) AS total_score, MAX(scoring) AS max_score, MIN(scoring) AS min_score
- FROM student_paper_relation_".$codePrev."
- WHERE is_feedback = '1' AND paper_id = '" . $query['paper_id'] . "'
- ")->queryRow();
- }
- if ($prevQuery) {
- $data['papers'][$exam['paper_id']]['prevTotalNum'] = $prevQuery['total_num'];
- $data['papers'][$exam['paper_id']]['prevTotalScore'] = $prevQuery['total_score'];
- $data['papers'][$exam['paper_id']]['prevMaxScore'] = $prevQuery['max_score'];
- $data['papers'][$exam['paper_id']]['prevMinScore'] = $prevQuery['min_score'];
- $data['papers'][$exam['paper_id']]['prevAvgScore'] = 0;
- $data['papers'][$exam['paper_id']]['prevAvgRate'] = 0;
- if ($prevQuery['total_num'] > 0) {
- $data['papers'][$exam['paper_id']]['prevAvgScore'] = number_format($prevQuery['total_score'] / $prevQuery['total_num'], 2);
- if (isset($data['papers'][$exam['paper_id']]['prevFullScore']) && $data['papers'][$exam['paper_id']]['prevFullScore'] > 0) {
- $data['papers'][$exam['paper_id']]['prevAvgRate'] = number_format($prevQuery['total_score'] / ($prevQuery['total_num'] * $data['papers'][$exam['paper_id']]['prevFullScore']), 4) * 100;
- }
- }
- }
- }
- unset($query);
- // 参加考试人数、平均得分率、平均分、及格率、最高分、最低分
- if(empty($codeNow)){
- $query = $this->sConn->createCommand("
- SELECT paper_id, COUNT(student_id) AS total_num, SUM(scoring) AS total_score, MAX(scoring) AS max_score, MIN(scoring) AS min_score
- FROM student_paper_relation
- WHERE is_feedback = '1' AND paper_id IN (" . implode(',', $data['paperIds']) . ")
- GROUP BY paper_id
- ")->queryAll();
- }else{
- $query = $this->sConn->createCommand("
- SELECT paper_id, COUNT(student_id) AS total_num, SUM(scoring) AS total_score, MAX(scoring) AS max_score, MIN(scoring) AS min_score
- FROM student_paper_relation_".$codeNow."
- WHERE is_feedback = '1' AND paper_id IN (" . implode(',', $data['paperIds']) . ")
- GROUP BY paper_id
- ")->queryAll();
- }
- if ($query) {
- foreach ($query as $k => $v) {
- $data['papers'][$v['paper_id']]['totalNum'] = $v['total_num'];
- $data['papers'][$v['paper_id']]['totalScore'] = $v['total_score'];
- $data['papers'][$v['paper_id']]['maxScore'] = $v['max_score'];
- $data['papers'][$v['paper_id']]['minScore'] = $v['min_score'];
- $data['papers'][$v['paper_id']]['avgScore'] = 0;
- $data['papers'][$v['paper_id']]['avgRate'] = 0;
- $data['papers'][$v['paper_id']]['avgFluctuate'] = 0;
- if ($v['total_num'] > 0) {
- $data['papers'][$v['paper_id']]['avgScore'] = number_format($v['total_score'] / $v['total_num'], 2);
- if (isset($data['papers'][$exam['paper_id']]['fullScore']) && $data['papers'][$exam['paper_id']]['fullScore'] > 0) {
- $data['papers'][$v['paper_id']]['avgRate'] = number_format($v['total_score'] / ($v['total_num'] * $data['papers'][$exam['paper_id']]['fullScore']), 4) * 100;
- if (isset($data['papers'][$v['paper_id']]['prevAvgRate'])) {
- $data['papers'][$v['paper_id']]['avgFluctuate'] = number_format($data['papers'][$v['paper_id']]['avgRate'] - $data['papers'][$v['paper_id']]['prevAvgRate'], 2);
- }
- }
- }
- }
- }
- unset($query);
- // 单题班级情况
- if(empty($codeNow)){
- $sql = "
- SELECT sptr.student_id, sptr.paper_id, sptr.topic_id, sptr.is_right, sptr.scoring, ptr.score,sptr.handlerIndex
- FROM student_paper_topic_rs sptr
- JOIN paper_topic_relation ptr ON (ptr.paper_id = sptr.paper_id AND ptr.topic_id = sptr.topic_id) where 1=1 ";
- //WHERE sptr.handlerIndex = '1'";
- }else{
- $sql = "
- SELECT sptr.student_id, sptr.paper_id, sptr.topic_id, sptr.is_right, sptr.scoring, ptr.score,sptr.handlerIndex
- FROM student_paper_topic_rs_".$codeNow." sptr
- JOIN paper_topic_relation ptr ON (ptr.paper_id = sptr.paper_id AND ptr.topic_id = sptr.topic_id) where 1=1 ";
- //WHERE sptr.handlerIndex = '1'";
- }
- $sql.="AND sptr.paper_id IN (" . implode(',', $data['paperIds']) . ")";
- $query = $this->sConn->createCommand($sql)->queryAll();
- $class_topic_score = array();
- $topic_score_arr = array();
- if ($query) {
- $data['papers'][$v['paper_id']]['topics'] = array();
- foreach ($query as $k => $v) {
- if (!isset($data['papers'][$v['paper_id']]['topics'][$v['topic_id']])) {
- $data['papers'][$v['paper_id']]['topics'][$v['topic_id']] = array();
- $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['fullScore'] = $v['score'];
- $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['totalScore'] = 0;
- $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['avgScore'] = 0;
- $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['avgRate'] = 0;
- $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['numRight'] = 0;
- $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['numWrong'] = 0;
- $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['studentIds'] = array();
- $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['rateLess70'] = array();//得分率低于70%的,选择题错的
- $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['classRate'] = 0;
- }
- $topic_score_arr[$v['topic_id']] = $v['score'];
- //班级得分
- if (!isset($class_topic_score[$v['paper_id']])) {
- $class_topic_score[$v['paper_id']] = array();
- }
- if (!isset($class_topic_score[$v['paper_id']][$v['topic_id']])) {
- $class_topic_score[$v['paper_id']][$v['topic_id']] = array();
- }
- $class_topic_score[$v['paper_id']][$v['topic_id']][] = $v['scoring'];
- $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['totalScore'] += $v['scoring'];
- if ($v['is_right'] == 1) {
- $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['numRight'] ++;
- } else {
- if($v["handlerIndex"]==1) {
- $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['numWrong']++;
- }
- }
- if($v["handlerIndex"]==1) {
- $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['studentIds'][] = $v['student_id'];
- }
- if ($v['score'] && $v['scoring']/$v['score'] < 0.7 && $v["handlerIndex"]==1) {
- $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['rateLess70'][] = $v['student_id'];
- }
- }
- }
- unset($query);
- // 缺考人数
- if(empty($codeNow)){
- $query = $this->sConn->createCommand("
- SELECT paper_id, COUNT(student_id) AS absent_num
- FROM student_paper_relation
- WHERE is_feedback = '0' AND paper_id IN (" . implode(',', $data['paperIds']) . ")
- GROUP BY paper_id
- ")->queryAll();
- }else{
- $query = $this->sConn->createCommand("
- SELECT paper_id, COUNT(student_id) AS absent_num
- FROM student_paper_relation_".$codeNow."
- WHERE is_feedback = '0' AND paper_id IN (" . implode(',', $data['paperIds']) . ")
- GROUP BY paper_id
- ")->queryAll();
- }
- if ($query) {
- foreach ($query as $k => $v) {
- $data['papers'][$v['paper_id']]['absentNum'] = $v['absent_num'];
- }
- }
- unset($query);
- // 及格率
- if(empty($codeNow)){
- $query = $this->sConn->createCommand("
- SELECT paper_id, student_id, scoring
- FROM student_paper_relation
- WHERE is_feedback = '1' AND paper_id IN (" . implode(',', $data['paperIds']) . ")
- ")->queryAll();
- }else{
- $query = $this->sConn->createCommand("
- SELECT paper_id, student_id, scoring
- FROM student_paper_relation_".$codeNow."
- WHERE is_feedback = '1' AND paper_id IN (" . implode(',', $data['paperIds']) . ")
- ")->queryAll();
- }
- if ($query) {
- foreach ($query as $k => $v) {
- if (!isset($data['papers'][$exam['paper_id']]['passNum'])) {
- $data['papers'][$exam['paper_id']]['passNum'] = 0;
- $data['papers'][$exam['paper_id']]['passNum_90'] = 0;
- }
- if (isset($data['papers'][$exam['paper_id']]['fullScore']) && $data['papers'][$exam['paper_id']]['fullScore'] > 0) {
- if ($v['scoring'] / $data['papers'][$exam['paper_id']]['fullScore'] >= 0.6) {
- $data['papers'][$exam['paper_id']]['passNum'] ++;
- }
- if ($v['scoring'] / $data['papers'][$exam['paper_id']]['fullScore'] >= 0.9) {
- $data['papers'][$exam['paper_id']]['passNum_90'] ++;
- }
- }
- }
- unset($query);
- }
- foreach ($data['paperIds'] as $paperId) {
- if (!isset($data['papers'][$exam['paper_id']]['passRate'])) {
- $data['papers'][$exam['paper_id']]['passRate'] = 0;
- }
- if (isset($data['papers'][$v['paper_id']]['totalNum']) && $data['papers'][$v['paper_id']]['totalNum'] > 0 && isset($data['papers'][$exam['paper_id']]['passNum'])) {
- $data['papers'][$exam['paper_id']]['passRate'] = number_format($data['papers'][$exam['paper_id']]['passNum'] / $data['papers'][$v['paper_id']]['totalNum'], 4) * 100;
- }
- }
- $prevQuery = array();
- if ($data['prevPaperIds']) {
- // 上次考试排名
- if(empty($codePrev)){
- $prevQuery = $this->sConn->createCommand("
- SELECT paper_id, student_id, scoring
- FROM student_paper_relation
- WHERE paper_id IN (" . implode(',', $data['prevPaperIds']) . ") AND is_feedback = '1'
- ORDER BY paper_id ASC, scoring DESC
- ")->queryAll();
- }else{
- $prevQuery = $this->sConn->createCommand("
- SELECT paper_id, student_id, scoring
- FROM student_paper_relation_".$codePrev."
- WHERE paper_id IN (" . implode(',', $data['prevPaperIds']) . ") AND is_feedback = '1'
- ORDER BY paper_id ASC, scoring DESC
- ")->queryAll();
- }
- }
- if ($prevQuery) {
- foreach ($prevQuery as $k => $v) {
- if (isset($data['prevPapers'][$v['paper_id']])) {
- if (!isset($data['papers'][$data['prevPapers'][$v['paper_id']]]['prevRanks'])) {
- $data['papers'][$data['prevPapers'][$v['paper_id']]]['prevRanks'] = array();
- $data['papers'][$data['prevPapers'][$v['paper_id']]]['_prevRanks'] = array();
- $data['papers'][$data['prevPapers'][$v['paper_id']]]['_i'] = 0;
- $data['papers'][$data['prevPapers'][$v['paper_id']]]['_j'] = 0;
- }
- if (!isset($prevRank[$data['prevPapers'][$v['paper_id']]])) {
- $prevRank[$data['prevPapers'][$v['paper_id']]] = 0;
- }
- if ($data['papers'][$data['prevPapers'][$v['paper_id']]]['_i'] > 0) {
- if ($v['scoring'] == $data['papers'][$data['prevPapers'][$v['paper_id']]]['_prevRanks'][$data['papers'][$data['prevPapers'][$v['paper_id']]]['_i'] - 1][1]) {
- $data['papers'][$data['prevPapers'][$v['paper_id']]]['_j'] ++;
- $data['papers'][$data['prevPapers'][$v['paper_id']]]['_prevRanks'][] = array(
- $v['student_id'],
- $v['scoring'],
- $prevRank[$data['prevPapers'][$v['paper_id']]]
- );
- } else {
- $prevRank[$data['prevPapers'][$v['paper_id']]] ++;
- $prevRank[$data['prevPapers'][$v['paper_id']]]+= $data['papers'][$data['prevPapers'][$v['paper_id']]]['_j'];
- $data['papers'][$data['prevPapers'][$v['paper_id']]]['_j'] = 0;
- $data['papers'][$data['prevPapers'][$v['paper_id']]]['_prevRanks'][] = array(
- $v['student_id'],
- $v['scoring'],
- $prevRank[$data['prevPapers'][$v['paper_id']]]
- );
- }
- } else {
- $prevRank[$data['prevPapers'][$v['paper_id']]] ++;
- $prevRank[$data['prevPapers'][$v['paper_id']]]+= $data['papers'][$data['prevPapers'][$v['paper_id']]]['_j'];
- $data['papers'][$data['prevPapers'][$v['paper_id']]]['_j'] = 0;
- $data['papers'][$data['prevPapers'][$v['paper_id']]]['_prevRanks'][] = array(
- $v['student_id'],
- $v['scoring'],
- $prevRank[$data['prevPapers'][$v['paper_id']]]
- );
- }
- $data['papers'][$data['prevPapers'][$v['paper_id']]]['prevRanks'][$v['student_id']] = $prevRank[$data['prevPapers'][$v['paper_id']]];
- $data['papers'][$data['prevPapers'][$v['paper_id']]]['_i'] ++;
- }
- }
- unset($prevRank);
- }
- // 本次考试排名
- if(empty($codeNow)){
- $query = $this->sConn->createCommand("
- SELECT spr.paper_id, spr.student_id, si.realname, spr.scoring
- FROM student_paper_relation spr
- JOIN student_info si ON si.student_id = spr.student_id
- WHERE spr.paper_id IN (" . implode(',', $data['paperIds']) . ") AND spr.is_feedback = '1'
- ORDER BY spr.paper_id ASC, spr.scoring DESC
- ")->queryAll();
- }else{
- $query = $this->sConn->createCommand("
- SELECT spr.paper_id, spr.student_id, si.realname, spr.scoring
- FROM student_paper_relation_".$codeNow." spr
- JOIN student_info si ON si.student_id = spr.student_id
- WHERE spr.paper_id IN (" . implode(',', $data['paperIds']) . ") AND spr.is_feedback = '1'
- ORDER BY spr.paper_id ASC, spr.scoring DESC
- ")->queryAll();
- }
- $studentNames = array();
- if ($query) {
- foreach ($query as $k => $v) {
- if (!isset($data['papers'][$v['paper_id']]['ranks'])) {
- $data['papers'][$v['paper_id']]['ranks'] = array();
- $data['papers'][$v['paper_id']]['_ranks'] = array();
- $data['papers'][$v['paper_id']]['_i'] = 0;
- $data['papers'][$v['paper_id']]['_j'] = 0;
- }
- if (!isset($rank[$v['paper_id']])) {
- $rank[$v['paper_id']] = 0;
- }
- if ($data['papers'][$v['paper_id']]['_i'] > 0) {
- if ($v['scoring'] == $data['papers'][$v['paper_id']]['_ranks'][$data['papers'][$v['paper_id']]['_i'] - 1][1]) {
- $data['papers'][$v['paper_id']]['_j'] ++;
- $data['papers'][$v['paper_id']]['_ranks'][] = array(
- $v['student_id'],
- $v['scoring'],
- $rank[$v['paper_id']]
- );
- } else {
- $rank[$v['paper_id']] ++;
- $rank[$v['paper_id']]+= $data['papers'][$v['paper_id']]['_j'];
- $data['papers'][$v['paper_id']]['_j'] = 0;
- $data['papers'][$v['paper_id']]['_ranks'][] = array(
- $v['student_id'],
- $v['scoring'],
- $rank[$v['paper_id']]
- );
- }
- } else {
- $rank[$v['paper_id']] ++;
- $rank[$v['paper_id']]+= $data['papers'][$v['paper_id']]['_j'];
- $data['papers'][$v['paper_id']]['_j'] = 0;
- $data['papers'][$v['paper_id']]['_ranks'][] = array(
- $v['student_id'],
- $v['scoring'],
- $rank[$v['paper_id']]
- );
- }
- $data['papers'][$v['paper_id']]['ranks'][] = array(
- 'studentId' => $v['student_id'],
- 'realname' => $v['realname'],
- 'rank' => $rank[$v['paper_id']],
- );
- $data['papers'][$v['paper_id']]['_i'] ++;
- $studentNames[$v['student_id']] = $v['realname'];
- }
- unset($rank);
- }
- //班级得分率
- $class_topic_rate = array();
- if ($class_topic_score) {
- foreach ($class_topic_score as $_p_id => $t_id_scoring) {
- if (!isset($class_topic_rate[$_p_id])) {
- $class_topic_rate[$_p_id] = array();
- }
- foreach ($t_id_scoring as $_t_id => $_t_scoring) {
- if (isset($topic_score_arr[$_t_id]) && $topic_score_arr[$_t_id] > 0) {
- $class_topic_rate[$_p_id][$_t_id] = round(array_sum($_t_scoring)/($topic_score_arr[$_t_id]*count($_t_scoring)),2) * 100;
- }else{
- $class_topic_rate[$_p_id][$_t_id] = 0;
- }
- }
- }
- }
- unset($class_topic_score);
- //得分率低于70%的,选择题错的对应的学生名称
- if($studentNames && isset($data['papers']) && isset($data['papers'][$v['paper_id']]['topics'])){
- foreach ($data['papers'] as $pId => $_topics){
- foreach ($_topics['topics'] as $tId => $less70) {
- foreach ($less70['rateLess70'] as $lessk => $stuId) {
- if (isset($studentNames[$stuId])) {
- $data['papers'][$pId]['topics'][$tId]['rateLess70'][$lessk] = $studentNames[$stuId];
- }
- }
- $data['papers'][$pId]['topics'][$tId]['classRate'] = isset($class_topic_rate[$pId]) && isset($class_topic_rate[$pId][$tId])?$class_topic_rate[$pId][$tId]:0;
- }
- }
- }
- $data['studentNames'] = $studentNames;
- unset($studentNames);
- // 大幅进步、大幅度退步
- foreach ($data['papers'] as $key => $val) {
- if (isset($val['prevRanks']) && isset($val['ranks'])) {
- foreach ($val['ranks'] as $k => $v) {
- if (isset($val['prevRanks'][$v['studentId']])) {
- // 进步
- if (!isset($data['papers'][$key]['forwards'])) {
- $data['papers'][$key]['forwards'] = array();
- }
- if ($val['prevRanks'][$v['studentId']] - $v['rank'] > 0) {
- if (!isset($data['papers'][$key]['forwards'][$val['prevRanks'][$v['studentId']] - $v['rank']])) {
- $data['papers'][$key]['forwards'][$val['prevRanks'][$v['studentId']] - $v['rank']] = array();
- }
- $data['papers'][$key]['forwards'][$val['prevRanks'][$v['studentId']] - $v['rank']][] = array(
- 'studentId' => $v['studentId'],
- 'realname' => $v['realname'],
- 'rank' => $v['rank'],
- 'prevRank' => $val['prevRanks'][$v['studentId']]
- );
- }
- // 退步
- if (!isset($data['papers'][$key]['rewinds'])) {
- $data['papers'][$key]['rewinds'] = array();
- }
- if ($v['rank'] - $val['prevRanks'][$v['studentId']] > 0) {
- if (!isset($data['papers'][$key]['rewinds'][$v['rank'] - $val['prevRanks'][$v['studentId']]])) {
- $data['papers'][$key]['rewinds'][$v['rank'] - $val['prevRanks'][$v['studentId']]] = array();
- }
- $data['papers'][$key]['rewinds'][$v['rank'] - $val['prevRanks'][$v['studentId']]][] = array(
- 'studentId' => $v['studentId'],
- 'realname' => $v['realname'],
- 'rank' => $v['rank'],
- 'prevRank' => $val['prevRanks'][$v['studentId']]
- );
- }
- }
- }
- if (isset($data['papers'][$key]['forwards'])) {
- krsort($data['papers'][$key]['forwards'], SORT_NUMERIC);
- }
- if (isset($data['papers'][$key]['rewinds'])) {
- krsort($data['papers'][$key]['rewinds'], SORT_NUMERIC);
- }
- }
- if (isset($val['topics'])) {
- foreach ($val['topics'] as $k => $v) {
- if (count($v['studentIds']) > 0) {
- $data['papers'][$key]['topics'][$k]['avgScore'] = number_format($v['totalScore'] / count($v['studentIds']), 2);
- if (isset($data['papers'][$key]['topics'][$k]['fullScore']) && $data['papers'][$key]['topics'][$k]['fullScore'] > 0) {
- $data['papers'][$key]['topics'][$k]['avgRate'] = number_format($v['totalScore'] / (count($v['studentIds']) * $data['papers'][$key]['topics'][$k]['fullScore']), 4) * 100;
- }
- }
- }
- }
- }
- unset($query);
- // 考试情况分析
- if(empty($codeNow)){
- $query = $this->sConn->createCommand("
- SELECT e.exam_group_id, e.exam_id, sptr.paper_id, sptr.student_id, sptr.topic_id, sptr.type, sptr.is_right, sptr.scoring, ptr.topic_id,ptr.stem_id, ptr.no, ptr.`order`,ptr.score, ptr.method_ids, ptr.method_difficulty,sptr.answer
- ,sptr.handlerIndex
- FROM student_paper_topic_rs sptr
- JOIN student_paper_relation spr ON (spr.paper_id = sptr.paper_id AND spr.student_id = sptr.student_id)
- JOIN paper_topic_relation ptr ON (ptr.paper_id = sptr.paper_id AND ptr.topic_id = sptr.topic_id AND ptr.type = sptr.type)
- JOIN paper p ON p.paper_id = ptr.paper_id
- JOIN exam e ON e.exam_id = p.exam_id
- WHERE spr.is_feedback = '1' AND sptr.paper_id IN (" . implode(',', $data['paperIds']) . ")
- ORDER BY sptr.paper_id ASC, sptr.type ASC, ptr.order ASC, sptr.topic_id ASC, sptr.student_id ASC
- ")->queryAll();
- }else{
- $query = $this->sConn->createCommand("
- SELECT e.exam_group_id, e.exam_id, sptr.paper_id, sptr.student_id, sptr.topic_id, sptr.type, sptr.is_right, sptr.scoring, ptr.topic_id, ptr.stem_id,ptr.no, ptr.`order`,ptr.score, ptr.method_ids, ptr.method_difficulty,sptr.answer
- ,sptr.handlerIndex
- FROM student_paper_topic_rs_".$codeNow." sptr
- JOIN student_paper_relation_".$codeNow." spr ON (spr.paper_id = sptr.paper_id AND spr.student_id = sptr.student_id)
- JOIN paper_topic_relation ptr ON (ptr.paper_id = sptr.paper_id AND ptr.topic_id = sptr.topic_id AND ptr.type = sptr.type)
- JOIN paper p ON p.paper_id = ptr.paper_id
- JOIN exam e ON e.exam_id = p.exam_id
- WHERE spr.is_feedback = '1' AND sptr.paper_id IN (" . implode(',', $data['paperIds']) . ")
- ORDER BY sptr.paper_id ASC, sptr.type ASC, ptr.order ASC, sptr.topic_id ASC, sptr.student_id ASC
- ")->queryAll();
- }
- if ($query) {
- //转换试卷中每道题目的序号
- $paperNos = $this->transferOrders($data['paperIds'],$is_qxk);
- //计算出每道必做题 做了的人数
- foreach($query as $k => $v){
- if (!isset($data['papers'][$v['paper_id']]['doTopicNums'])) {//每道必做题 做了的人数
- $data['papers'][$v['paper_id']]['doTopicNums'] = array();
- }
- if (!isset($data['papers'][$v['paper_id']]['doTopicNums'][$v['topic_id']])) {
- $data['papers'][$v['paper_id']]['doTopicNums'][$v['topic_id']] = 0;
- }
- if ($v["handlerIndex"] ==1) {
- $data['papers'][$v['paper_id']]['doTopicNums'][$v['topic_id']] ++;
- }
- }
- foreach ($query as $k => $v) {
- if($v['stem_id']){
- $new_topic_id = (string)$v['stem_id'];
- }else{
- $new_topic_id = (string)$v['topic_id'];
- }
- //客观题答案明细
- if($v['type'] == 1 && !$score_type){//单选题
- if(!isset($data['answer_score_details'][$v['topic_id']])){
- $data['answer_score_details'][$v['topic_id']] = array();
- $data['answer_score_details'][$v['topic_id']]['answer'] = '';
- $data['answer_score_details'][$v['topic_id']]['option']['A'] = 0;
- $data['answer_score_details'][$v['topic_id']]['option']['B'] = 0;
- $data['answer_score_details'][$v['topic_id']]['option']['C'] = 0;
- $data['answer_score_details'][$v['topic_id']]['option']['D'] = 0;
- $data['answer_score_details'][$v['topic_id']]['order'] = $v['order'];
- }
- if(isset($data['answer_score_details'][$v['topic_id']]['option'][$v['answer']])){
- $data['answer_score_details'][$v['topic_id']]['option'][$v['answer']]++;
- }
- }
- //type=>3 全学科试卷 多选题
- if((in_array($v['type'],array(2,11)) || $is_qxk && $v['type']==3) && !$score_type ){//多选不定项
- $v_answer = str_replace(',','',$v['answer']);
- if(!isset($data['answer_score_details'][$v['topic_id']])){
- $data['answer_score_details'][$v['topic_id']] = array();
- $data['answer_score_details'][$v['topic_id']]['answer'] = '';
- $data['answer_score_details'][$v['topic_id']]['order'] = $v['order'];
- }
- if(isset($data['answer_score_details'][$v['topic_id']]['option'][$v_answer])){
- $data['answer_score_details'][$v['topic_id']]['option'][$v_answer]++;
- }else{
- $data['answer_score_details'][$v['topic_id']]['option'][$v_answer] = 1;
- }
- }
-
- if (!isset($data['papers'][$v['paper_id']]['errorNums'])) {
- $data['papers'][$v['paper_id']]['errorNums'] = array();
- }
- if (!isset($data['papers'][$v['paper_id']]['errorNums'][$v['no']])) {
- $data['papers'][$v['paper_id']]['errorNums'][$v['no']] = 0;
- }
- if ($v['is_right'] != 1 && $v["handlerIndex"] ==1) {
- $data['papers'][$v['paper_id']]['errorNums'][$v['no']] ++;
- }
- if (!in_array((string)$new_topic_id, $data['topicIds'],true)) {
- $data['topicIds'][] = $new_topic_id;
- }
- if (!in_array((string)$v['topic_id'], $data['noTopicIds'],true)) {
- $data['noTopicIds'][] = (string)$v['topic_id'];
- }
- if (!isset($data['papers'][$v['paper_id']]['topicIds'])) {
- $data['papers'][$v['paper_id']]['topicIds'] = array();
- }
- if (!isset($data['papers'][$v['paper_id']]['noTopicIds'])) {
- $data['papers'][$v['paper_id']]['noTopicIds'] = array();
- }
- if (!in_array($new_topic_id, $data['papers'][$v['paper_id']]['topicIds'],true)) {
- $data['papers'][$v['paper_id']]['topicIds'][] = $new_topic_id;
- }
- if (!in_array((string)$v['topic_id'], $data['papers'][$v['paper_id']]['noTopicIds'],true)) {
- $data['papers'][$v['paper_id']]['noTopicIds'][] = (string)$v['topic_id'];
- }
- if (!isset($data['papers'][$v['paper_id']]['topicNos'])) {
- $data['papers'][$v['paper_id']]['topicNos'] = array();
- }
- $data['papers'][$v['paper_id']]['topicNos'][$v['topic_id']] = $v['no'];
- //带选做题的新序号
- if (!isset($data['papers'][$v['paper_id']]['newTopicNos'])) {
- $data['papers'][$v['paper_id']]['newTopicNos'] = array();
- }
- $data['papers'][$v['paper_id']]['newTopicNos'][$v['topic_id']] = isset($paperNos[$v['paper_id']][$v['topic_id']])?$paperNos[$v['paper_id']][$v['topic_id']]:$v['no'];
- if (!isset($data['examGroups'][$v['exam_group_id']]['topicIds'])) {
- $data['examGroups'][$v['exam_group_id']]['topicIds'] = array();
- }
- if (!in_array($v['topic_id'], $data['examGroups'][$v['exam_group_id']]['topicIds'])) {
- $data['examGroups'][$v['exam_group_id']]['topicIds'][] = $v['topic_id'];
- }
- if (!isset($data['examGroups'][$v['exam_group_id']]['rules'])) {
- $data['examGroups'][$v['exam_group_id']]['rules'] = array();
- }
- $ruleMethodIds = $v['method_ids'];
- $ruleType =(in_array($v['type'], array(17, 27)) ? 7 : $v['type']);
- if($is_qxk && $v["method_ids"]){//如果是全学科的考试转变成老知识点
- $methodIds = explode(',', $v['method_ids']);
- $ruleMethodIds = array();
- foreach($methodIds as $methodId){
- if(isset($qxkKnowledge[$methodId])){
- $ruleMethodIds = array_merge($ruleMethodIds,$qxkKnowledge[$methodId]);
- }
- }
- $ruleMethodIds = empty($ruleMethodIds)?"":join(",",$ruleMethodIds);
- $ruleType = 8;
- }
- $data['examGroups'][$v['exam_group_id']]['rules'][$v['topic_id']] = array(
- 'num' => 1,
- 'difficulty' => $v['method_difficulty'],
- 'type' => $ruleType,
- 'inMethodIds' => $ruleMethodIds,
- 'eqMethodIds' => $ruleMethodIds,
- 'callback' => $v['topic_id'],
- );
- $no = $paperNos[$v['paper_id']][$v['topic_id']];
- if ($v['method_ids'] && $data['papers'][$v['paper_id']]['doTopicNums'][$v['topic_id']]) {
- $methodIds = explode(',', $v['method_ids']);
- foreach ($methodIds as $methodId) {
- if (!in_array($methodId, $data['methodIds'])) {
- $data['methodIds'][] = $methodId;
- }
- if (!isset($data['papers'][$v['paper_id']]['methodNos'])) {
- $data['papers'][$v['paper_id']]['methodNos'] = array();
- }
- if (!isset($data['papers'][$v['paper_id']]['methodNos'][$methodId])) {
- $data['papers'][$v['paper_id']]['methodNos'][$methodId] = array();
- }
- if (!in_array($no, $data['papers'][$v['paper_id']]['methodNos'][$methodId])) {
- $data['papers'][$v['paper_id']]['methodNos'][$methodId][] = $no;
- }
- if (!isset($data['papers'][$v['paper_id']]['methodErrorNums'])) {
- $data['papers'][$v['paper_id']]['methodErrorNums'] = array();
- }
- if (!isset($data['papers'][$v['paper_id']]['methodErrorNums'][$methodId])) {
- $data['papers'][$v['paper_id']]['methodErrorNums'][$methodId] = 0;
- }
- if ($v['is_right'] != 1 && $v['handlerIndex']==1) {
- $data['papers'][$v['paper_id']]['methodErrorNums'][$methodId] ++;
- }
- if (!isset($data['papers'][$v['paper_id']]['methodErrorStudents'])) {
- $data['papers'][$v['paper_id']]['methodErrorStudents'] = array();
- }
- if (!isset($data['papers'][$v['paper_id']]['methodErrorStudents'][$methodId])) {
- $data['papers'][$v['paper_id']]['methodErrorStudents'][$methodId] = array();
- }
- if ($v['is_right'] != 1) {
- if (!in_array($v['student_id'], $data['papers'][$v['paper_id']]['methodErrorStudents'][$methodId],true) && $v['handlerIndex']==1) {
- $data['papers'][$v['paper_id']]['methodErrorStudents'][$methodId][] = $v['student_id'];
- }
- }
- if (!isset($data['papers'][$v['paper_id']]['methodFullScores'])) {
- $data['papers'][$v['paper_id']]['methodFullScores'] = array();
- }
- if (!isset($data['papers'][$v['paper_id']]['methodFullScores'][$methodId])) {
- $data['papers'][$v['paper_id']]['methodFullScores'][$methodId] = 0;
- }
- $data['papers'][$v['paper_id']]['methodFullScores'][$methodId] += $v['score'];
- if (!isset($data['papers'][$v['paper_id']]['methodScores'])) {
- $data['papers'][$v['paper_id']]['methodScores'] = array();
- }
- if (!isset($data['papers'][$v['paper_id']]['methodScores'][$methodId])) {
- $data['papers'][$v['paper_id']]['methodScores'][$methodId] = 0;
- }
- $data['papers'][$v['paper_id']]['methodScores'][$methodId] += $v['scoring'];
- }
- }
- }
- foreach ($data['papers'] as $key => $val) {
- if (isset($val['errorNums'])) {
- //重置题号
- $i = 1;
- $newErrorNums = array();
- foreach($val['errorNums'] as $k => $v){
- $newErrorNums[$i] = $v;
- $i++;
- }
- if($newErrorNums){
- $val['errorNums'] = $newErrorNums;
- $data['papers'][$key]['errorNums'] = $newErrorNums;
- }
- foreach ($val['errorNums'] as $k => $v) {
- if (!isset($data['papers'][$key]['errorRates'])) {
- $data['papers'][$key]['errorRates'] = array();
- }
- if ($data['papers'][$key]['totalNum'] > 0) {
- $data['papers'][$key]['errorRates'][$k] = number_format($data['papers'][$key]['errorNums'][$k] / $data['papers'][$key]['totalNum'], 4) * 100;
- } else {
- $data['papers'][$key]['errorRates'][$k] = 0;
- }
- }
- }
- }
- }
- } else {
- echo "文件尚未生成\n";
- $error[] = $className."文件尚未生成";
- continue;
- }
- if ($data['wb_isp_version'] != 1 || $isFromPast) { //个性化版
- if (isset($data['examGroups']) && $data['examGroups'] && is_array($data['examGroups'])) {
- // 抽题
- foreach ($data['examGroups'] as $key => $val) {
- if($same_bs_data){
- $data['examGroups'][$key]['fcTopicIds'] = array();
- $data['examGroups'][$key]['fcCallbacks'] = array();
- foreach($same_bs_data as $sa_k=>$sa_v){
- $has_topic_gaokao[] = $sa_k;
- foreach($sa_v as $sa_v_topic){
- $has_topic_gaokao[] = $sa_v_topic;
- $data['examGroups'][$key]['fcTopicIds'][] = $sa_v_topic;
- $data['examGroups'][$key]['fcCallbacks'][$sa_k][] = $sa_v_topic;
- if (!in_array((string)$sa_v_topic, $data['fcTopicIds'])) {
- $data['fcTopicIds'][] = (string)$sa_v_topic;
- }
- }
- }
- }else{
- if($labelled_type == 2){//教师端标注抽题
- $data['examGroups'][$key]['fcTopicIds'] = array();
- $data['examGroups'][$key]['fcCallbacks'] = array();
- $sql = "select topic_id,relation_id from exam_topic_label where exam_group_id = '{$key}'";
- $etl_data = $this->sConn->createCommand($sql)->queryAll();
- if($etl_data){
- foreach($etl_data as $etl_data_v){
- if($etl_data_v['topic_id'] && $etl_data_v['relation_id']){
- $relation_topic_arr = explode(",",$etl_data_v['relation_id']);
- foreach($relation_topic_arr as $relation_topic_v){
- if (!in_array((string)$relation_topic_v, $data['fcTopicIds'])) {
- $data['fcTopicIds'][] = (string)$relation_topic_v;
- }
- $data['examGroups'][$key]['fcTopicIds'][] = $relation_topic_v;
- $data['examGroups'][$key]['fcCallbacks'][$etl_data_v['topic_id']][] = $relation_topic_v;
- $has_topic_gaokao[] = $relation_topic_v;
- }
- $has_topic_gaokao[] = $etl_data_v['topic_id'];
- }
- }
- }
- }else{
- if (isset($val['rules'])) {
- $fc = $this->apiPost('/isp/ai', array(
- 'schoolId' => $v_data['school_id'],
- 'rules' => $val['rules'],
- 'notInTopicIds' => $data['examGroups'][$key]['topicIds'],
- ));
- if ($fc && !isset($fc->error)) {
- $data['examGroups'][$key]['fcTopicIds'] = array();
- $data['examGroups'][$key]['fcCallbacks'] = array();
- foreach ($fc as $k => $v) {
- if (!in_array($v->id, $data['fcTopicIds'])) {
- $data['fcTopicIds'][] = $v->id;
- }
- $data['examGroups'][$key]['fcTopicIds'][] = $v->id;
- $data['examGroups'][$key]['fcCallbacks'][$v->callback][] = $v->id;
- $has_topic_gaokao[] = $v->id;
- $has_topic_gaokao[] = $v->callback;
- }
- }
- }
- }
- }
- }
- $topicDetails=array();
- $topicItems_1 = $this->apiPost('/topic/batchAll', array('topicIds' => array_merge(
- $data['topicIds'],
- (isset($data['fcTopicIds']) ? $data['fcTopicIds'] : array())
- )));
- if (isset($topicItems_1->error)) {
- $error[] = $className.$topicItems_1->error;
- } elseif (! $topicItems_1) {
- $error[] = $className.'Error in pumping system[2]';
- } else {
- foreach ($topicItems_1 as $topicItem) {
- $topicDetails[$topicItem->id] = (object)$topicItem;
- }
- }
- if ($topicDetails) {
- foreach ($topicDetails as $k => $v) {
- $v=(array)$v;
- $v['id'] = (string)$v['id'];
- $teacher_tips= isset($v['teacher_tips'])?$v['teacher_tips']:"";
- if(!$teacher_tips){
- $teacher_tips = $this->dealTeacherTips($v);
- }
- $v['teacher_tips'] = $this->topicProcess($teacher_tips);
- $v['parse_content'] = $this->topicProcess($v['parse_content']);
- if($v['type_id'] == 5){
- $v['title'] = preg_replace("/<img[^>]*[\s]+src[\s]*=[\s]*(([\'\"](\/images\/list_\d\.png)[\'\"])|(\/images\/list_\d\.png))[^>]*>/si", '__________', $v['title']);
- }
- $v['title'] = $this->topicProcess($v['title']);
- if(isset($v['items'][0])){
- $v['items'][0]=(array)$v['items'][0];
- $v['items'][0]['options']=(array)$v['items'][0]['options'];
- if (isset($v['items']) && isset($v['items'][0]) && isset($v['items'][0]['options'])) {
- foreach ($v['items'][0]['options'] as $key => $val) {
- $val=(array)$val;
- $v['items'][0]['options'][$key]=(array)$v['items'][0]['options'][$key];
- $v['items'][0]['options'][$key]['option_content'] = $this->topicProcess($val['option_content']);
- if(isset($data['answer_score_details'][$v['id']]) && $val['option_correct'] == 1){
- $data['answer_score_details'][$v['id']]['answer'] .= $this->numToLetter($key + 1);
- }
- }
- }
- }
- $data['topicDetails'][$v['id']] = $v;
- }
- unset($topicDetails);
- }
- }
- } else { //分层版
- //获取原题以及对应四个层次的提分题
- //$preparation_plan_id = $exam['preparation_plan_id'];
- if($data['level_rule'] == 1){
- $isDiffMin = $this->sConn->createCommand(" select template_id,level,topic_id,difficulty_degree from preparation_plan_topic where preparation_plan_id=" . $examId." and is_diff_min = 1")->queryAll();
- if($isDiffMin){
- $plan_topic_res = $isDiffMin;
- }else{
- $plan_topic_res = $this->sConn->createCommand(" select template_id,level,topic_id,difficulty_degree from preparation_plan_topic where preparation_plan_id=" . $examId)->queryAll();
- if($plan_topic_res){
- $topicsOrigin = array();
- $topicRelation = array();
- foreach($plan_topic_res as $k=>$v){
- $topicsOrigin[] = $v['template_id'];
- $topicRelation[$v['template_id']][] = $v;
- $has_topic_gaokao[] =$v['template_id'];
- $has_topic_gaokao[] =$v['topic_id'];
- }
- if($topicsOrigin){
- $topicsOrigin = array_unique($topicsOrigin);
- $topicDetails = $this->aipost('/topic/batchAll', array('topicIds' => $topicsOrigin));
- if (!$topicDetails) {
- echo "获取接口batchALL无数据!\n";
- $error[] = $className."无数据";
- continue;
- } elseif (isset($topicDetails['status']) && $topicDetails['status']==0) {
- echo $topicDetails['error'][0]."\n";
- $error[] =$className.$topicDetails['error'][0];
- continue;
- }
- $topicDiff = array();
- foreach($topicDetails as $k=>$v){
- if(isset($v['difficulty_degree'])){
- $diff = $v['difficulty_degree'];
- }elseif(isset($v['experience_degree'])){
- $diff = $v['experience_degree'];
- }else{
- $diff = 0;
- }
- $topicDiff[$v['id']] = $diff;
- }
- $new_plan_topic_res = array();
- foreach($topicDiff as $k=>$v){
- if(isset($topicRelation[$k])){
- $arr1 = array();
- $arr2 = array();
- foreach($topicRelation[$k] as $relation){
- $arr1[] = $relation['difficulty_degree'];
- }
- $x=$v;
- $count=count($arr1);
- for ($i=0; $i <$count ; $i++) {
- $arr2[]=abs($x-$arr1[$i]);
- }
- $min= min($arr2);
- for ($i=0; $i <$count ; $i++) {
- if ($min==$arr2[$i]) {
- $new_plan_topic_res[] = $topicRelation[$k][$i];
- break 1;
- }
- }
- }
- }
- }
- $plan_topic_res = $new_plan_topic_res;
- }
- }
- }else{
- $plan_topic_res = $this->sConn->createCommand(" select template_id,level,topic_id from preparation_plan_topic where preparation_plan_id=" . $examId)->queryAll();
- }
- if (!$plan_topic_res) {
- echo "文件尚未生成\n";
- $error[] = $className."文件尚未生成";
- continue;
- }
- $template_topic_arr = array();
- $isp_id_arr = array();
- foreach ($plan_topic_res as $v) {
- $template_id = $v['template_id'];
- $level = $v['level'];
- $topic_id = $v['topic_id'];
- if (!isset($template_topic_arr[$template_id])) {
- $template_topic_arr[$template_id] = array();
- }
- $template_topic_arr[$template_id][$level] = $topic_id;
- $isp_id_arr[] = $topic_id;
- }
- //试卷中校本题库题是哪些,云题库题是哪些
- $sch_id_arr = array(); //试卷中校本题库题是哪些
- $yun_id_arr = array();
- $sql = 'select topic_id,mode,type,no from paper_topic_relation ptr join paper p on p.paper_id = ptr.paper_id where p.exam_id=' . $examId;
- $paper_topic_res = $this->sConn->createCommand($sql)->queryAll();
- if (!$paper_topic_res) {
- echo "文件尚未生成\n";
- $error[] = $className."文件尚未生成";
- continue;
- }
- $topic_no_arr = $this->getTopicNoByPaper($paper_topic_res, $exam['tpl_index']); //获取每道题在试卷中的序号,如 21A,21B
- foreach ($paper_topic_res as $v) {
- $v['mode'] == 1 && $sch_id_arr[] = $v['topic_id'];
- $v['mode'] == 0 && $yun_id_arr [] = $v['topic_id'];
- }
- $isp_id_arr = array_merge($isp_id_arr, $yun_id_arr);
- //获取所有以上题目的详情,以供显示到教师讲案中
- $topic_detail_arr = $this->paperTopicDetail($isp_id_arr, $sch_id_arr, $examId,'分层提分题');
- if (!$topic_detail_arr) {
- echo "获取不到试卷题目内容\n";
- $error[] = $className."获取不到试卷题目内容";
- continue;
- }
- foreach($topic_detail_arr as $k_topic=>$v_topic){
- if(isset($data['answer_score_details'][(string)$k_topic])){
- $data['answer_score_details'][(string)$k_topic]['answer'] = isset($v_topic['answer_format'])?$v_topic['answer_format']:'';
- }
- }
- $diff_id_arr = array_diff($isp_id_arr + $sch_id_arr, array_keys($topic_detail_arr));
- if ($diff_id_arr) {
- //todo 发送消息到补提
- echo "请等待题库老师补题!\n";
- $error[] = $className."请等待题库老师补题!";
- continue;
- } else {
- $data['template_topic_arr'] = $template_topic_arr;
- $data['topic_details'] = $topic_detail_arr;
- $data['topic_no_arr'] = $topic_no_arr;
- unset($template_topic_arr);
- unset($topic_detail_arr);
- }
- }
- // 获取考点名称
- if (isset($data['methodIds']) && $data['methodIds']) {
- if($is_qxk){
- $methods = $this->apiPost('/all_knowledge/knowledge_name', array('knowledgeIds' => $data['methodIds']));
- if ($methods && isset($methods->data) && $methods->data) {
- foreach ($methods->data as $k => $v) {
- $data['methodNames'][$k] = $v;
- }
- unset($methods);
- }
- }else{
- $methods = $this->apiPost('/special/methods', array('methodIds' => $data['methodIds']));
- if ($methods) {
- foreach ($methods as $k => $v) {
- $data['methodNames'][$v->method_id] = $v->method_name;
- }
- unset($methods);
- }
- }
- }
- if (isset($data['examGroupIds']) && $data['examGroupIds'] && is_array($data['examGroupIds'])) {
- // $this->sConn->active = false;
- // $this->sConn = $this->getDbConnection();
- $this->sConn->active = false;
- $sConn = $this->getDbConnection($result_one["database_host"],$result_one["database_name"], $result_one["database_user"],$result_one["database_password"]);
- $this->sConn = $sConn;
- $query = array();
- if(empty($codeNow)){
- $sql = "SELECT sptr.student_id, sptr.paper_id, sptr.topic_id, sptr.is_right, sptr.scoring, e.exam_group_id,sptr.handlerIndex
- FROM student_paper_topic_rs sptr
- JOIN paper p ON p.paper_id = sptr.paper_id
- JOIN exam e ON e.exam_id = p.exam_id
- WHERE e.exam_group_id IN (" . implode(',', $data['examGroupIds']) . ")";
- }else{
- $sql = "SELECT sptr.student_id, sptr.paper_id, sptr.topic_id, sptr.is_right, sptr.scoring, e.exam_group_id,sptr.handlerIndex
- FROM student_paper_topic_rs_".$codeNow." sptr
- JOIN paper p ON p.paper_id = sptr.paper_id
- JOIN exam e ON e.exam_id = p.exam_id
- WHERE e.exam_group_id IN (" . implode(',', $data['examGroupIds']) . ") ";
- }
- $sptrData = $this->sConn->createCommand($sql)->queryAll();
- if($sptrData){
- $paperTopic = array();
- $paperIds = array();
- foreach($sptrData as $k=>$v){
- if(!in_array($v['paper_id'], $paperIds)){
- $paperIds[] = $v['paper_id'];
- }
- }
- if($paperIds){
- $sql = "select score,paper_id,topic_id from paper_topic_relation where paper_id in (" . implode(',', $paperIds) . ")";
- $ptrData = $this->sConn->createCommand($sql)->queryAll();
- if($ptrData){
- foreach($ptrData as $k=>$v){
- $paperTopic[$v['paper_id']][$v['topic_id']] = $v['score'];
- }
- unset($ptrData);
- }
- if($paperTopic){
- foreach($sptrData as $k=>$v){
- if(isset($paperTopic[$v['paper_id']]) && isset($paperTopic[$v['paper_id']][$v['topic_id']])){
- $sptrData[$k]['score'] = $paperTopic[$v['paper_id']][$v['topic_id']];
- }
- }
- $query = $sptrData;
- }
- }
- unset($sptrData);
- }
- /////////newending
- ///
- $grade_topic_score = array();
- if ($query) {
- foreach ($query as $k => $v) {
- if (!isset($data['examGroups'][$v['exam_group_id']]['topics'])) {
- $data['examGroups'][$v['exam_group_id']]['topics'] = array();
- }
- if (!isset($data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']])) {
- $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']] = array();
- $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['fullScore'] = $v['score'];
- $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['totalScore'] = 0;
- $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['avgScore'] = 0;
- $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['avgRate'] = 0;
- $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['numRight'] = 0;
- $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['numWrong'] = 0;
- $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['studentIds'] = array();
- }
- $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['totalScore'] += $v['scoring'];
- if ($v['is_right'] == 1) {
- $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['numRight'] ++;
- } else {
- if($v["handlerIndex"]==1) {//必做题
- $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['numWrong']++;
- }
- }
- if($v["handlerIndex"]==1) {//必做题
- $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['studentIds'][] = $v['student_id'];
- }
- //年级得分
- if (!isset($grade_topic_score[$v['topic_id']])) {
- $grade_topic_score[$v['topic_id']] = array();
- }
- $grade_topic_score[$v['topic_id']][] = $v['scoring'];
- }
- foreach ($data['examGroups'] as $key => $val) {
- if (isset($val['topics'])) {
- foreach ($val['topics'] as $k => $v) {
- if (count($v['studentIds']) > 0) {
- $data['examGroups'][$key]['topics'][$k]['avgScore'] = number_format($v['totalScore'] / count($v['studentIds']), 2);
- if (isset($data['examGroups'][$key]['topics'][$k]['fullScore']) && $data['examGroups'][$key]['topics'][$k]['fullScore'] > 0) {
- $data['examGroups'][$key]['topics'][$k]['avgRate'] = number_format($v['totalScore'] / (count($v['studentIds']) * $data['examGroups'][$key]['topics'][$k]['fullScore']), 4) * 100;
- }
- }
- }
- }
- }
- }
- }
- $grade_topic_rate = array();
- if ($grade_topic_score) {
- foreach ($grade_topic_score as $_t_id => $_t_scoring) {
- if (isset($topic_score_arr[$_t_id]) && $topic_score_arr[$_t_id] > 0) {
- $grade_topic_rate[$_t_id] = round(array_sum($_t_scoring)/($topic_score_arr[$_t_id]*count($_t_scoring)),2) * 100;
- }else{
- $grade_topic_rate[$_t_id] = 0;
- }
- }
- }
- unset($grade_topic_score);
- unset($topic_score_arr);
- //高考真题
- $data['gaokao_topic'] = array();
- if($grade == 3){
- $gaokao_topic = array();
- $sql = "select topic_id from gaokao_academicr_topic where class_id ='{$classId}'";
- $gaokao_data = $this->sConn->createCommand($sql)->queryAll();
- if($gaokao_data){
- foreach($gaokao_data as $gao){
- $gaokao_topic[] = $gao['topic_id'];
- }
- }
- if($gen_origin_methods){
- $weak_methodids = array_keys($gen_origin_methods);
- }else{
- $weak_methodids = array();
- }
- if($paper_method_ids){
- $paper_methodids = explode(",",$paper_method_ids);
- }else{
- $paper_methodids = array();
- }
- if($has_topic_gaokao){
- $has_topic = $has_topic_gaokao;
- }else{
- $has_topic = array();
- }
- $gaokao_topic = $this->acadGaokao($examId,$classId,$has_topic,$weak_methodids,$paper_methodids);
- if($gaokao_topic){
- $topicBatchs = $this->aipost('topic/batchall', array('topicIds' => $gaokao_topic));
- if ($topicBatchs && !isset($topicBatchs->error)) {
- $data['gaokao_topic'] = $this->formatDetails($topicBatchs);
- }
- }
- }
- //整理客观题明细数据
- if($data['answer_score_details']){
- $new_answer_score_details = array();
- $a = 0;
- foreach($data['answer_score_details'] as $k=>$v){
- if(isset($v['option']) && $v['option']){
- foreach($v['option'] as $option_type=>$option_count){
- $new_answer_score_details[$a]['id'] = $k;
- $new_answer_score_details[$a]['order'] = $v['order'];
- $new_answer_score_details[$a]['answer'] = $v['answer']?$v['answer']:'';
- $new_answer_score_details[$a]['option'] = $option_type;
- $new_answer_score_details[$a]['option_count'] = $option_count;
- $a++;
- }
- }
- }
- $data['answer_score_details'] = $new_answer_score_details;
- }
- // $this->sConn->active = false; // 关闭连接 close();
- if (isset($data['papers']) && $data['papers'] && is_array($data['papers'])) {
- // 渲染
- foreach ($data['papers'] as $key => $val) {
- if (!isset($val['examId']) || !$val['examId'])
- continue;
- if (!isset($val['examGroupId']) || !$val['examGroupId'])
- continue;
- // $classname = ClassModel::model()->getClassName($classId);
- $data = array_merge($val, array(
- 'methodNames' => (isset($data['methodNames']) ? $data['methodNames'] : array()),
- 'topicDetails' => (isset($data['topicDetails']) ? $data['topicDetails'] : array()),
- 'groupTopics' => (isset($data['examGroups']) && isset($data['examGroups'][$val['examGroupId']]) && isset($data['examGroups'][$val['examGroupId']]['topics']) ? $data['examGroups'][$val['examGroupId']]['topics'] : array()),
- 'fcCallbacks' => (isset($data['examGroups']) && isset($data['examGroups'][$val['examGroupId']]) && isset($data['examGroups'][$val['examGroupId']]['fcCallbacks']) ? $data['examGroups'][$val['examGroupId']]['fcCallbacks'] : array()),
- 'wb_isp_version' => isset($data['wb_isp_version']) ? $data['wb_isp_version'] : 0,
- 'template_topic_arr' => isset($data['template_topic_arr']) ? $data['template_topic_arr'] : array(),
- 'topic_details' => isset($data['topic_details']) ? $data['topic_details'] : array(),
- 'topic_no_arr' => isset($data['topic_no_arr']) ? $data['topic_no_arr']: array(),
- 'level_rule' => isset($data['level_rule']) ? $data['level_rule'] : 0,
- 'gradeTopicRate' => $grade_topic_rate,
- 'studentNames'=>isset($data['studentNames']) ? $data['studentNames'] : array(),
- 'excellent_solution'=>isset($data['excellent_solution']) ? $data['excellent_solution'] : array(),
- 'gen_topics'=>isset($data['gen_topics']) ? $data['gen_topics'] : array(),
- 'gen_topics_detail'=>isset($data['gen_topics_detail']) ? $data['gen_topics_detail'] : array(),
- 'gen_topics_msg'=>isset($data['gen_topics_msg']) ? $data['gen_topics_msg'] : array(),
- 'answer_score_details'=>isset($data['answer_score_details']) ? $data['answer_score_details'] : array(),
- 'gen_origin_methods'=>isset($data['gen_origin_methods'])?$data['gen_origin_methods']:'',
- 'gaokao_topic'=>isset($data['gaokao_topic'])?$data['gaokao_topic']:array(),
- 'setting_arr'=>isset($setting_arr)?$setting_arr:array(),
- 'grade_topic_data'=>isset($data['grade_topic_data']) ? $data['grade_topic_data'] : array(),
- 'is_qxk'=>$is_qxk,
- )
- );
- $data['className'] = $className;
- // $html = $this->renderPartial("academicr", $data, true);
- $data['imgUrl'] = $file_html_url;
- //是否是精准学习宝学校
- $http = http('customer/precision-learning-school/check/'.$v_data['school_id'], 'GET', $authUsername);
- $response = formatResponse($http);
- $data['isPrecise'] = isset($response['data']) ? $response['data'] : 0;
-
- //教师姓名
- $sql = "select t.teacher_id,t.teacher_name from teacher t join teacher_class_relation tcr on t.teacher_id = tcr.teacher_id where tcr.class_id = '{$classId}' and tcr.semester_id = '{$semesterId}' and t.subjects=3";
- $teacher_msg = $this->sConn->createCommand($sql)->queryRow();
- if($teacher_msg){
- $data['teacherName'] = $teacher_msg['teacher_name'];
- }
- $html = $this->viewRender("academicr_1", $data, true);
- //unset($data);
- $htmlpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/academicr/'; //存放生成的HTML路径
- $pdfpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/academicr/' . $v_data['school_id'] . "/"; //存放生成的PDF路径
- $pdfurl = '/upload/tmpDir/academicr/' . $v_data['school_id'] . "/";
- if (!is_dir($htmlpath)) {
- if (!mkdir($htmlpath, 0777, true)) {
- exit('Create directory fail: ' . $htmlpath);
- }else{
- exec('chown -R www:www '.$htmlpath);
- }
- }if (!is_dir($pdfpath)) {
- if (!mkdir($pdfpath, 0777, true)) {
- exit('Create directory fail1: ' . $pdfpath);
- }else{
- exec('chown -R www:www '.$pdfpath);
- }
- }
- $htmlpath.=$examId . ".html";
- echo "开始写入html\n";
- $f = fopen($htmlpath, "w");
- fwrite($f, $html);
- fclose($f);
- echo "写入html结束\n";
- $htmlurl = '/upload/tmpDir/academicr/' . $examId . ".html"; //访问HTML的路径
- if (Yii::app()->basePath == "C:\wamp\www\zsyas2\protected") {//本地的basePath
- $locale='en_US.UTF-8'; // 或 $locale='zh_CN.UTF-8';
- setlocale(LC_ALL,$locale);
- putenv('LC_ALL='.$locale);
- $htmlurl = "http://zsyte.dev.xueping.com/html/%E9%A6%96%E9%A1%B5.html";
- // $pdffname = str_replace(".", "。", $exam_info['class_name'] . "-" . $exam_info['exam_name']);
- // $pdffname = str_replace(" ", "", $pdffname) . ".pdf";
- // $pdffname=iconv("UTF-8", "GBK",$pdffname);
- $pdffname=$classId."-".$examId.".pdf";
- $pdfpath = $pdfpath . $pdffname;
- $pdfurl = $pdfurl . $pdffname;
- $header_str = $school_name.$exam_info['class_name']."+++".$exam_info['exam_name']."+++"."时间:".date("Y-m-d",time());
- $commond = Yii::app()->params['phantomjs_server'] . " "
- . Yii::app()->basePath . '/../js/html2pdf_math.js' . " "
- . " {$htmlurl}"
- . " {$pdfpath}"
- . " 176mm*250mm '{$header_str}'";
- } else {
- $locale='en_US.UTF-8'; // 或 $locale='zh_CN.UTF-8';
- setlocale(LC_ALL,$locale);
- putenv('LC_ALL='.$locale);
- // echo Yii::app()->params['phantomjs'];exit;
- $htmlurl = $file_html_url . $htmlurl;
- // $htmlurl = "http://" . $_SERVER['SERVER_NAME'] . $htmlurl;
- // $pdffname = str_replace(".", "。", $exam_info['class_name'] . "-" . $exam_info['exam_name']);
- // $pdffname = str_replace(" ", "", $pdffname) . ".pdf";
- // $pdffname=iconv("UTF-8", "GBK",$pdffname);
- $pdffname=$classId."-".$examId.".pdf";
- $pdfpath = $pdfpath . $pdffname;
- $pdfurl = $pdfurl . $pdffname;
- $header_str = $school_name.$exam_info['class_name']."+++".$exam_info['exam_name']."+++"."时间:".date("Y-m-d",time());
- $commond = Yii::app()->params['phantomjs_server'] . " "
- . Yii::app()->basePath . '/../js/html2pdf_math.js' . " "
- . " {$htmlurl}"
- . " {$pdfpath}"
- . " 176mm*250mm '{$header_str}'";
- }
- echo "开始转pdf\n";
- exec($commond, $res, $code);
- echo "转pdf结束\n";
- $ucloud = new Qcloud();
- //上传html
- $rehtml = $examId.".html";
- $rehtmlname = 'zsyas2/math_academicr/'.$v_data['school_id'].'/'. date('Y') . '/' . date('m') . '/' . date('d').'/'. uniqid() . '.' . $rehtml;
- $uploadHtmlInfo = $ucloud->putFile($rehtmlname, $htmlpath);
- if($uploadHtmlInfo['status'] == 0){
- // $html_url = "http://" . $_SERVER['SERVER_NAME'].$htmlurl;
- $html_url = $file_html_url.$htmlurl;
- }else{
- $html_url = $uploadHtmlInfo['url'];
- @unlink($htmlpath);
- }
- $this->sConn->createCommand()->update("exam", array("academicr_html_path"=>$html_url), "exam_id = '{$examId}'");
- if(isset($res[0])){
- if (strpos($res[0], 'succeed') !== false) {//命令返回成功
- if ($this->file_exists($pdfpath)) {
- // $pdfurl=iconv("GBK", "UTF-8",$pdfurl);
- $repdf = $examId.".pdf";
- $rename = 'zsyas2/math_academicr/'.$v_data['school_id'].'/'. date('Y') . '/' . date('m') . '/' . date('d').'/'. uniqid() . '.' . $repdf;
- echo "开始上传ucloud\n";
- $uploadInfo = $ucloud->putFile($rename, $pdfpath);
- echo "上传ucloud结束\n";
- //@unlink($pdfpath);
- if ($uploadInfo['status'] == 0) {
- echo "PDF文件上传失败\n";
- echo $uploadInfo['msg']."\n";
- $error[] = $className."PDF文件上传失败";
- }else{
- $this->sConn->active = false;
- $sConn = $this->getDbConnection($result_one["database_host"],$result_one["database_name"], $result_one["database_user"],$result_one["database_password"]);
- $this->sConn = $sConn;
- $this->sConn->createCommand()->update("exam", array("academicr_html_path"=>$html_url,"academicr_pdf_path" => $uploadInfo['url'], "academicr_pdf_time" => time(), "is_academicr_pdf" => 1), "exam_id = '{$examId}'");
- $pdfArr[] = $pdfpath;
- $pdfNames[] = $className;
- // @unlink($htmlpath);
- }
- //echo $htmlpath;exit;
- // @unlink($htmlpath);
- } else {
- $this->sConn->createCommand()->update("exam", array("academicr_pdf_path" => "", "academicr_pdf_time" => 0, "is_academicr_pdf" => 0), "exam_id = '{$examId}'");
- // @unlink($htmlpath);
- echo "PDF文件未找到\n";
- $error[] = $className."PDF文件未找到";
- }
- } else {
- // @unlink($htmlpath);
- echo "PDF创建失败1\n";
- $error[] = $className."PDF创建失败1";
- }
- }else{
- // Curl::post(Yii::app()->params['handle_log_api'], array(
- // "exam_group_id" => (string)$val['examGroupId'],
- // "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'=>array("examId"=>$examId,"pdf"=>array("commond"=>$commond,"res"=>$res,"code"=>$code),"htmlurl"=>$htmlurl))),
- //
- // ));
- echo "PDF创建失败2!\n";
- $error[] = $className."PDF创建失败2!";
- }
- }
- } else {
- echo "渲染失败!\n";
- $error[] = $className."渲染失败!";
- // throw new CException("系统错误");
- }
- }else{
- $pdfArr[] = $pdfpath;
- $pdfNames[] = $className;
- }
- }
- }
- // var_dump($pdfArr);
- foreach($pdfArr as $k=>$v){
- if(strpos($v,'http') !== false){
- $new_dir_url = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/academicr_batch/'.$v_data['exam_group_id']."/".$v_data['id']."/";
- if (!is_dir($new_dir_url)) {
- if (!mkdir($new_dir_url, 0777, true)) {
- echo 'Create directory fail1: ' . $new_dir_url. "\n";
- }else{
- exec('chown -R www:www '.$new_dir_url);
- }
- }
- $new_file_url = $this->downImgRar($v,$new_dir_url,$k);
- $pdfArr[$k] = $new_file_url;
- // echo $new_file_url;exit;
- }
-
- }
- //var_dump($pdfArr);exit;
- $this->conn->active = false;
- $conn = $this->getDbConnection(Yii::app()->params["default_server"]['addr'], Yii::app()->params["default_db"]['name'], Yii::app()->params["default_server"]['username'], Yii::app()->params["default_server"]['password']);
- $this->conn = $conn;
- if($pdfArr){
- echo "开始压缩文件\n";
- if($pdfArr){
- echo $examName.'pdf生成成功!'. "\n";
- // $report_name = $class_name.$year."年度报告.zip";
- $filepath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/academicr_batch/'.$v_data['exam_group_id']."/".$v_data['id']."/"; //存放生成的PDF路径
- if (!is_dir($filepath)) {
- if (!mkdir($filepath, 0777, true)) {
- echo 'Create directory fail1: ' . $filepath. "\n";
- }else{
- exec('chown -R www:www '.$filepath);
- }
- }
- $examName = iconv("UTF-8","GBK//IGNORE",$examName);
- $filename = dirname(dirname(dirname(__FILE__))).'/upload/tmpDir/academicr_batch/'.$v_data['exam_group_id']."/".$v_data['id']."/".$v_data['exam_group_id'].".zip"; //最终生成的文件名(含路径)
- $zip = new ZipArchive();//使用本类,linux需开启zlib,windows需取消php_zip.dll前的注释
- if ($zip->open($filename, ZIPARCHIVE::OVERWRITE)!==TRUE) {
- echo $examName.'zip生成失败!'. "\n";
- }else{
- foreach ($pdfArr as $k=>$val) {
- // $pdfNames[$k] = iconv("UTF-8","GBK//IGNORE",$pdfNames[$k]);
- $pdfname = '-'.$pdfNames[$k].'-教师讲案';
- $pdfname = iconv("UTF-8","GBK//IGNORE",$pdfname);
- $res=$zip->addFile($val,$examName.$pdfname.'.pdf');
- //@unlink($pdfArr[$k]);
- }
- $zip->close();//关闭
- foreach($pdfArr as $k=>$val){
- @unlink($val);
- }
- //生成完成
- // $filename = addslashes($filename);
- $time = time();
- $filename = $this->characet($filename);
- $ucloud = new Qcloud();
- $filename = iconv("UTF-8","GBK//IGNORE",$filename);
- $examName = $this->characet($examName);
- $meg = $ucloud->putFile('zsyas2/academicr_batch/'.$v_data['exam_group_id'].'/'.$v_data['id'].'/'.$examName.'.zip',$filename);
- if($meg['status'] == 0){
- $error[] = $className.$meg['msg'];
- }else{
- $url = $meg['url'];
- $url = str_replace("%2F","/",$url);
- $sql = "update download_table_setting set status = 2,zip_url = '{$url}',update_time = {$time} where id = {$v_data['id']}";
- $this->conn->createCommand($sql)->execute();
- $is_success = 1;
- echo $examName.'zip生成成功!'. "\n";
- }
- @unlink($filename);
- // if($pdfArr){
- // $sql = "update download_table_setting set status = 2,zip_url = '{$url}',update_time = {$time} where id = {$v_data['id']}";
- // $this->conn->createCommand($sql)->execute();
- // echo $examName.'zip生成成功!'. "\n";
- // }
- }
- }else{
- echo 'pdf生成失败!'. "\n";
- }
- }
- }else{
- echo '连接学校ID'.$v_data['school_id']."失败\n";
- continue;
- }
- }else{
- echo '暂无学校ID'.$v_data['school_id']."的信息\n";
- continue;
- }
- $this->sConn->active = false;
- }
- if(!$is_success){
- if($error){
- $time = time();
- $sql = "update download_table_setting set error_msg='".implode(",",$error)."',update_time = {$time},status=3 where id = {$v_data['id']}";
- $this->conn->createCommand($sql)->execute();
- echo $examName.'zip生成失败!'. "\n";
- }else{
- $time = time();
- $sql = "update download_table_setting set update_time = {$time},status=3 where id = {$v_data['id']}";
- $this->conn->createCommand($sql)->execute();
- echo $examName.'zip生成失败!'. "\n";
- }
- }else{
- if($error){
- $time = time();
- $sql = "update download_table_setting set error_msg='".implode(",",$error)."',update_time = {$time} where id = {$v_data['id']}";
- $this->conn->createCommand($sql)->execute();
- }
- }
- // $this->conn->active = false;
- }
- }catch(Exception $e){
- $sql = "update download_table_setting set status=3,error_msg='系统异常' where id = {$v_data['id']}";
- $this->conn->createCommand($sql)->execute();
- echo $e->getMessage();
- }
- }
- }else{
- echo "暂无要生成的数据\n";
- }
- $this->conn->active = false;
- }else{
- echo "连接业务库失败\n";
- }
- }
-
-
- function characet($data){
- if( !empty($data) ){
- $fileType = mb_detect_encoding($data , array('UTF-8','GBK','LATIN1','BIG5')) ;
- if( $fileType != 'UTF-8'){
- $data = mb_convert_encoding($data ,'utf-8' , $fileType);
- }
- }
- return $data;
- }
- public function apiPost($path, $arr, $type = 0)
- {
- $ch = @curl_init();
- $result = FALSE;
- if ($ch) {
- $data = json_encode($arr);
- $url = Yii::app()->params['api'][$type]['prefix'] . $path;
- $username = Yii::app()->params['api'][$type]['username'];
- $password = Yii::app()->params['api'][$type]['password'];
- // Digest认证
- curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
- curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);
- // 不输出头部
- curl_setopt($ch, CURLOPT_HEADER, 0);
- // curl_exec 获取到的内容不直接输出, 而是返回
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- // 请求重启路由器的地址 传参 进行重启
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_USERAGENT, 'Api Client/1.0.0 (chengfei@liancaitech.com)');
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
- 'Content-Type: application/json',
- 'Content-Length: ' . strlen($data),
- ));
- if (!curl_errno($ch)) {
- $result = json_decode(curl_exec($ch));
- }
- // 释放资源
- curl_close($ch);
- }
- return $result;
- }
- public function aipost($url, $array = array(), $timeout = 5, $type = 0)
- {
- $url = Yii::app()->params['api'][$type]['prefix'] . $url;
- $username = Yii::app()->params['api'][$type]['username'];
- $password = Yii::app()->params['api'][$type]['password'];
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
- curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
- curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);
- if ($array) {
- $array = http_build_query($array);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $array);
- }
- //curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
- $data = curl_exec($ch);
- if (!curl_errno($ch)) {
- $result = json_decode($data, 1);
- return $result;
- }
- curl_close($ch);
- return false;
- }
- private function check_zip($file_path) {
- if (substr($file_path, strlen($file_path) - 4, 4) == ".zip") {
- if (file_exists($file_path)) {
- return true;
- }
- }
- return false;
- }
- /**
- * 获取接口数据
- * @param $url
- * @param $method
- * @param array $params
- * @return array
- */
- private function getHttp($url,$method,$params = array()){
- $res = http($url, $method, $this->authUsername, $params);
- $res = $this->handleRes($res);
- return $res;
- }
- /**
- * 处理接口返回的数据
- * @param $res
- * @return array
- */
- public function handleRes($res){
- $result = array(
- 'status' => 0,
- 'data' => array(),
- 'msg' => '暂无数据',
- );
- if($res){
- $res = json_decode($res,true);
- if(isset($res['errCode']) && $res['errCode'] == '00'){
- $result['status'] = 1;
- $result['data'] = isset($res['data'])?$res['data']:array();
- $result['msg'] = $res['errMsg'];
- }else{
- if(isset($res['errMsg'])){
- $result['msg'] = $res['errMsg'];
- }
- }
- }
- unset($res);
- return $result;
- }
-
-
- function file_exists($url)
- {
- $ch = curl_init();
- $timeout = 10;
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HEADER, 1);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
- $contents = curl_exec($ch);
- if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == 404) {
- return false;
- }
- return true;
- // $ch = curl_init();
- // curl_setopt ($ch, CURLOPT_URL, $url);
- // //不下载
- // curl_setopt($ch, CURLOPT_NOBODY, 1);
- // //设置超时
- // curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 3);
- // curl_setopt($ch, CURLOPT_TIMEOUT, 3);
- // //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- // curl_exec($ch);
- // $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- // if($http_code == 200) {
- // return true;
- // }
- // return false;
- }
-
-
- public function viewRender($viewName, $data)
- {
- extract($data, EXTR_PREFIX_SAME,'data');
- ob_start();
- ob_implicit_flush(0);
- require(dirname(dirname(dirname(__FILE__))).'/protected/views/export/'.$viewName . '.php');
- return ob_get_clean();
- }
-
- public function getDbConnection($database_host,$database_name,$database_user,$database_password)
- {
- if($database_host && $database_name && $database_user && $database_password){
- $myDbDsn = 'mysql:host=' . $database_host . ';dbname=' . $database_name;
- $my_connection = new CDbConnection($myDbDsn, $database_user, $database_password);
- $my_connection->emulatePrepare = true;
- $my_connection->enableProfiling = true;
- $my_connection->enableParamLogging = true;
- $myDbDsn = null;
- return $my_connection;
- }else{
- return null;
- }
- }
- private function img_process($img)
- {
- $widthArr = array();
- $heightArr = array();
- $width = '';
- $height = '';
-
- if (preg_match('/[\s\'"]width\s*:\s*(\d+\.*\d*)\s*([a-zA-Z]+)*/si',$img,$widthArr)) {
- $width = $this->length_process($widthArr);
- } else {
- if (preg_match('/[\s\'"]width\s*=\s*[\'"]\s*(\d+\.*\d*)\s*([a-zA-Z]+)*;?[\'"]/si',$img,$widthArr)) {
- $width = $this->length_process($widthArr);
- }
- }
- if ($width) {
- $width = "width=".$width;
- }
-
- if (preg_match('/[\s\'"]height\s*:\s*(\d+\.*\d*)\s*([a-zA-Z]+)*/si',$img,$heightArr)) {
- $height = $this->length_process($heightArr);
- } else {
- if (preg_match('/[\s\'"]height\s*=\s*[\'"]\s*(\d+\.*\d*)\s*([a-zA-Z]+)*;?[\'"]/si',$img,$heightArr)) {
- $height = $this->length_process($heightArr);
- }
- }
- if ($height) {
- $height = "height=".$height;
- }
-
- $return_img = preg_replace('/<img[^>]*[\s]+(src[\s]*=[\s]*(([\"]([^\"]*)[\"])|([\']([^\']*)[\'])|([^\s]*)))([^>]*>)/si',"<img ".$width." ".$height." $1 />",$img);
- return $return_img;
- }
-
- private function length_process($length_arr){
- $length = 0.6*$length_arr[1];
- $unit_keys = array_keys($this->units);
- if (isset($length_arr[2])) {
- //将直接连接单位改为 单位换算
- if(in_array($length_arr[2],$unit_keys)){
- $length = $length*$this->units[$length_arr[2]];
- }else {
- $length .= $length_arr[2];
- }
- }
- return $length;
- }
-
- public function getCodeByExamId($examId){
- $code = 0;
- $sql = "select s.status,s.refer_code from exam e join semester s on e.semester_id = s.semester_id where e.exam_id = '{$examId}'";
- $data_sem = $this->sConn->createCommand($sql)->queryRow();
- if($data_sem && $data_sem['status'] != 1){
- $code = $data_sem['refer_code']?$data_sem['refer_code']:0;
- }
- return $code;
- }
- private function check_pdf($pdf_path) {
- if (substr($pdf_path, strlen($pdf_path) - 4, 4) == ".pdf") {
- if (file_exists($pdf_path)) {
- return true;
- }
- }
- return false;
- }
- function get_version($class_id)
- {
- if($class_id){
- $sql = 'select show_level,pcr.set_type from product_class_relation pcr join class c on pcr.class_id=c.class_id join product_setting ps on pcr.ps_id=ps.ps_id where c.class_id='.$class_id;
- $product_res = $this->sConn->createCommand($sql)->queryRow();
- if (!$product_res) { //没有找到班级与设置的关系表
- $sql = 'select wb_isp_version from class where class_id='.$class_id;
- $res = $this->sConn->createCommand($sql)->queryRow();
- return $res['wb_isp_version'];
- } else {
- if ($product_res['set_type'] == 1) { //如果是错题本,还是找以前的配置
- $sql = 'select wb_isp_version from class where class_id='.$class_id;
- $res = $this->sConn->createCommand($sql)->queryRow();
- return $res['wb_isp_version'];
- } else{
- return $product_res['show_level'];
- }
- }
- }
- return 0;
- }
- function get_level_rule($class_id)
- {
- if($class_id){
- $sql = 'select level_rule,pcr.set_type from product_class_relation pcr join class c on pcr.class_id=c.class_id join product_setting ps on pcr.ps_id=ps.ps_id where c.class_id='.$class_id;
- $product_res = $this->sConn->createCommand($sql)->queryRow();
- if (!$product_res) { //没有找到班级与设置的关系表
- return 0;
- } else {
- return $product_res['level_rule'];
- }
- }
- return 0;
- }
- function transferOrders($paperIds,$is_qxk=0)
- {
- $sql = 'select paper_id,topic_id,type,`order`,`stem_id` from paper_topic_relation where paper_id in ('.implode(',',$paperIds).') order by paper_id, type asc,`order` asc';
- $paper_topcic_relation_res = $this->sConn->createCommand($sql)->queryAll();
- $sql = 'select tpl_index,tpl_data,paper_id from exam e join paper p on e.exam_id = p.exam_id where p.paper_id in ('.implode(',',$paperIds).')' ;
- $tpl_index_res = $this->sConn->createCommand($sql)->queryAll();
- $tpl_index_arr = array();
- $changeDoToicNo = $tpl_data_arr = array();
- foreach ($tpl_index_res as $v) {
- $tpl_index_arr[$v['paper_id']] = $v['tpl_index'];
- if($v['tpl_data']){
- $v['tpl_data'] = preg_replace('/:\s*(-?\d{15,})/', ': "$1"', $v['tpl_data']);//把15位的int转成string
- $tplData = json_decode($v['tpl_data'],true);
- if($tplData){
- $tplstatus = 0;
- if(isset($tplData['tplstatus'])){
- $tpl_data_arr[$v['paper_id']] = $tplData['tplstatus'];
- }else{
- $tpl_data_arr[$v['paper_id']] = 0;
- }
- }
- }
- //选做题题号
- if (isset($tplData['new_items']) && $tplData['new_items']) {
- $new_items = array_values($tplData['new_items']);
- foreach ($new_items as $key => &$item) {
- if (isset($item['sameAliasNo']) && $item['sameAliasNo']>0) {
- $no =$item['alias'];
- $item['topicId'] = (string)$item['topicId'];
- $changeDoToicNo[$v['paper_id']]["list"][$item['topicId']]["sameAliasNo"] = $item['sameAliasNo'];//选做题组id
- $changeDoToicNo[$v['paper_id']]["list"][$item['topicId']]["smTopicLen"] = $item['smTopicLen'];//选做题组必做数量
- $changeDoToicNo[$v['paper_id']]["list"][$item['topicId']]["no"] = $no;//题号
- $changeDoToicNo[$v['paper_id']]["list"][$item['topicId']]["topicId"] = $item['topicId'];//题目id
- $changeDoToicNo[$v['paper_id']]["gather"][$item['sameAliasNo']][]=$item['topicId'];
- }
- }
- }
- }
- $paper_topcic_relation_arr = array();
- foreach ( $paper_topcic_relation_res as $v) {
- $paper_id = $v['paper_id'];
- $type = $v['type'];
- $order = $v['order'];
- $topic_id = $v['topic_id'];
- $stem_id = (string)$v['stem_id'];
- if (!isset($paper_topcic_relation_arr[$paper_id])) {
- $paper_topcic_relation_arr[$paper_id] = array();
- }
- $paper_topcic_relation_arr[$paper_id][] = array(
- 'type' => $type,
- 'order' => $order,
- 'topic_id'=>$topic_id,
- 'stem_id'=>$stem_id
- );
- }
- $paper_topic_no_arr = array();
- foreach ($paper_topcic_relation_arr as $paper_id => $paper_topic_relation) {
- $tpl_index = $tpl_index_arr[$paper_id];
- $tplstatus = isset($tpl_data_arr[$paper_id])?$tpl_data_arr[$paper_id]:0;
- $change_do_toicno = isset($changeDoToicNo[$paper_id])?$changeDoToicNo[$paper_id]:array();
- $paper_topic_no_arr[$paper_id] =$this->topic_number($paper_topic_relation,$tpl_index,$tplstatus,$is_qxk,$change_do_toicno);
- }
- return $paper_topic_no_arr;
- }
- function topic_number($paper_topcic_relation_arr, $tpl_index,$tplstatus,$is_qxk=0,$change_do_toicno=array())
- {
- $topic_no_arr = array(); //每道题的序号
- if($is_qxk){
- $_order = 1;
- $small_no = 1;
- $temp_stem_arr = array();
- foreach($paper_topcic_relation_arr as $v){
- if(isset($v['stem_id']) && $v['stem_id']){
- $temp_stem_arr[$v['stem_id']][] = $v['topic_id'];
- }
- }
- foreach ($paper_topcic_relation_arr as $v) {
- if(!isset($temp_stem_arr[$v['stem_id']]) || count($temp_stem_arr[$v['stem_id']]) == 1){
- if(!empty($change_do_toicno["list"]) && isset($change_do_toicno["list"][$v['topic_id']]) &&
- count($change_do_toicno["gather"][$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]])>1) {//判断是否选做题
- if (isset($change_no_arr[$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]])) {
- $change_no = $change_no_arr[$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]];
- } else {
- $change_no = 65;//从A开始
- }
- $topic_no_arr[$v['topic_id']] = $_order . chr($change_no);
- $change_no_arr[$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]] = $change_no +1;
- }else{
- $topic_no_arr[$v['topic_id']] = $_order;
- $_order++;
- }
- $small_no = 1;
- }else{
- if(!empty($change_do_toicno["list"]) && isset($change_do_toicno["list"][$v['topic_id']]) &&
- count($change_do_toicno["gather"][$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]])>1) {//判断是否选做题
- if(isset($change_no_arr[$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]])){
- $change_no = $change_no_arr[$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]];
- }else{
- $change_no = 65;//从A开始
- }
- $_order = $_order . chr($change_no);
- }
- $topic_no_arr[$v['topic_id']] = $_order.'('.$small_no.')';
- if($small_no == count($temp_stem_arr[$v['stem_id']])){
- $small_no = 1;
- $_order++;
- }
- $small_no++;
- }
- }
- }else if ($tpl_index == 10 || $tpl_index == 1010 || $tplstatus == 3 || $tplstatus == 4) { //10,1010 表示江苏那个有a,b,c,d选做题的模板,编号不能按表里的编号来
- $prefix_no = 0;
- $num = 0;
- $index_arr = array('A','B','C','D','E');
- $_order = 0;
- foreach($paper_topcic_relation_arr as $v) {
- if (!$prefix_no && $v['type'] == 17) {
- $_order += 1; //序号加1
- $prefix_no = $_order;
- $topic_no_arr[$v['topic_id']] = $prefix_no.'A';
- } elseif ($prefix_no && $v['type'] == 17) {
- $num += 1;
- $topic_no_arr[$v['topic_id']] = $prefix_no.$index_arr[$num];
- }
- if ($v['type'] == 27) {
- $prefix_no += 1;
- $topic_no_arr[$v['topic_id']] = $prefix_no;
- }
- if ($v['type'] != 17 && $v['type'] != 27){
- $_order += 1;
- $topic_no_arr[$v['topic_id']] = $_order;
- }
- }
- } else { //其他模板都是根据order就行
- $_order = 0;
- foreach ($paper_topcic_relation_arr as $v) {
- if(!empty($change_do_toicno["list"]) && isset($change_do_toicno["list"][$v['topic_id']]) &&
- count($change_do_toicno["gather"][$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]])>1) {//判断是否选做题
- if (isset($change_no_arr[$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]])) {
- $change_no = $change_no_arr[$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]];
- } else {
- $change_no = 65;//从A开始
- $_order += 1;
- }
- $topic_no_arr[$v['topic_id']] = $_order . chr($change_no);
- $change_no_arr[$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]] = $change_no + 1;
- }else{
- $_order += 1;
- $topic_no_arr[$v['topic_id']] = $_order;
- }
- }
- }
- return $topic_no_arr;
- }
-
- private function topicProcess($html) {
- if (preg_match_all('/(<img[^>]*[\s]+)((src)[\s]*=[\s]*(([\"]([^\"]*)[\"])|([\']([^\']*)[\'])|([^\s]*)))([^>]*>)/si', $html, $arr)) {
- foreach ($arr[0] as $v) {
- $process_str = $this->img_process($v);
- ;
- $html = str_replace($v, $process_str, $html);
- }
- }
- $html = preg_replace('/style\s*=\s*(([\"]([^\"]*)[\"])|([\']([^\']*)[\']))/si', '', $html);
- $html = preg_replace('/<p\s*>/', '', $html);
- $html = preg_replace('/<\/p>/', '', $html);
- $html = preg_replace('/<br\/*>/', '', $html);
- $html = preg_replace('/<big\s*>/', '', $html);
- $html = preg_replace('/<\/big>/', '', $html);
- $html = str_replace(" ", '', $html);
-
- //将图片地址改成二进制地址
- return $html;
- if(preg_match_all("/http:\/\/zxhx[\s\S]*?png/i",$html,$matches)){
- $need_replace = array();
- foreach($matches[0] as $v){
- //$image_info = getimagesize($v);
- $er = 'data:image/png;base64,' . chunk_split(base64_encode(file_get_contents($v)));
- $need_replace[] = array(
- "origin_url" => $v,
- "after_url" => $er
- );
- }
- unset($matches);
- if($need_replace){
- foreach($need_replace as $v){
- $html = str_replace($v["origin_url"],$v["after_url"],$html);
- }
- unset($need_replace);
- }
- }
- return $html;
- }
-
- private function getTopicNoByPaper($paper_topcic_relation_arr, $tpl_index)
- {
- $topic_no_arr = array(); //每道题的序号
- if ($tpl_index == 10 || $tpl_index == 1010) { //10,1010 表示江苏那个有a,b,c,d选做题的模板,编号不能按表里的编号来
- $prefix_no = 0;
- $num = 0;
- $index_arr = array('A','B','C','D','E');
- foreach($paper_topcic_relation_arr as $v) {
- if (!$prefix_no && $v['type'] == 17) {
- $prefix_no = $v['no'];
- $topic_no_arr[$v['topic_id']] = $prefix_no.'A';
- } elseif ($prefix_no && $v['type'] == 17) {
- $num += 1;
- $topic_no_arr[$v['topic_id']] = $prefix_no.$index_arr[$num];
- }
- if ($v['type'] == 27) {
- $prefix_no += 1;
- $topic_no_arr[$v['topic_id']] = $prefix_no;
- }
- if ($v['type'] != 17 && $v['type'] != 27){
- $topic_no_arr[$v['topic_id']] = $v['no'];
- }
- }
- } else {
- foreach ($paper_topcic_relation_arr as $v) {
- $topic_no_arr[$v['topic_id']] = $v['no'];
- }
- }
- return $topic_no_arr;
- }
-
- private function paperTopicDetail($yun_id_arr, $sch_id_arr, $exam_id, $typestr) {
- try {
- $all_id_arr = array_merge($yun_id_arr,$sch_id_arr);
- if (!$all_id_arr ) {
- return false;
- }
- $data = array();
- $total_count = count($all_id_arr);
- $page_size = 100;
- $page = ceil($total_count/$page_size);
- for ($i = 0; $i<$page; $i++) {
- $offset = $i * $page_size;
- $id_arr = array_slice($all_id_arr,$offset, $page_size);
- $topicBatchs = $this->apiPost('topic/batchall', array('topicIds' => $id_arr));
- if (!$topicBatchs) {
- throw new Exception('获取接口topic/batchALL数据时无任何返回,type is '.$typestr.' ,exam_id is ('.$exam_id.')');
- }if(isset($topicBatchs->status) && $topicBatchs->status == 0 ){
- throw new Exception($topicBatchs->error[0]);
- } else{
- $data += $this->formatDetails($topicBatchs);
- }
- }
- return $data;
- } catch (Exception $e) {
- return false;
- }
- }
- public function formatDetails($topicBatches) {
- $optionIndex = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K');
- $topicDetails = array();
- foreach ($topicBatches AS $ke=>$topic) {
- if(!isset($topic["teacher_tips"]) || !$topic["teacher_tips"]){
- $topicBatches[$ke]["teacher_tips"] = $this->dealTeacherTips($topic);
- }
- $topic = (object) $topic;
- $topic->id = (string)$topic->id;
- $type = $topic->type_id;
- 6 == $type && $type = 5; //6表示多空题,多空题也是5
- $topicDetails[$topic->id] = array();
- $topicDetails[$topic->id]['type'] = $type;
- $topicDetails[$topic->id]['methods'] = ''; //考点
- $topicDetails[$topic->id]['method_id_arr'] = ''; //考点id数组
- $topicDetails[$topic->id]['kps'] = ''; //知识点
- $topicDetails[$topic->id]['queBody'] = $this->topicProcess($topic->title); //题目详情
- $topicDetails[$topic->id]['options'] = '';
- $topicDetails[$topic->id]['parse_video_qrcode'] = isset($topic->parse_video_qrcode) ? $topic->parse_video_qrcode : '';
- $topicDetails[$topic->id]['answer'] = ''; //每题的正确答案
- $topicDetails[$topic->id]['analysis'] = $this->topicProcess($topic->parse_content); //答题解析
- $topicDetails[$topic->id]['teacher_tips'] = $this->topicProcess($topic->teacher_tips); //名师点评
- $topicDetails[$topic->id]['difficulty_degree'] = isset($topic->difficulty_degree) ? $topic->difficulty_degree : null;
- $topicDetails[$topic->id]['difficulty'] = $topic->difficulty;
- $topicDetails[$topic->id]['type_name'] = $topic->type_name;
- $topicDetails[$topic->id]['source'] = $topic->source;
- $_methods = array();
- $_method_id_arr = array();
- if ($topic->specials) {
- foreach ($topic->specials AS $_method) {
- $_method = (object) $_method;
- if ($_method->method_name) {
- $_methods[] = $_method->method_name;
- }
- if (isset($_method->method_id)) {
- $_method_id_arr[] = $_method->method_id;
- }
- }
- $topicDetails[$topic->id]['methods'] = implode('|', array_unique($_methods)); //考点
- $topicDetails[$topic->id]['method_id_arr'] = $_method_id_arr;
- }
- $_kps = array();
- if (isset($topic->kps) && $topic->kps) {
- foreach ($topic->kps as $_kp) {
- $_kp = (object) $_kp;
- if ($_kp->kp_name) {
- $_kps[$_kp->kp_id] = $_kp->kp_name;
- }
- }
- $topicDetails[$topic->id]['kps'] = $_kps; //考点
- }
- if ($topic->type_id == 1 || $topic->type_id == 2) { //选择题有选项
- if ($topic->items) {
- if (isset($topic->items[0])) {
- $topic->items[0] = (object) $topic->items[0];
- if (isset($topic->items[0]->options)) {
- $options = $topic->items[0]->options;
- if ($options) {
- $_tmp_options = array();
- $anwer_str = "";
- foreach ($options AS $_optionIndex => $_option) {
- $_option = (object) $_option;
- $_tmp_options[$_optionIndex] = $this->topicProcess($_option->option_content);
- if ($_option->option_correct) {
- if($anwer_str == ""){
- $anwer_str = $this->topicProcess($optionIndex[$_optionIndex]);
- // $topicDetails[$topic->id]['answer'] = $this->topicProcess($optionIndex[$_optionIndex]);
- }else{
- $anwer_str .= "、".$this->topicProcess($optionIndex[$_optionIndex]);
- }
- }
- }
- $topicDetails[$topic->id]['answer'] = $anwer_str;
- $topicDetails[$topic->id]['answer_format'] = str_replace('、', '', $anwer_str);
- $_list_type = (int) $topic->items[0]->list_type;
- $topicDetails[$topic->id]['options'] = $this->option_process($_tmp_options, $_list_type);
- }
- }
- }
- }
- } else {
- if ($topic->items) {
- if (isset($topic->items[0])) {
- $topic->items[0] = (object) $topic->items[0];
- if (isset($topic->items[0]->options)) {
- $options = $topic->items[0]->options;
- if ($options) {
- $_answer = '';
- foreach ($options as $v) {
- $_option = (object) $v;
- if (trim($_answer) != '') {
- $_answer .= ' ; ';
- }
- $_answer .= $_option->option_content;
- }
- $topicDetails[$topic->id]['answer'] = $this->topicProcess($_answer);
- }
- }
- }
- }
- }
- }
- return $topicDetails;
- }
- private function option_process($options, $list_type) {
- $option_index = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
- if ($list_type == 0) { //纵向排列,即1行1个
- $option_str = "";
- foreach ($options as $key => $option) {
- $option_str.="<li class='fl lis-one'>$option_index[$key].$option</li>";
- }
- } elseif ($list_type == 1) { //横向排列,即1行4个
- $option_str = "";
- foreach ($options as $key => $option) {
- $option_str.="<li class='fl lis-four'>$option_index[$key].$option</li>";
- }
- } elseif ($list_type == 2) { //1行2个
- $option_str = "";
- foreach ($options as $key => $option) {
- if ($key % 2 == 0) {
- $option1 = $options[$key];
- $option_str2 = "<li class='fl lis-two'>$option_index[$key].$option1</li>";
- $key1 = $key + 1;
- if (isset($options[$key1])) {
- $option2 = $options[$key1];
- $option_str2.="<li class='fl lis-two'>$option_index[$key1].$option2</li>";
- }
- $option_str.=$option_str2;
- } else {
- continue;
- }
- }
- }
- return $option_str;
- }
- public function numToUpper($number)
- {
- $number = substr($number, 0, 2);
- $arr = array('零', '一', '二', '三', '四', '五', '六', '七', '八', '九');
- if (strlen($number) == 1) {
- $result = $arr[$number];
- } else {
- if ($number == 10) {
- $result = '十';
- } else {
- if ($number < 20) {
- $result = '十';
- } else {
- $result = $arr[substr($number, 0, 1)] .'十';
- }
-
- if (substr($number, 1, 1) != '0') {
- $result .= $arr[substr($number, 1, 1)];
- }
- }
- }
-
- return $result;
- }
-
- public function numToLetter($number)
- {
- $letters = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
- $number = (int)$number;
- $result = '';
-
- if ($number >= 1 AND $number <= 26) {
- $result = $letters[$number - 1];
- }
-
- return $result;
- }
- //远程路径,名称,文件后缀
- function downImgRar($url,$rename,$name){
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
- $rawdata=curl_exec ($ch);
- curl_close ($ch);
- // 使用中文文件名需要转码
- $fp = fopen($rename.$name.".pdf",'w');
- fwrite($fp, $rawdata);
- fclose($fp);
- // 返回路径
- return $rename.$name.".pdf";
- }
-
- /**
- * 教师讲案高考真题
- * @exam_id 考试ID
- * @class_id 班级ID
- * @has_topic 教师讲案其他题集合
- * @weak_methodids 共性题考点
- * @paper_methodids 试卷考点
- */
- function acadGaokao($exam_id,$class_id,$has_topic,$weak_methodids,$paper_methodids){
- //最终抽出来的题
- $final_topic = array();
-
- if(!$weak_methodids){
- return $final_topic;
- }else{
- $topic_data = $this->aipost('/relation_math/true_topic', array('methodIds' => $weak_methodids));
- if($topic_data && isset($topic_data['data']) && $topic_data['data']){
- $topic_pool = $topic_data['data'];
- }else{
- return $final_topic;
- }
- }
-
-
- //step1 过滤已经存在的题
- if($has_topic){
- foreach($topic_pool as $k=>$v){
- if(in_array($k,$has_topic)){
- unset($topic_pool[$k]);
- }
- }
- }
- //step2 过滤超纲的题
- if($paper_methodids){
- foreach($topic_pool as $k=>$v){
- foreach($v as $method){
- if(!in_array($method,$paper_methodids)){
- unset($topic_pool[$k]);
- continue;
- }
- }
- }
- }
- //step3 优先抽全部薄弱考点的题,如果题不够,逐一减少薄弱考点,直到抽到2题为止 $weak_methodids(薄弱考点)
- if($topic_pool){
- //整理数据
- $topic_methods_count = array();//题目对应薄弱考点数量
- $count_to_topic = array();//薄弱考点数量对应题目
- foreach($topic_pool as $k=>$v){
- foreach($v as $method){
- if(in_array($method,$weak_methodids)){
- if(!isset($topic_methods_count[$k])){
- $topic_methods_count[$k] = 1;
- }else{
- $topic_methods_count[$k] ++;
- }
- }
- }
- }
- if($topic_methods_count){
- foreach($topic_methods_count as $k=>$v){
- for($a=1;$a<=$v;$a++){
- if(!isset($count_to_topic[$a])){
- $count_to_topic[$a] = array();
- }
- $count_to_topic[$a][] = $k;
- }
- }
- }
- if($count_to_topic){
- krsort($count_to_topic);//根据薄弱考点数量倒序
- foreach($count_to_topic as $k=>$v){
-
- foreach($v as $topic_id){
- if(count($final_topic) > 1){
- break;
- }
- if(!in_array($topic_id,$final_topic)){
- $final_topic[] = $topic_id;
- }
- }
- }
- }
- }
- //过滤完没题就随机抽两题
- if(!$final_topic || count($final_topic) < 2){
- $topic_keys = array_keys($topic_pool);
- shuffle($topic_keys);
- foreach($topic_keys as $k=>$v){
- if(count($final_topic) > 1){
- break;
- }
- if(!in_array($v,$final_topic)){
- $final_topic[] = $v;
- }
- }
- }
-
- //插入数据
- if($final_topic){
- $delSql = "delete from gaokao_academicr_topic where exam_id = '".$exam_id."'";
- $insertSql="insert into gaokao_academicr_topic (`exam_id`,`class_id`,`topic_id`,`create_time`) values";
- $insertSqlStr = "";
- foreach($final_topic as $k=>$v){
- $insertSqlStr.="('".$exam_id."','".$class_id."','".$v."','".time()."'),";
- }
- $insertSql .= substr($insertSqlStr, 0, -1);
- $this->sConn->createCommand($delSql)->execute();
- $this->sConn->createCommand($insertSql)->execute();
- }
- return $final_topic;
- }
-
- /**
- * 获取订单
- */
- function getOrderStu($eid, $cid, $typeVal,$relateStudentRes,$semesterId, $grade,$schoolId,$coachName)
- {
- $data = array();
- $sql = "select semester_id,refer_code from semester where semester_id='{$semesterId}'";
- $code = $this->sConn->createCommand($sql)->queryRow();
- $sql = "select subject_id,create_time from exam where exam_id = '{$eid}'";
- $examInfo = $this->sConn->createCommand($sql)->queryRow();
- $sql = "select add_time from class_exam_printer where exam_id = '{$eid}' and class_id = '{$cid}' and type=0";
- $print_time = $this->sConn->createCommand($sql)->queryRow();
- if($print_time && $print_time['add_time']){
- $exam_time = $print_time['add_time'];
- }else{
- $exam_time = $examInfo['create_time'];
- }
- $intarr=array(
- "schoolId"=>$schoolId,
- "clazzId"=>$cid,
- "semester"=>$code['refer_code'],
- "grade"=>$grade,
- "examTime"=>$exam_time,
- "students"=>array(),
- "classify"=>$typeVal,
- );
-
- $intarr['subject']=$examInfo['subject_id'];
- if(in_array($intarr['subject'],array(3,6,51))){
- $intarr['subject']=3;
- }
- foreach($relateStudentRes as $key => $val){
- $intarr['students'][] = $val['student_id'];
- }
- $basic = imsBasicAuth($schoolId.'_'.$coachName,Yii::app()->params["zsy_api_key"]);
- $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr),$basic));
- if(!$rs){
- //Yii::app()->jump->error("接口错误");
- return false;
- }
- if($rs->errCode!="00"){
- //Yii::app()->jump->error($rs->errMsg);
- //exit();
- return false;
- }
- if(!empty($rs->data)){
- foreach($rs->data as $v){
- $data['limitstu'][$v]=$v;
- }
- }else{
- $data['limitstu']=-1;
- }
- return $data;
- }
-
- /**
- * 获取班级设置
- */
- function getClassSet($classId,$semesterId){
- $is_set = 0;
- $temp_swich = 3;
- $temp_bate = 0;
- $switch_arr = array(3=>0,4=>1);
-
- $sql = "select switch from producut_set_edition";
- $switch_data = $this->sConn->createCommand($sql)->queryRow();
- if($switch_data && $switch_data['switch'] && in_array($switch_data['switch'],array(3,4))){
- $temp_swich = $switch_data['switch'];
- $temp_bate = $switch_arr[$temp_swich];
- }
-
- if($classId && $semesterId){
- $sql = "select wrong_book,isp,wb_isp from product_class_set where class_id = '{$classId}' and semester_id='{$semesterId}' and subject_id =3 and is_beta={$temp_bate}";
- $res = $this->sConn->createCommand($sql)->queryAll();
- if($res){
- foreach($res as $res_k=>$res_v){
- $setting_arr = array();
- $setting_arr[1] = $res_v['wrong_book'];
- $setting_arr[2] = $res_v['isp'];
- $setting_arr[3] = $res_v['wb_isp'];
- foreach($setting_arr as $k=>$v){
- $sql = "select config_text from product_template where template_id = '{$v}'";
- $data = $this->sConn->createCommand($sql)->queryRow();
- if($data){
- $json_data = $data['config_text'];
- $json_data_arr = json_decode($json_data,true);
- if(isset($json_data_arr['studentLevelDivide']) && isset($json_data_arr['studentLevelDivide']['isPushSameTrain']) && $json_data_arr['studentLevelDivide']['isPushSameTrain']){
- $is_set = 1;
- break 2;
- }
- }
- }
- }
-
- }else{
- $sql = "select template_id,config_text from product_template where subject_id=3 and is_default=1 and target_type=1 and is_beta={$temp_bate}";
- $data = $this->sConn->createCommand($sql)->queryAll();
- if($data){
- foreach($data as $k=>$v){
- $json_data = $v['config_text'];
- $json_data_arr = json_decode($json_data,true);
- if(isset($json_data_arr['studentLevelDivide']) && isset($json_data_arr['studentLevelDivide']['isPushSameTrain']) && $json_data_arr['studentLevelDivide']['isPushSameTrain']){
- $is_set = 1;
- break;
- }
- }
- }
- }
-
- }
- return $is_set;
- }
- /**获取名师指点信息
- * @param $topicInfo
- * @return mixed|string
- */
- public function dealTeacherTips($topicInfo){
- if(isset($topicInfo["teacher_tips"]) && $topicInfo["teacher_tips"]){//如果有的话直接返回
- return $topicInfo["teacher_tips"];
- }
- //兼容全学科题目
- if(!isset($topicInfo["topic_type_config"]) || empty($topicInfo["topic_type_config"]) || !isset($topicInfo["affiliate"])|| empty($topicInfo["affiliate"])){
- return "";
- }
- $topicTypeConfig = $topicInfo["topic_type_config"];
- if(is_object($topicTypeConfig)){
- $topicTypeConfig = json_decode(json_encode($topicTypeConfig),true);
- }
- //$topicTypeConfig = json_decode($topicInfo["topic_type_config"],true);
- if(!isset($topicTypeConfig["subject_custom"]) || !isset($topicTypeConfig["subject_custom"]["custom_column"])){
- return "";
- }
- if(!isset($topicTypeConfig["subject_custom"]["custom_column"][$topicInfo["subject_id"]])){
- return "";
- }
- $customColumnArr = $topicTypeConfig["subject_custom"]["custom_column"][$topicInfo["subject_id"]];
- $field_name = "";
- foreach($customColumnArr as $value){//获取题型对应的 名师指点定制标签
- if(isset($value["field_describe"]) && strpos($value["field_describe"],"名师指点") !==false){
- $field_name =$value["field_name"];
- break;
- }
- }
- if(!$field_name){
- return "";
- }
- $returnTeacherTips ="";
- $affiliate = $topicInfo["affiliate"];
- if(is_object($affiliate)){
- $affiliate = json_decode(json_encode($affiliate),true);
- }
- foreach($affiliate as $affValue){//获取定制标签的值
- if(is_object($affValue)){
- $affValue = json_decode(json_encode($affValue),true);
- }
- if(isset($affValue["field_key"]) && $affValue["field_key"] == $field_name){
- $returnTeacherTips = isset($affValue["field_value"])?$affValue["field_value"]:"";
- break;
- }
- }
- return $returnTeacherTips;
- }
- }
|