AcademicrBatchCommand.php 245 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144
  1. <?php
  2. class AcademicrBatchCommand extends CConsoleCommand {
  3. public $conn;
  4. public $sConn;
  5. public function init() {
  6. parent::init();
  7. @ini_set('memory_limit', '1024M');
  8. set_time_limit(0);
  9. }
  10. public $authUsername = '';
  11. private $units = array(
  12. 'in' => 96,
  13. 'cm' => 28,
  14. 'mm' => 2.8,
  15. 'pt' => 1.33,
  16. 'pc' => 12,
  17. );
  18. public function actionIndex($YII_ENV='development',$taskId=""){
  19. //echo YII_ENV;exit;
  20. if(YII_ENV == "production"){
  21. $file_html_url = "http://zsyas2.zhixinhuixue.com";
  22. }else{
  23. if(YII_ENV == 'development'){
  24. $file_html_url = "http://xbas2.dev.xiaoben.com";
  25. }else{
  26. $file_html_url = "http://xbas2.testing.xiaoben.com";
  27. }
  28. }
  29. //连接业务库
  30. $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']);
  31. if($conn){
  32. $this->conn = $conn;
  33. $time = time();
  34. //获取要生成教师讲案的数据
  35. if(isset($taskId) && $taskId){
  36. $sql = "select id,school_id,exam_group_id,class_ids from download_table_setting where id='{$taskId}'";
  37. }else{
  38. $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";
  39. }
  40. $result_all = $this->conn->createCommand($sql)->queryAll();
  41. //超过五分钟默认生成失败
  42. $sql = "update download_table_setting set status = 3,error_msg ='系统错误,建议单个生成' where status = 4 and error_msg = '' and update_time <".($time-600);
  43. $this->conn->createCommand($sql)->execute();
  44. if($result_all){
  45. // $time = time();
  46. // $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)";
  47. // $this->conn->createCommand($sql)->execute();
  48. // foreach($result_all as $v_data){
  49. foreach($result_all as $v_data_k=>$v_data){
  50. if($v_data_k > 0){
  51. break;
  52. }
  53. // var_dump($v_data);exit;
  54. $coach_name = "";
  55. $sql = "select coach_name from coach where school_id='{$v_data['school_id']}' and `status`=0";
  56. $coach_one = $this->conn->createCommand($sql)->queryRow();
  57. if($coach_one){
  58. $coach_name = $coach_one["coach_name"];
  59. }
  60. $sql = "select school_name from school where school_id = '{$v_data['school_id']}'";
  61. $school_one = $this->conn->createCommand($sql)->queryRow();
  62. if($school_one){
  63. $school_name = $school_one["school_name"];
  64. }else{
  65. $school_name = "";
  66. }
  67. $sql = "update download_table_setting set update_time = {$time},status=4 where id ={$v_data['id']}";
  68. $this->conn->createCommand($sql)->execute();
  69. $error = array();
  70. $pdfArr = array();
  71. $is_success = 0;
  72. //学管账号
  73. $coach = $this->conn->createCommand("select coach_name from coach where `status` = 0 and school_id={$v_data['school_id']};")->queryRow();
  74. if($coach){
  75. $authUsername = $v_data['school_id'].'_'.$coach['coach_name'];
  76. }else{
  77. echo $v_data['school_id']."学校获取学管信息失败\n";
  78. $error[] = $v_data['school_id']."学校获取学管信息失败";
  79. continue;
  80. }
  81. try{
  82. if($v_data['class_ids'] && $v_data['school_id'] && $v_data['exam_group_id']){
  83. //连接学校库
  84. $sql = "select database_host,database_user,database_password,database_name,group_id from `database` where school_id = '{$v_data['school_id']}'";
  85. $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']);
  86. if($conn){
  87. $this->conn = $conn;
  88. }else{
  89. echo "连接业务库失败\n";
  90. $error[] = "连接业务库失败";
  91. continue;
  92. }
  93. $result_one = $this->conn->createCommand($sql)->queryRow();
  94. if($result_one){
  95. $school_group_id = $result_one["group_id"];
  96. if (!is_numeric($school_group_id)){
  97. $school_group_id = 0;
  98. }
  99. $sConn = $this->getDbConnection($result_one["database_host"],$result_one["database_name"], $result_one["database_user"],$result_one["database_password"]);
  100. if($sConn){
  101. $sql = "select * from group_server where group_id = '{$school_group_id}'";
  102. $group_server_data = $this->conn->createCommand($sql)->queryRow();
  103. $static_url_data = $group_server_data['static_url'];
  104. $this->sConn = $sConn;
  105. echo '连接学校ID'.$v_data['school_id']."成功\n";
  106. $null_data = 1;
  107. $pdfNames = array();
  108. echo '开始获取任务ID'.$v_data['id']."的数据\n";
  109. $classIds = explode(",", $v_data["class_ids"]);
  110. if($classIds){
  111. foreach($classIds as $classId){
  112. $this->sConn->active = false;
  113. $sConn = $this->getDbConnection($result_one["database_host"],$result_one["database_name"], $result_one["database_user"],$result_one["database_password"]);
  114. $this->sConn = $sConn;
  115. echo "开始获取classId=".$classId."的数据\n";
  116. $data = array();
  117. $sql = "select class_name from class where class_id = '{$classId}'";
  118. $data_one = $this->sConn->createCommand($sql)->queryRow();
  119. if($data_one){
  120. $className = $data_one['class_name'];
  121. }else{
  122. $className = "";
  123. }
  124. $sql = "select exam_id,name from exam where exam_group_id = '{$v_data["exam_group_id"]}' and class_id = '{$classId}'";
  125. $data_one = $this->sConn->createCommand($sql)->queryRow();
  126. if($data_one){
  127. $examId = $data_one["exam_id"];
  128. $examName = $data_one["name"];
  129. $codeNow = $this->getCodeByExamId($examId);//当前学期code
  130. if($codeNow){
  131. $isFromPast = 1;
  132. }else{
  133. $isFromPast = 0;
  134. }
  135. $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}";
  136. $exam_info = $this->sConn->createCommand($sql)->queryRow();
  137. $grade = $exam_info['grade'];
  138. $paper_method_ids = $exam_info['method_ids'];
  139. $score_type = $exam_info['import_score_type'];//成绩导入流程 0-正常扫描
  140. $semesterId = $exam_info['semester_id'];
  141. if ($exam_info['mark_type'] == 0) {
  142. if(empty($codeNow)){
  143. $sql = "SELECT feedback_time
  144. FROM student_paper_relation
  145. WHERE paper_id = '" . $exam_info['paper_id'] . "' AND is_feedback = '1' AND is_del = '0' order by feedback_time desc limit 1";
  146. }else{
  147. $sql = "SELECT feedback_time
  148. FROM student_paper_relation_".$codeNow."
  149. WHERE paper_id = '" . $exam_info['paper_id'] . "' AND is_feedback = '1' AND is_del = '0' order by feedback_time desc limit 1";
  150. }
  151. $query = $this->sConn->createCommand($sql)->queryRow();
  152. if ($query && $query['feedback_time'] >= $exam_info['academicr_pdf_time']) {
  153. if (file_exists($exam_info['academicr_pdf_path'])) {
  154. unlink($exam_info['academicr_pdf_path']);
  155. }
  156. $force = 1;
  157. }
  158. unset($query);
  159. }
  160. $pdfpath = str_replace("protected", "", Yii::app()->basePath) . $exam_info['academicr_pdf_path'];
  161. $pdfurl = $pdfpath =$exam_info['academicr_pdf_path'];
  162. $is_create=1;
  163. $force = 0;
  164. if(strpos($pdfurl,'http') !== false){
  165. if(!file_get_contents($pdfurl)){
  166. $force = 1;
  167. }
  168. }else{
  169. $force = 1;
  170. }
  171. if (!$exam_info['academicr_pdf_path'] || $exam_info['is_academicr_pdf'] == 0 || $force) {
  172. // if (!$exam_info['academicr_pdf_path'] || $exam_info['is_academicr_pdf'] == 0 || !$this->check_pdf($pdfpath)) {
  173. $is_create=0;
  174. $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 ";
  175. $sql.= "FROM exam e ";
  176. $sql.= "JOIN paper p ON p.exam_id = e.exam_id ";
  177. $sql.= "JOIN exam_group eg ON eg.exam_group_id = e.exam_group_id ";
  178. $sql.= "WHERE e.status = '1' AND e.exam_id = '{$examId}' ";
  179. $data = array();
  180. $exam = $this->sConn->createCommand($sql)->queryRow();
  181. $labelled_type = $exam['labelled_type'];
  182. $class_id = $exam['class_id'];
  183. $is_qxk = $exam['qxk_paper_id']?1:0;//是否是全学科
  184. if($is_qxk){
  185. $qxkKnowledge = SPaperTopicRelation::newKnowledgeRelate();//获取全学科知识点对应老知识点的关系
  186. }
  187. if($class_id){
  188. $exam['show_level'] = $this->get_version($class_id);
  189. $exam['level_rule'] = $this->get_level_rule($class_id);
  190. }
  191. //获取显示设置
  192. $setting_arr = array("common"=>1,"common_wrong"=>1,"paper"=>1,"paper_wrong"=>1,"real_topic"=>1,"classmateOptimization"=>1);
  193. $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}'";
  194. $setting_data = $this->sConn->createCommand($sql)->queryRow();
  195. if($setting_data){
  196. $setting_data_arr = json_decode($setting_data['config_text'],true);
  197. if(isset($setting_data_arr['common'])){
  198. $setting_arr['common'] = $setting_data_arr['common'];
  199. }
  200. if(isset($setting_data_arr['common_wrong'])){
  201. $setting_arr['common_wrong'] = $setting_data_arr['common_wrong'];
  202. }
  203. if(isset($setting_data_arr['paper'])){
  204. $setting_arr['paper'] = $setting_data_arr['paper'];
  205. }
  206. if(isset($setting_data_arr['paper_wrong'])){
  207. $setting_arr['paper_wrong'] = $setting_data_arr['paper_wrong'];
  208. }
  209. if(isset($setting_data_arr['real_topic'])){
  210. $setting_arr['real_topic'] = $setting_data_arr['real_topic'];
  211. }
  212. if(isset($setting_data_arr['classmateOptimization'])){
  213. $setting_arr['classmateOptimization'] = $setting_data_arr['classmateOptimization'];
  214. }
  215. }
  216. $is_same_bs = 1;//是否开启相同变式题(需要读提分宝班级定制的配置)
  217. $same_bs_data = array();//开启相同变式题 原题跟变式题的对应关系
  218. $is_same_bs = $this->getClassSet($classId, $semesterId);
  219. if($is_same_bs && $labelled_type == 1){
  220. //判断有没有订单(提分方案2,提分宝3) 如果没有订单生成教学宝 有订单没数据不能生成
  221. $has_order = 0;
  222. $table_spr = empty($codeNow)?'student_paper_relation':'student_paper_relation_'.$codeNow;
  223. $sql = "select student_id from {$table_spr} where exam_id = '{$examId}'";
  224. $spr_data = $this->sConn->createCommand($sql)->queryAll();
  225. $relateStudentRes = array();
  226. if($spr_data){
  227. foreach($spr_data as $spr_v){
  228. $relateStudentRes[]['student_id'] = $spr_v['student_id'];
  229. }
  230. }
  231. foreach(array(2,3) as $product_type){
  232. $temp_order = $this->getOrderStu($examId, $classId, $product_type, $relateStudentRes, $semesterId, $grade,$v_data['school_id'],$coach_name);
  233. if($temp_order && isset($temp_order['limitstu']) && $temp_order['limitstu']){
  234. $has_order = 1;
  235. break;
  236. }
  237. }
  238. $sql = "select preparation_plan_id,template_id,topic_id from preparation_plan_topic where preparation_plan_id='{$examId}'";
  239. $same_bs = $this->sConn->createCommand($sql)->queryAll();
  240. if($same_bs){
  241. foreach($same_bs as $same_k=>$same_v){
  242. $same_bs_data[$same_v['template_id']][] = $same_v['topic_id'];
  243. }
  244. }else{
  245. if($has_order){
  246. echo json_encode(array("status"=>1,"error"=>"变式题未生成,请等待"));
  247. $error[] = $className."变式题未生成";
  248. continue;
  249. // exit;
  250. }
  251. }
  252. $setting_arr['common'] = 0;
  253. }
  254. if($labelled_type == 2){
  255. $exam['show_level'] = 0;
  256. }else{
  257. $sql = "select switch from producut_set_edition";
  258. $switch_data = $this->sConn->createCommand($sql)->queryRow();
  259. if($switch_data && in_array($switch_data['switch'],array(3,4))){
  260. $exam['show_level'] = 0;
  261. $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";
  262. $gongxing_data = $this->sConn->createCommand($sql)->queryAll();
  263. if(!$gongxing_data){
  264. echo json_encode(array("status"=>1,"error"=>"共性问题未生成,请稍等"));
  265. $error[] = $className."共性问题未生成";
  266. continue;
  267. // exit;
  268. }
  269. }else{
  270. if ($exam && !$isFromPast && $exam['show_level'] == 1 && $exam['is_preparation_created'] != 1) { //如果选择的是分层班,教师讲案的生成条件是教师讲评题已经抽出
  271. echo json_encode(array("status"=>1,"error"=>"文件内容尚未生成,请等待"));
  272. exit;
  273. }elseif ($exam && !$isFromPast && $exam['show_level'] == 1 && $exam['is_preparation_created'] == 2) {
  274. echo json_encode(array("status"=>1,"error"=>"由于题库题目导致无法生成,请联系后台题库老师去处理题目!"));
  275. exit;
  276. }
  277. }
  278. }
  279. if ($exam['is_labelled']!=1) {
  280. echo "试卷还未标注,请先标注试卷\n";
  281. $error[] = $className."试卷还未标注,请先标注试卷";
  282. continue;
  283. }
  284. // if($switch_data && in_array($switch_data['switch'],array(3,4))){
  285. // $sql = "select template_id,topic_id,topic_type from product_common_topic where exam_id = '{$examId}' order by topic_type asc";
  286. // $gongxing_data = $this->sConn->createCommand($sql)->queryAll();
  287. // if(!$gongxing_data){
  288. // echo "共性问题未生成,请等待\n";
  289. // $error[] = $className."共性问题未生成,请等待";
  290. // continue;
  291. // }
  292. // }
  293. if ($exam) {
  294. //同学优解
  295. $excellent_solution = SStudentPaperTopicRs::model()->bestAnswer($exam,$codeNow,$static_url_data,$this->sConn,$is_qxk);
  296. //获取共性问题
  297. $has_topic_gaokao = array();//本教学宝其他题,用于抽取高考真题
  298. $gen_topics = array();
  299. $gen_topics_ids = array();//共性所有题ID集合
  300. $gen_topics_detail = array();//试题详情
  301. $gen_topics_msg = array();//题目难度、考点、挑战信息
  302. // $schoolId = $this->schoolId;//当前学校
  303. $school_province_name = "";//学校省份
  304. $school_province_id = 0;//学校省份Id
  305. $gen_origin_ids = array();//共性原题Id
  306. $gen_origin_methods = array();//共性原题考点集合
  307. // $school_msg = Yii::app()->businessDb->createCommand()->from('school')
  308. // ->select("province_id")
  309. // ->where("school_id = ".$v_data['school_id'])
  310. // ->queryRow();
  311. $this->conn->active = false;
  312. $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']);
  313. $this->conn = $conn;
  314. $sql = "select province_id from school where school_id = '{$v_data['school_id']}'";
  315. $school_msg = $this->conn->createCommand($sql)->queryRow();
  316. if($school_msg){
  317. $school_province_id = $school_msg['province_id'];
  318. }
  319. if($school_province_id){
  320. // $region_msg = Yii::app()->businessDb->createCommand()->from('region')
  321. // ->select("region_name")
  322. // ->where("region_id = ".$school_province_id)
  323. // ->queryRow();
  324. $sql = "select region_name from region where region_id = '{$school_province_id}'";
  325. $region_msg = $this->conn->createCommand($sql)->queryRow();
  326. if($region_msg){
  327. $school_province_name = $region_msg["region_name"];
  328. }
  329. }
  330. $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";
  331. $gongxing_data = $this->sConn->createCommand($sql)->queryAll();
  332. if($gongxing_data){
  333. foreach($gongxing_data as $k=>$v){
  334. $i = 0;
  335. $gen_topics_ids[] = $gen_origin_ids[] = $v['template_id'];
  336. $gen_topics_ids[] = $v['topic_id'];
  337. $gen_topics[$v['topic_type']][$i]['topic_id'] = $v['template_id'];
  338. $gen_topics[$v['topic_type']][$i]['is_template'] = 1;
  339. $i++;
  340. $gen_topics[$v['topic_type']][$i]['topic_id'] = $v['topic_id'];
  341. $gen_topics[$v['topic_type']][$i]['is_template'] = 0;
  342. //变式训练获取地区挑战数
  343. if($v['topic_id']){
  344. $gen_topics_msg[$v['topic_id']]['school_province_name'] = $school_province_name;
  345. $topic_count = Yii::app()->topic_province_count->hmget('province_stat:topic:'.$school_province_id,array($v['topic_id']));
  346. if($topic_count && isset($topic_count[0])){
  347. $gen_topics_msg[$v['topic_id']]['province_count'] = empty($topic_count[0])?1000:$topic_count[0]+1000;
  348. }else{
  349. $gen_topics_msg[$v['topic_id']]['province_count'] = 1000;
  350. }
  351. $gen_topics_msg[$v['template_id']]['template_no'] = $v['template_no'];
  352. }
  353. }
  354. }
  355. $gen_topics_ids = array_values(array_unique($gen_topics_ids));
  356. if($gen_topics_ids){
  357. $topicItems_1 = $this->aipost('/topic/batchAll', array('topicIds' => $gen_topics_ids));
  358. //debug($topicItems_1);
  359. if ($topicItems_1 && !isset($topicItems_1['status'])) {
  360. foreach ($topicItems_1 as $topicItem) {
  361. $gen_topics_detail_temp[$topicItem['id']] = $topicItem;
  362. }
  363. if ($gen_topics_detail_temp) {
  364. foreach ($gen_topics_detail_temp as $k => $v) {
  365. $v=(array)$v;
  366. $v['id'] = (string)$v['id'];
  367. $teacher_tips= isset($v['teacher_tips'])?$v['teacher_tips']:"";
  368. if(!$teacher_tips){
  369. $teacher_tips = $this->dealTeacherTips($v);
  370. }
  371. $v['teacher_tips'] = $this->topicProcess($teacher_tips);
  372. $v['parse_content'] = $this->topicProcess($v['parse_content']);
  373. if($v['type_id'] == 5 || $v['type_id'] == 6){
  374. $v['title'] = preg_replace("/<img[^>]*[\s]+src[\s]*=[\s]*(([\'\"](\/images\/list_\d\.png)[\'\"])|(\/images\/list_\d\.png))[^>]*>/si", '__________', $v['title']);
  375. }
  376. $v['title'] = $this->topicProcess($v['title']);
  377. if(isset($v['items'][0])){
  378. $v['items'][0]=(array)$v['items'][0];
  379. $v['items'][0]['options']=(array)$v['items'][0]['options'];
  380. if (isset($v['items']) && isset($v['items'][0]) && isset($v['items'][0]['options'])) {
  381. foreach ($v['items'][0]['options'] as $key => $val) {
  382. $val=(array)$val;
  383. $v['items'][0]['options'][$key]=(array)$v['items'][0]['options'][$key];
  384. $v['items'][0]['options'][$key]['option_content'] = $this->topicProcess($val['option_content']);
  385. }
  386. }
  387. }
  388. //难度
  389. $gen_topics_msg[$v['id']]['difficulty'] = isset($v['difficulty_degree'])?$v['difficulty_degree']:0;
  390. //考点
  391. $gen_topics_msg[$v['id']]['methods'] = "";
  392. $methods_arr = array();
  393. if(isset($v['specials']) && $v['specials']){
  394. foreach($v['specials'] as $specials){
  395. if(isset($specials['method_name'])){
  396. $methods_arr[] = $specials['method_name'];
  397. }
  398. if(in_array($v['id'],$gen_origin_ids)){
  399. $gen_origin_methods[$specials['method_id']] = $specials['method_name'];
  400. }
  401. }
  402. }elseif (isset($v['kps']) && $v['kps']){
  403. foreach($v['kps'] as $kps){
  404. if(isset($kps['kp_name'])){
  405. $methods_arr[] = $kps['kp_name'];
  406. }
  407. if(in_array($v['id'],$gen_origin_ids)){
  408. $gen_origin_methods[$kps['kp_id']] = $kps['kp_name'];
  409. }
  410. }
  411. }
  412. if($methods_arr){
  413. $gen_topics_msg[$v['id']]['methods'] = implode(",",$methods_arr);
  414. }
  415. $gen_topics_detail[$v['id']] = $v;
  416. }
  417. }
  418. unset($gen_topics_detail_temp);
  419. }
  420. unset($topicItems_1);
  421. }
  422. //年级共性问题
  423. $grade_topics_ids = array();
  424. $grade_topic_data = array();
  425. $sql = "select topic_id from product_grade_common_topic where exam_group_id = '{$exam['exam_group_id']}'";
  426. $grade_data = $this->sConn->createCommand($sql)->queryAll();
  427. if($grade_data){
  428. foreach($grade_data as $k=>$v){
  429. $grade_topics_ids[] = $v['topic_id'];
  430. }
  431. }
  432. if($grade_topics_ids){
  433. $grade_topic_item = $this->aipost('/topic/batchAll', array('topicIds' => $grade_topics_ids));
  434. if ($grade_topic_item && !isset($grade_topic_item['status'])) {
  435. foreach ($grade_topic_item as $k => $v) {
  436. $v['parse_content'] = $this->topicProcess($v['parse_content']);
  437. if($v['type_id'] == 5 || $v['type_id'] == 6){
  438. $v['title'] = preg_replace("/<img[^>]*[\s]+src[\s]*=[\s]*(([\'\"](\/images\/list_\d\.png)[\'\"])|(\/images\/list_\d\.png))[^>]*>/si", '__________', $v['title']);
  439. }
  440. $v['title'] = $this->topicProcess($v['title']);
  441. if(isset($v['items'][0])){
  442. if (isset($v['items']) && isset($v['items'][0]) && isset($v['items'][0]['options'])) {
  443. foreach ($v['items'][0]['options'] as $key => $val) {
  444. $v['items'][0]['options'][$key]=(array)$v['items'][0]['options'][$key];
  445. $v['items'][0]['options'][$key]['option_content'] = $this->topicProcess($val['option_content']);
  446. }
  447. }
  448. }
  449. $grade_topic_item[$k] =$v;
  450. }
  451. $grade_topic_data = $grade_topic_item;
  452. }
  453. }
  454. $data['grade_topic_data'] = $grade_topic_data;
  455. $data['gen_origin_methods'] = $gen_origin_methods?implode(",",$gen_origin_methods):"";
  456. $data['gen_topics_msg'] = $gen_topics_msg;
  457. $data['gen_topics'] = $gen_topics;
  458. $data['gen_topics_detail'] = $gen_topics_detail;
  459. $data['excellent_solution'] = $excellent_solution;
  460. $data['wb_isp_version'] = $exam['show_level'];
  461. $data['level_rule'] = $exam['level_rule'];
  462. $data['examGroups'] = array();
  463. $data['examGroupIds'] = array();
  464. $data['exams'] = array();
  465. $data['examIds'] = array();
  466. $data['prevExams'] = array();
  467. $data['prevExamIds'] = array();
  468. $data['papers'] = array();
  469. $data['paperIds'] = array();
  470. $data['prevPapers'] = array();
  471. $data['prevPaperIds'] = array();
  472. $data['fcTopicIds'] = array();
  473. $data['methodIds'] = array();
  474. $data['methodNames'] = array();
  475. $data['topicIds'] = array();
  476. $data['noTopicIds'] = array();
  477. $data['topicDetails'] = array();
  478. $data['answer_score_details'] = array();//客观题答案明细
  479. if (!isset($data['examGroups'][$exam['exam_group_id']])) {
  480. $data['examGroups'][$exam['exam_group_id']] = array(
  481. 'examIds' => array(),
  482. 'paperIds' => array(),
  483. 'examName' => $exam['exam_name'],
  484. 'examTime' => $exam['exam_time'],
  485. 'fullScore' => $exam['paper_score'],
  486. );
  487. }
  488. $data['examGroups'][$exam['exam_group_id']]['examIds'][] = $exam['exam_id'];
  489. $data['examGroups'][$exam['exam_group_id']]['paperIds'][] = $exam['paper_id'];
  490. if (!isset($data['exams'][$exam['exam_id']])) {
  491. $data['exams'][$exam['exam_id']] = array(
  492. 'paperIds' => array(),
  493. 'examName' => $exam['exam_name'],
  494. 'examTime' => $exam['exam_time'],
  495. 'examGroupId' => $exam['exam_group_id'],
  496. 'fullScore' => $exam['paper_score'],
  497. );
  498. }
  499. $data['exams'][$exam['exam_id']]['paperIds'][] = $exam['paper_id'];
  500. if (!isset($data['papers'][$exam['paper_id']])) {
  501. $data['papers'][$exam['paper_id']] = array();
  502. }
  503. $data['papers'][$exam['paper_id']]['examId'] = $exam['exam_id'];
  504. $data['papers'][$exam['paper_id']]['examName'] = $exam['exam_name'];
  505. $data['papers'][$exam['paper_id']]['examTime'] = $exam['exam_time'];
  506. $data['papers'][$exam['paper_id']]['examGroupId'] = $exam['exam_group_id'];
  507. $data['papers'][$exam['paper_id']]['fullScore'] = $exam['paper_score'];
  508. $data['examGroupIds'][] = $exam['exam_group_id'];
  509. $data['examIds'][] = $exam['exam_id'];
  510. $data['paperIds'][] = $exam['paper_id'];
  511. // 上一次考试
  512. $sql = "SELECT e.exam_id, p.paper_id
  513. FROM exam e
  514. JOIN paper p ON p.exam_id = e.exam_id
  515. 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'
  516. ORDER BY e.create_time DESC
  517. LIMIT 1";
  518. $query = $this->sConn->createCommand($sql)->queryRow();
  519. if ($query) {
  520. $codePrev = $this->getCodeByExamId($query['exam_id']);
  521. $data['prevExamIds'][] = $query['exam_id'];
  522. $data['prevPaperIds'][] = $query['paper_id'];
  523. $data['exams'][$exam['exam_id']]['prevExamId'] = $query['exam_id'];
  524. $data['papers'][$exam['paper_id']]['prevPaperId'] = $query['paper_id'];
  525. $data['prevExams'][$query['exam_id']] = $exam['exam_id'];
  526. $data['prevPapers'][$query['paper_id']] = $exam['paper_id'];
  527. // 上次考试总分
  528. $prevQuery = $this->sConn->createCommand("
  529. SELECT score
  530. FROM paper
  531. WHERE paper_id = '" . $query['paper_id'] . "'
  532. ")->queryRow();
  533. if ($prevQuery) {
  534. $data['papers'][$exam['paper_id']]['prevFullScore'] = $prevQuery['score'];
  535. }
  536. unset($prevQuery);
  537. // 上次考试的平均得分率
  538. if(empty($codePrev)){
  539. $prevQuery = $this->sConn->createCommand("
  540. SELECT paper_id, COUNT(student_id) AS total_num, SUM(scoring) AS total_score, MAX(scoring) AS max_score, MIN(scoring) AS min_score
  541. FROM student_paper_relation
  542. WHERE is_feedback = '1' AND paper_id = '" . $query['paper_id'] . "'
  543. ")->queryRow();
  544. }else{
  545. $prevQuery = $this->sConn->createCommand("
  546. SELECT paper_id, COUNT(student_id) AS total_num, SUM(scoring) AS total_score, MAX(scoring) AS max_score, MIN(scoring) AS min_score
  547. FROM student_paper_relation_".$codePrev."
  548. WHERE is_feedback = '1' AND paper_id = '" . $query['paper_id'] . "'
  549. ")->queryRow();
  550. }
  551. if ($prevQuery) {
  552. $data['papers'][$exam['paper_id']]['prevTotalNum'] = $prevQuery['total_num'];
  553. $data['papers'][$exam['paper_id']]['prevTotalScore'] = $prevQuery['total_score'];
  554. $data['papers'][$exam['paper_id']]['prevMaxScore'] = $prevQuery['max_score'];
  555. $data['papers'][$exam['paper_id']]['prevMinScore'] = $prevQuery['min_score'];
  556. $data['papers'][$exam['paper_id']]['prevAvgScore'] = 0;
  557. $data['papers'][$exam['paper_id']]['prevAvgRate'] = 0;
  558. if ($prevQuery['total_num'] > 0) {
  559. $data['papers'][$exam['paper_id']]['prevAvgScore'] = number_format($prevQuery['total_score'] / $prevQuery['total_num'], 2);
  560. if (isset($data['papers'][$exam['paper_id']]['prevFullScore']) && $data['papers'][$exam['paper_id']]['prevFullScore'] > 0) {
  561. $data['papers'][$exam['paper_id']]['prevAvgRate'] = number_format($prevQuery['total_score'] / ($prevQuery['total_num'] * $data['papers'][$exam['paper_id']]['prevFullScore']), 4) * 100;
  562. }
  563. }
  564. }
  565. }
  566. unset($query);
  567. // 参加考试人数、平均得分率、平均分、及格率、最高分、最低分
  568. if(empty($codeNow)){
  569. $query = $this->sConn->createCommand("
  570. SELECT paper_id, COUNT(student_id) AS total_num, SUM(scoring) AS total_score, MAX(scoring) AS max_score, MIN(scoring) AS min_score
  571. FROM student_paper_relation
  572. WHERE is_feedback = '1' AND paper_id IN (" . implode(',', $data['paperIds']) . ")
  573. GROUP BY paper_id
  574. ")->queryAll();
  575. }else{
  576. $query = $this->sConn->createCommand("
  577. SELECT paper_id, COUNT(student_id) AS total_num, SUM(scoring) AS total_score, MAX(scoring) AS max_score, MIN(scoring) AS min_score
  578. FROM student_paper_relation_".$codeNow."
  579. WHERE is_feedback = '1' AND paper_id IN (" . implode(',', $data['paperIds']) . ")
  580. GROUP BY paper_id
  581. ")->queryAll();
  582. }
  583. if ($query) {
  584. foreach ($query as $k => $v) {
  585. $data['papers'][$v['paper_id']]['totalNum'] = $v['total_num'];
  586. $data['papers'][$v['paper_id']]['totalScore'] = $v['total_score'];
  587. $data['papers'][$v['paper_id']]['maxScore'] = $v['max_score'];
  588. $data['papers'][$v['paper_id']]['minScore'] = $v['min_score'];
  589. $data['papers'][$v['paper_id']]['avgScore'] = 0;
  590. $data['papers'][$v['paper_id']]['avgRate'] = 0;
  591. $data['papers'][$v['paper_id']]['avgFluctuate'] = 0;
  592. if ($v['total_num'] > 0) {
  593. $data['papers'][$v['paper_id']]['avgScore'] = number_format($v['total_score'] / $v['total_num'], 2);
  594. if (isset($data['papers'][$exam['paper_id']]['fullScore']) && $data['papers'][$exam['paper_id']]['fullScore'] > 0) {
  595. $data['papers'][$v['paper_id']]['avgRate'] = number_format($v['total_score'] / ($v['total_num'] * $data['papers'][$exam['paper_id']]['fullScore']), 4) * 100;
  596. if (isset($data['papers'][$v['paper_id']]['prevAvgRate'])) {
  597. $data['papers'][$v['paper_id']]['avgFluctuate'] = number_format($data['papers'][$v['paper_id']]['avgRate'] - $data['papers'][$v['paper_id']]['prevAvgRate'], 2);
  598. }
  599. }
  600. }
  601. }
  602. }
  603. unset($query);
  604. // 单题班级情况
  605. if(empty($codeNow)){
  606. $sql = "
  607. SELECT sptr.student_id, sptr.paper_id, sptr.topic_id, sptr.is_right, sptr.scoring, ptr.score,sptr.handlerIndex
  608. FROM student_paper_topic_rs sptr
  609. JOIN paper_topic_relation ptr ON (ptr.paper_id = sptr.paper_id AND ptr.topic_id = sptr.topic_id) where 1=1 ";
  610. //WHERE sptr.handlerIndex = '1'";
  611. }else{
  612. $sql = "
  613. SELECT sptr.student_id, sptr.paper_id, sptr.topic_id, sptr.is_right, sptr.scoring, ptr.score,sptr.handlerIndex
  614. FROM student_paper_topic_rs_".$codeNow." sptr
  615. JOIN paper_topic_relation ptr ON (ptr.paper_id = sptr.paper_id AND ptr.topic_id = sptr.topic_id) where 1=1 ";
  616. //WHERE sptr.handlerIndex = '1'";
  617. }
  618. $sql.="AND sptr.paper_id IN (" . implode(',', $data['paperIds']) . ")";
  619. $query = $this->sConn->createCommand($sql)->queryAll();
  620. $class_topic_score = array();
  621. $topic_score_arr = array();
  622. if ($query) {
  623. $data['papers'][$v['paper_id']]['topics'] = array();
  624. foreach ($query as $k => $v) {
  625. if (!isset($data['papers'][$v['paper_id']]['topics'][$v['topic_id']])) {
  626. $data['papers'][$v['paper_id']]['topics'][$v['topic_id']] = array();
  627. $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['fullScore'] = $v['score'];
  628. $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['totalScore'] = 0;
  629. $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['avgScore'] = 0;
  630. $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['avgRate'] = 0;
  631. $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['numRight'] = 0;
  632. $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['numWrong'] = 0;
  633. $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['studentIds'] = array();
  634. $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['rateLess70'] = array();//得分率低于70%的,选择题错的
  635. $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['classRate'] = 0;
  636. }
  637. $topic_score_arr[$v['topic_id']] = $v['score'];
  638. //班级得分
  639. if (!isset($class_topic_score[$v['paper_id']])) {
  640. $class_topic_score[$v['paper_id']] = array();
  641. }
  642. if (!isset($class_topic_score[$v['paper_id']][$v['topic_id']])) {
  643. $class_topic_score[$v['paper_id']][$v['topic_id']] = array();
  644. }
  645. $class_topic_score[$v['paper_id']][$v['topic_id']][] = $v['scoring'];
  646. $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['totalScore'] += $v['scoring'];
  647. if ($v['is_right'] == 1) {
  648. $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['numRight'] ++;
  649. } else {
  650. if($v["handlerIndex"]==1) {
  651. $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['numWrong']++;
  652. }
  653. }
  654. if($v["handlerIndex"]==1) {
  655. $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['studentIds'][] = $v['student_id'];
  656. }
  657. if ($v['score'] && $v['scoring']/$v['score'] < 0.7 && $v["handlerIndex"]==1) {
  658. $data['papers'][$v['paper_id']]['topics'][$v['topic_id']]['rateLess70'][] = $v['student_id'];
  659. }
  660. }
  661. }
  662. unset($query);
  663. // 缺考人数
  664. if(empty($codeNow)){
  665. $query = $this->sConn->createCommand("
  666. SELECT paper_id, COUNT(student_id) AS absent_num
  667. FROM student_paper_relation
  668. WHERE is_feedback = '0' AND paper_id IN (" . implode(',', $data['paperIds']) . ")
  669. GROUP BY paper_id
  670. ")->queryAll();
  671. }else{
  672. $query = $this->sConn->createCommand("
  673. SELECT paper_id, COUNT(student_id) AS absent_num
  674. FROM student_paper_relation_".$codeNow."
  675. WHERE is_feedback = '0' AND paper_id IN (" . implode(',', $data['paperIds']) . ")
  676. GROUP BY paper_id
  677. ")->queryAll();
  678. }
  679. if ($query) {
  680. foreach ($query as $k => $v) {
  681. $data['papers'][$v['paper_id']]['absentNum'] = $v['absent_num'];
  682. }
  683. }
  684. unset($query);
  685. // 及格率
  686. if(empty($codeNow)){
  687. $query = $this->sConn->createCommand("
  688. SELECT paper_id, student_id, scoring
  689. FROM student_paper_relation
  690. WHERE is_feedback = '1' AND paper_id IN (" . implode(',', $data['paperIds']) . ")
  691. ")->queryAll();
  692. }else{
  693. $query = $this->sConn->createCommand("
  694. SELECT paper_id, student_id, scoring
  695. FROM student_paper_relation_".$codeNow."
  696. WHERE is_feedback = '1' AND paper_id IN (" . implode(',', $data['paperIds']) . ")
  697. ")->queryAll();
  698. }
  699. if ($query) {
  700. foreach ($query as $k => $v) {
  701. if (!isset($data['papers'][$exam['paper_id']]['passNum'])) {
  702. $data['papers'][$exam['paper_id']]['passNum'] = 0;
  703. $data['papers'][$exam['paper_id']]['passNum_90'] = 0;
  704. }
  705. if (isset($data['papers'][$exam['paper_id']]['fullScore']) && $data['papers'][$exam['paper_id']]['fullScore'] > 0) {
  706. if ($v['scoring'] / $data['papers'][$exam['paper_id']]['fullScore'] >= 0.6) {
  707. $data['papers'][$exam['paper_id']]['passNum'] ++;
  708. }
  709. if ($v['scoring'] / $data['papers'][$exam['paper_id']]['fullScore'] >= 0.9) {
  710. $data['papers'][$exam['paper_id']]['passNum_90'] ++;
  711. }
  712. }
  713. }
  714. unset($query);
  715. }
  716. foreach ($data['paperIds'] as $paperId) {
  717. if (!isset($data['papers'][$exam['paper_id']]['passRate'])) {
  718. $data['papers'][$exam['paper_id']]['passRate'] = 0;
  719. }
  720. if (isset($data['papers'][$v['paper_id']]['totalNum']) && $data['papers'][$v['paper_id']]['totalNum'] > 0 && isset($data['papers'][$exam['paper_id']]['passNum'])) {
  721. $data['papers'][$exam['paper_id']]['passRate'] = number_format($data['papers'][$exam['paper_id']]['passNum'] / $data['papers'][$v['paper_id']]['totalNum'], 4) * 100;
  722. }
  723. }
  724. $prevQuery = array();
  725. if ($data['prevPaperIds']) {
  726. // 上次考试排名
  727. if(empty($codePrev)){
  728. $prevQuery = $this->sConn->createCommand("
  729. SELECT paper_id, student_id, scoring
  730. FROM student_paper_relation
  731. WHERE paper_id IN (" . implode(',', $data['prevPaperIds']) . ") AND is_feedback = '1'
  732. ORDER BY paper_id ASC, scoring DESC
  733. ")->queryAll();
  734. }else{
  735. $prevQuery = $this->sConn->createCommand("
  736. SELECT paper_id, student_id, scoring
  737. FROM student_paper_relation_".$codePrev."
  738. WHERE paper_id IN (" . implode(',', $data['prevPaperIds']) . ") AND is_feedback = '1'
  739. ORDER BY paper_id ASC, scoring DESC
  740. ")->queryAll();
  741. }
  742. }
  743. if ($prevQuery) {
  744. foreach ($prevQuery as $k => $v) {
  745. if (isset($data['prevPapers'][$v['paper_id']])) {
  746. if (!isset($data['papers'][$data['prevPapers'][$v['paper_id']]]['prevRanks'])) {
  747. $data['papers'][$data['prevPapers'][$v['paper_id']]]['prevRanks'] = array();
  748. $data['papers'][$data['prevPapers'][$v['paper_id']]]['_prevRanks'] = array();
  749. $data['papers'][$data['prevPapers'][$v['paper_id']]]['_i'] = 0;
  750. $data['papers'][$data['prevPapers'][$v['paper_id']]]['_j'] = 0;
  751. }
  752. if (!isset($prevRank[$data['prevPapers'][$v['paper_id']]])) {
  753. $prevRank[$data['prevPapers'][$v['paper_id']]] = 0;
  754. }
  755. if ($data['papers'][$data['prevPapers'][$v['paper_id']]]['_i'] > 0) {
  756. if ($v['scoring'] == $data['papers'][$data['prevPapers'][$v['paper_id']]]['_prevRanks'][$data['papers'][$data['prevPapers'][$v['paper_id']]]['_i'] - 1][1]) {
  757. $data['papers'][$data['prevPapers'][$v['paper_id']]]['_j'] ++;
  758. $data['papers'][$data['prevPapers'][$v['paper_id']]]['_prevRanks'][] = array(
  759. $v['student_id'],
  760. $v['scoring'],
  761. $prevRank[$data['prevPapers'][$v['paper_id']]]
  762. );
  763. } else {
  764. $prevRank[$data['prevPapers'][$v['paper_id']]] ++;
  765. $prevRank[$data['prevPapers'][$v['paper_id']]]+= $data['papers'][$data['prevPapers'][$v['paper_id']]]['_j'];
  766. $data['papers'][$data['prevPapers'][$v['paper_id']]]['_j'] = 0;
  767. $data['papers'][$data['prevPapers'][$v['paper_id']]]['_prevRanks'][] = array(
  768. $v['student_id'],
  769. $v['scoring'],
  770. $prevRank[$data['prevPapers'][$v['paper_id']]]
  771. );
  772. }
  773. } else {
  774. $prevRank[$data['prevPapers'][$v['paper_id']]] ++;
  775. $prevRank[$data['prevPapers'][$v['paper_id']]]+= $data['papers'][$data['prevPapers'][$v['paper_id']]]['_j'];
  776. $data['papers'][$data['prevPapers'][$v['paper_id']]]['_j'] = 0;
  777. $data['papers'][$data['prevPapers'][$v['paper_id']]]['_prevRanks'][] = array(
  778. $v['student_id'],
  779. $v['scoring'],
  780. $prevRank[$data['prevPapers'][$v['paper_id']]]
  781. );
  782. }
  783. $data['papers'][$data['prevPapers'][$v['paper_id']]]['prevRanks'][$v['student_id']] = $prevRank[$data['prevPapers'][$v['paper_id']]];
  784. $data['papers'][$data['prevPapers'][$v['paper_id']]]['_i'] ++;
  785. }
  786. }
  787. unset($prevRank);
  788. }
  789. // 本次考试排名
  790. if(empty($codeNow)){
  791. $query = $this->sConn->createCommand("
  792. SELECT spr.paper_id, spr.student_id, si.realname, spr.scoring
  793. FROM student_paper_relation spr
  794. JOIN student_info si ON si.student_id = spr.student_id
  795. WHERE spr.paper_id IN (" . implode(',', $data['paperIds']) . ") AND spr.is_feedback = '1'
  796. ORDER BY spr.paper_id ASC, spr.scoring DESC
  797. ")->queryAll();
  798. }else{
  799. $query = $this->sConn->createCommand("
  800. SELECT spr.paper_id, spr.student_id, si.realname, spr.scoring
  801. FROM student_paper_relation_".$codeNow." spr
  802. JOIN student_info si ON si.student_id = spr.student_id
  803. WHERE spr.paper_id IN (" . implode(',', $data['paperIds']) . ") AND spr.is_feedback = '1'
  804. ORDER BY spr.paper_id ASC, spr.scoring DESC
  805. ")->queryAll();
  806. }
  807. $studentNames = array();
  808. if ($query) {
  809. foreach ($query as $k => $v) {
  810. if (!isset($data['papers'][$v['paper_id']]['ranks'])) {
  811. $data['papers'][$v['paper_id']]['ranks'] = array();
  812. $data['papers'][$v['paper_id']]['_ranks'] = array();
  813. $data['papers'][$v['paper_id']]['_i'] = 0;
  814. $data['papers'][$v['paper_id']]['_j'] = 0;
  815. }
  816. if (!isset($rank[$v['paper_id']])) {
  817. $rank[$v['paper_id']] = 0;
  818. }
  819. if ($data['papers'][$v['paper_id']]['_i'] > 0) {
  820. if ($v['scoring'] == $data['papers'][$v['paper_id']]['_ranks'][$data['papers'][$v['paper_id']]['_i'] - 1][1]) {
  821. $data['papers'][$v['paper_id']]['_j'] ++;
  822. $data['papers'][$v['paper_id']]['_ranks'][] = array(
  823. $v['student_id'],
  824. $v['scoring'],
  825. $rank[$v['paper_id']]
  826. );
  827. } else {
  828. $rank[$v['paper_id']] ++;
  829. $rank[$v['paper_id']]+= $data['papers'][$v['paper_id']]['_j'];
  830. $data['papers'][$v['paper_id']]['_j'] = 0;
  831. $data['papers'][$v['paper_id']]['_ranks'][] = array(
  832. $v['student_id'],
  833. $v['scoring'],
  834. $rank[$v['paper_id']]
  835. );
  836. }
  837. } else {
  838. $rank[$v['paper_id']] ++;
  839. $rank[$v['paper_id']]+= $data['papers'][$v['paper_id']]['_j'];
  840. $data['papers'][$v['paper_id']]['_j'] = 0;
  841. $data['papers'][$v['paper_id']]['_ranks'][] = array(
  842. $v['student_id'],
  843. $v['scoring'],
  844. $rank[$v['paper_id']]
  845. );
  846. }
  847. $data['papers'][$v['paper_id']]['ranks'][] = array(
  848. 'studentId' => $v['student_id'],
  849. 'realname' => $v['realname'],
  850. 'rank' => $rank[$v['paper_id']],
  851. );
  852. $data['papers'][$v['paper_id']]['_i'] ++;
  853. $studentNames[$v['student_id']] = $v['realname'];
  854. }
  855. unset($rank);
  856. }
  857. //班级得分率
  858. $class_topic_rate = array();
  859. if ($class_topic_score) {
  860. foreach ($class_topic_score as $_p_id => $t_id_scoring) {
  861. if (!isset($class_topic_rate[$_p_id])) {
  862. $class_topic_rate[$_p_id] = array();
  863. }
  864. foreach ($t_id_scoring as $_t_id => $_t_scoring) {
  865. if (isset($topic_score_arr[$_t_id]) && $topic_score_arr[$_t_id] > 0) {
  866. $class_topic_rate[$_p_id][$_t_id] = round(array_sum($_t_scoring)/($topic_score_arr[$_t_id]*count($_t_scoring)),2) * 100;
  867. }else{
  868. $class_topic_rate[$_p_id][$_t_id] = 0;
  869. }
  870. }
  871. }
  872. }
  873. unset($class_topic_score);
  874. //得分率低于70%的,选择题错的对应的学生名称
  875. if($studentNames && isset($data['papers']) && isset($data['papers'][$v['paper_id']]['topics'])){
  876. foreach ($data['papers'] as $pId => $_topics){
  877. foreach ($_topics['topics'] as $tId => $less70) {
  878. foreach ($less70['rateLess70'] as $lessk => $stuId) {
  879. if (isset($studentNames[$stuId])) {
  880. $data['papers'][$pId]['topics'][$tId]['rateLess70'][$lessk] = $studentNames[$stuId];
  881. }
  882. }
  883. $data['papers'][$pId]['topics'][$tId]['classRate'] = isset($class_topic_rate[$pId]) && isset($class_topic_rate[$pId][$tId])?$class_topic_rate[$pId][$tId]:0;
  884. }
  885. }
  886. }
  887. $data['studentNames'] = $studentNames;
  888. unset($studentNames);
  889. // 大幅进步、大幅度退步
  890. foreach ($data['papers'] as $key => $val) {
  891. if (isset($val['prevRanks']) && isset($val['ranks'])) {
  892. foreach ($val['ranks'] as $k => $v) {
  893. if (isset($val['prevRanks'][$v['studentId']])) {
  894. // 进步
  895. if (!isset($data['papers'][$key]['forwards'])) {
  896. $data['papers'][$key]['forwards'] = array();
  897. }
  898. if ($val['prevRanks'][$v['studentId']] - $v['rank'] > 0) {
  899. if (!isset($data['papers'][$key]['forwards'][$val['prevRanks'][$v['studentId']] - $v['rank']])) {
  900. $data['papers'][$key]['forwards'][$val['prevRanks'][$v['studentId']] - $v['rank']] = array();
  901. }
  902. $data['papers'][$key]['forwards'][$val['prevRanks'][$v['studentId']] - $v['rank']][] = array(
  903. 'studentId' => $v['studentId'],
  904. 'realname' => $v['realname'],
  905. 'rank' => $v['rank'],
  906. 'prevRank' => $val['prevRanks'][$v['studentId']]
  907. );
  908. }
  909. // 退步
  910. if (!isset($data['papers'][$key]['rewinds'])) {
  911. $data['papers'][$key]['rewinds'] = array();
  912. }
  913. if ($v['rank'] - $val['prevRanks'][$v['studentId']] > 0) {
  914. if (!isset($data['papers'][$key]['rewinds'][$v['rank'] - $val['prevRanks'][$v['studentId']]])) {
  915. $data['papers'][$key]['rewinds'][$v['rank'] - $val['prevRanks'][$v['studentId']]] = array();
  916. }
  917. $data['papers'][$key]['rewinds'][$v['rank'] - $val['prevRanks'][$v['studentId']]][] = array(
  918. 'studentId' => $v['studentId'],
  919. 'realname' => $v['realname'],
  920. 'rank' => $v['rank'],
  921. 'prevRank' => $val['prevRanks'][$v['studentId']]
  922. );
  923. }
  924. }
  925. }
  926. if (isset($data['papers'][$key]['forwards'])) {
  927. krsort($data['papers'][$key]['forwards'], SORT_NUMERIC);
  928. }
  929. if (isset($data['papers'][$key]['rewinds'])) {
  930. krsort($data['papers'][$key]['rewinds'], SORT_NUMERIC);
  931. }
  932. }
  933. if (isset($val['topics'])) {
  934. foreach ($val['topics'] as $k => $v) {
  935. if (count($v['studentIds']) > 0) {
  936. $data['papers'][$key]['topics'][$k]['avgScore'] = number_format($v['totalScore'] / count($v['studentIds']), 2);
  937. if (isset($data['papers'][$key]['topics'][$k]['fullScore']) && $data['papers'][$key]['topics'][$k]['fullScore'] > 0) {
  938. $data['papers'][$key]['topics'][$k]['avgRate'] = number_format($v['totalScore'] / (count($v['studentIds']) * $data['papers'][$key]['topics'][$k]['fullScore']), 4) * 100;
  939. }
  940. }
  941. }
  942. }
  943. }
  944. unset($query);
  945. // 考试情况分析
  946. if(empty($codeNow)){
  947. $query = $this->sConn->createCommand("
  948. 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
  949. ,sptr.handlerIndex
  950. FROM student_paper_topic_rs sptr
  951. JOIN student_paper_relation spr ON (spr.paper_id = sptr.paper_id AND spr.student_id = sptr.student_id)
  952. JOIN paper_topic_relation ptr ON (ptr.paper_id = sptr.paper_id AND ptr.topic_id = sptr.topic_id AND ptr.type = sptr.type)
  953. JOIN paper p ON p.paper_id = ptr.paper_id
  954. JOIN exam e ON e.exam_id = p.exam_id
  955. WHERE spr.is_feedback = '1' AND sptr.paper_id IN (" . implode(',', $data['paperIds']) . ")
  956. ORDER BY sptr.paper_id ASC, sptr.type ASC, ptr.order ASC, sptr.topic_id ASC, sptr.student_id ASC
  957. ")->queryAll();
  958. }else{
  959. $query = $this->sConn->createCommand("
  960. 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
  961. ,sptr.handlerIndex
  962. FROM student_paper_topic_rs_".$codeNow." sptr
  963. JOIN student_paper_relation_".$codeNow." spr ON (spr.paper_id = sptr.paper_id AND spr.student_id = sptr.student_id)
  964. JOIN paper_topic_relation ptr ON (ptr.paper_id = sptr.paper_id AND ptr.topic_id = sptr.topic_id AND ptr.type = sptr.type)
  965. JOIN paper p ON p.paper_id = ptr.paper_id
  966. JOIN exam e ON e.exam_id = p.exam_id
  967. WHERE spr.is_feedback = '1' AND sptr.paper_id IN (" . implode(',', $data['paperIds']) . ")
  968. ORDER BY sptr.paper_id ASC, sptr.type ASC, ptr.order ASC, sptr.topic_id ASC, sptr.student_id ASC
  969. ")->queryAll();
  970. }
  971. if ($query) {
  972. //转换试卷中每道题目的序号
  973. $paperNos = $this->transferOrders($data['paperIds'],$is_qxk);
  974. //计算出每道必做题 做了的人数
  975. foreach($query as $k => $v){
  976. if (!isset($data['papers'][$v['paper_id']]['doTopicNums'])) {//每道必做题 做了的人数
  977. $data['papers'][$v['paper_id']]['doTopicNums'] = array();
  978. }
  979. if (!isset($data['papers'][$v['paper_id']]['doTopicNums'][$v['topic_id']])) {
  980. $data['papers'][$v['paper_id']]['doTopicNums'][$v['topic_id']] = 0;
  981. }
  982. if ($v["handlerIndex"] ==1) {
  983. $data['papers'][$v['paper_id']]['doTopicNums'][$v['topic_id']] ++;
  984. }
  985. }
  986. foreach ($query as $k => $v) {
  987. if($v['stem_id']){
  988. $new_topic_id = (string)$v['stem_id'];
  989. }else{
  990. $new_topic_id = (string)$v['topic_id'];
  991. }
  992. //客观题答案明细
  993. if($v['type'] == 1 && !$score_type){//单选题
  994. if(!isset($data['answer_score_details'][$v['topic_id']])){
  995. $data['answer_score_details'][$v['topic_id']] = array();
  996. $data['answer_score_details'][$v['topic_id']]['answer'] = '';
  997. $data['answer_score_details'][$v['topic_id']]['option']['A'] = 0;
  998. $data['answer_score_details'][$v['topic_id']]['option']['B'] = 0;
  999. $data['answer_score_details'][$v['topic_id']]['option']['C'] = 0;
  1000. $data['answer_score_details'][$v['topic_id']]['option']['D'] = 0;
  1001. $data['answer_score_details'][$v['topic_id']]['order'] = $v['order'];
  1002. }
  1003. if(isset($data['answer_score_details'][$v['topic_id']]['option'][$v['answer']])){
  1004. $data['answer_score_details'][$v['topic_id']]['option'][$v['answer']]++;
  1005. }
  1006. }
  1007. //type=>3 全学科试卷 多选题
  1008. if((in_array($v['type'],array(2,11)) || $is_qxk && $v['type']==3) && !$score_type ){//多选不定项
  1009. $v_answer = str_replace(',','',$v['answer']);
  1010. if(!isset($data['answer_score_details'][$v['topic_id']])){
  1011. $data['answer_score_details'][$v['topic_id']] = array();
  1012. $data['answer_score_details'][$v['topic_id']]['answer'] = '';
  1013. $data['answer_score_details'][$v['topic_id']]['order'] = $v['order'];
  1014. }
  1015. if(isset($data['answer_score_details'][$v['topic_id']]['option'][$v_answer])){
  1016. $data['answer_score_details'][$v['topic_id']]['option'][$v_answer]++;
  1017. }else{
  1018. $data['answer_score_details'][$v['topic_id']]['option'][$v_answer] = 1;
  1019. }
  1020. }
  1021. if (!isset($data['papers'][$v['paper_id']]['errorNums'])) {
  1022. $data['papers'][$v['paper_id']]['errorNums'] = array();
  1023. }
  1024. if (!isset($data['papers'][$v['paper_id']]['errorNums'][$v['no']])) {
  1025. $data['papers'][$v['paper_id']]['errorNums'][$v['no']] = 0;
  1026. }
  1027. if ($v['is_right'] != 1 && $v["handlerIndex"] ==1) {
  1028. $data['papers'][$v['paper_id']]['errorNums'][$v['no']] ++;
  1029. }
  1030. if (!in_array((string)$new_topic_id, $data['topicIds'],true)) {
  1031. $data['topicIds'][] = $new_topic_id;
  1032. }
  1033. if (!in_array((string)$v['topic_id'], $data['noTopicIds'],true)) {
  1034. $data['noTopicIds'][] = (string)$v['topic_id'];
  1035. }
  1036. if (!isset($data['papers'][$v['paper_id']]['topicIds'])) {
  1037. $data['papers'][$v['paper_id']]['topicIds'] = array();
  1038. }
  1039. if (!isset($data['papers'][$v['paper_id']]['noTopicIds'])) {
  1040. $data['papers'][$v['paper_id']]['noTopicIds'] = array();
  1041. }
  1042. if (!in_array($new_topic_id, $data['papers'][$v['paper_id']]['topicIds'],true)) {
  1043. $data['papers'][$v['paper_id']]['topicIds'][] = $new_topic_id;
  1044. }
  1045. if (!in_array((string)$v['topic_id'], $data['papers'][$v['paper_id']]['noTopicIds'],true)) {
  1046. $data['papers'][$v['paper_id']]['noTopicIds'][] = (string)$v['topic_id'];
  1047. }
  1048. if (!isset($data['papers'][$v['paper_id']]['topicNos'])) {
  1049. $data['papers'][$v['paper_id']]['topicNos'] = array();
  1050. }
  1051. $data['papers'][$v['paper_id']]['topicNos'][$v['topic_id']] = $v['no'];
  1052. //带选做题的新序号
  1053. if (!isset($data['papers'][$v['paper_id']]['newTopicNos'])) {
  1054. $data['papers'][$v['paper_id']]['newTopicNos'] = array();
  1055. }
  1056. $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'];
  1057. if (!isset($data['examGroups'][$v['exam_group_id']]['topicIds'])) {
  1058. $data['examGroups'][$v['exam_group_id']]['topicIds'] = array();
  1059. }
  1060. if (!in_array($v['topic_id'], $data['examGroups'][$v['exam_group_id']]['topicIds'])) {
  1061. $data['examGroups'][$v['exam_group_id']]['topicIds'][] = $v['topic_id'];
  1062. }
  1063. if (!isset($data['examGroups'][$v['exam_group_id']]['rules'])) {
  1064. $data['examGroups'][$v['exam_group_id']]['rules'] = array();
  1065. }
  1066. $ruleMethodIds = $v['method_ids'];
  1067. $ruleType =(in_array($v['type'], array(17, 27)) ? 7 : $v['type']);
  1068. if($is_qxk && $v["method_ids"]){//如果是全学科的考试转变成老知识点
  1069. $methodIds = explode(',', $v['method_ids']);
  1070. $ruleMethodIds = array();
  1071. foreach($methodIds as $methodId){
  1072. if(isset($qxkKnowledge[$methodId])){
  1073. $ruleMethodIds = array_merge($ruleMethodIds,$qxkKnowledge[$methodId]);
  1074. }
  1075. }
  1076. $ruleMethodIds = empty($ruleMethodIds)?"":join(",",$ruleMethodIds);
  1077. $ruleType = 8;
  1078. }
  1079. $data['examGroups'][$v['exam_group_id']]['rules'][$v['topic_id']] = array(
  1080. 'num' => 1,
  1081. 'difficulty' => $v['method_difficulty'],
  1082. 'type' => $ruleType,
  1083. 'inMethodIds' => $ruleMethodIds,
  1084. 'eqMethodIds' => $ruleMethodIds,
  1085. 'callback' => $v['topic_id'],
  1086. );
  1087. $no = $paperNos[$v['paper_id']][$v['topic_id']];
  1088. if ($v['method_ids'] && $data['papers'][$v['paper_id']]['doTopicNums'][$v['topic_id']]) {
  1089. $methodIds = explode(',', $v['method_ids']);
  1090. foreach ($methodIds as $methodId) {
  1091. if (!in_array($methodId, $data['methodIds'])) {
  1092. $data['methodIds'][] = $methodId;
  1093. }
  1094. if (!isset($data['papers'][$v['paper_id']]['methodNos'])) {
  1095. $data['papers'][$v['paper_id']]['methodNos'] = array();
  1096. }
  1097. if (!isset($data['papers'][$v['paper_id']]['methodNos'][$methodId])) {
  1098. $data['papers'][$v['paper_id']]['methodNos'][$methodId] = array();
  1099. }
  1100. if (!in_array($no, $data['papers'][$v['paper_id']]['methodNos'][$methodId])) {
  1101. $data['papers'][$v['paper_id']]['methodNos'][$methodId][] = $no;
  1102. }
  1103. if (!isset($data['papers'][$v['paper_id']]['methodErrorNums'])) {
  1104. $data['papers'][$v['paper_id']]['methodErrorNums'] = array();
  1105. }
  1106. if (!isset($data['papers'][$v['paper_id']]['methodErrorNums'][$methodId])) {
  1107. $data['papers'][$v['paper_id']]['methodErrorNums'][$methodId] = 0;
  1108. }
  1109. if ($v['is_right'] != 1 && $v['handlerIndex']==1) {
  1110. $data['papers'][$v['paper_id']]['methodErrorNums'][$methodId] ++;
  1111. }
  1112. if (!isset($data['papers'][$v['paper_id']]['methodErrorStudents'])) {
  1113. $data['papers'][$v['paper_id']]['methodErrorStudents'] = array();
  1114. }
  1115. if (!isset($data['papers'][$v['paper_id']]['methodErrorStudents'][$methodId])) {
  1116. $data['papers'][$v['paper_id']]['methodErrorStudents'][$methodId] = array();
  1117. }
  1118. if ($v['is_right'] != 1) {
  1119. if (!in_array($v['student_id'], $data['papers'][$v['paper_id']]['methodErrorStudents'][$methodId],true) && $v['handlerIndex']==1) {
  1120. $data['papers'][$v['paper_id']]['methodErrorStudents'][$methodId][] = $v['student_id'];
  1121. }
  1122. }
  1123. if (!isset($data['papers'][$v['paper_id']]['methodFullScores'])) {
  1124. $data['papers'][$v['paper_id']]['methodFullScores'] = array();
  1125. }
  1126. if (!isset($data['papers'][$v['paper_id']]['methodFullScores'][$methodId])) {
  1127. $data['papers'][$v['paper_id']]['methodFullScores'][$methodId] = 0;
  1128. }
  1129. $data['papers'][$v['paper_id']]['methodFullScores'][$methodId] += $v['score'];
  1130. if (!isset($data['papers'][$v['paper_id']]['methodScores'])) {
  1131. $data['papers'][$v['paper_id']]['methodScores'] = array();
  1132. }
  1133. if (!isset($data['papers'][$v['paper_id']]['methodScores'][$methodId])) {
  1134. $data['papers'][$v['paper_id']]['methodScores'][$methodId] = 0;
  1135. }
  1136. $data['papers'][$v['paper_id']]['methodScores'][$methodId] += $v['scoring'];
  1137. }
  1138. }
  1139. }
  1140. foreach ($data['papers'] as $key => $val) {
  1141. if (isset($val['errorNums'])) {
  1142. //重置题号
  1143. $i = 1;
  1144. $newErrorNums = array();
  1145. foreach($val['errorNums'] as $k => $v){
  1146. $newErrorNums[$i] = $v;
  1147. $i++;
  1148. }
  1149. if($newErrorNums){
  1150. $val['errorNums'] = $newErrorNums;
  1151. $data['papers'][$key]['errorNums'] = $newErrorNums;
  1152. }
  1153. foreach ($val['errorNums'] as $k => $v) {
  1154. if (!isset($data['papers'][$key]['errorRates'])) {
  1155. $data['papers'][$key]['errorRates'] = array();
  1156. }
  1157. if ($data['papers'][$key]['totalNum'] > 0) {
  1158. $data['papers'][$key]['errorRates'][$k] = number_format($data['papers'][$key]['errorNums'][$k] / $data['papers'][$key]['totalNum'], 4) * 100;
  1159. } else {
  1160. $data['papers'][$key]['errorRates'][$k] = 0;
  1161. }
  1162. }
  1163. }
  1164. }
  1165. }
  1166. } else {
  1167. echo "文件尚未生成\n";
  1168. $error[] = $className."文件尚未生成";
  1169. continue;
  1170. }
  1171. if ($data['wb_isp_version'] != 1 || $isFromPast) { //个性化版
  1172. if (isset($data['examGroups']) && $data['examGroups'] && is_array($data['examGroups'])) {
  1173. // 抽题
  1174. foreach ($data['examGroups'] as $key => $val) {
  1175. if($same_bs_data){
  1176. $data['examGroups'][$key]['fcTopicIds'] = array();
  1177. $data['examGroups'][$key]['fcCallbacks'] = array();
  1178. foreach($same_bs_data as $sa_k=>$sa_v){
  1179. $has_topic_gaokao[] = $sa_k;
  1180. foreach($sa_v as $sa_v_topic){
  1181. $has_topic_gaokao[] = $sa_v_topic;
  1182. $data['examGroups'][$key]['fcTopicIds'][] = $sa_v_topic;
  1183. $data['examGroups'][$key]['fcCallbacks'][$sa_k][] = $sa_v_topic;
  1184. if (!in_array((string)$sa_v_topic, $data['fcTopicIds'])) {
  1185. $data['fcTopicIds'][] = (string)$sa_v_topic;
  1186. }
  1187. }
  1188. }
  1189. }else{
  1190. if($labelled_type == 2){//教师端标注抽题
  1191. $data['examGroups'][$key]['fcTopicIds'] = array();
  1192. $data['examGroups'][$key]['fcCallbacks'] = array();
  1193. $sql = "select topic_id,relation_id from exam_topic_label where exam_group_id = '{$key}'";
  1194. $etl_data = $this->sConn->createCommand($sql)->queryAll();
  1195. if($etl_data){
  1196. foreach($etl_data as $etl_data_v){
  1197. if($etl_data_v['topic_id'] && $etl_data_v['relation_id']){
  1198. $relation_topic_arr = explode(",",$etl_data_v['relation_id']);
  1199. foreach($relation_topic_arr as $relation_topic_v){
  1200. if (!in_array((string)$relation_topic_v, $data['fcTopicIds'])) {
  1201. $data['fcTopicIds'][] = (string)$relation_topic_v;
  1202. }
  1203. $data['examGroups'][$key]['fcTopicIds'][] = $relation_topic_v;
  1204. $data['examGroups'][$key]['fcCallbacks'][$etl_data_v['topic_id']][] = $relation_topic_v;
  1205. $has_topic_gaokao[] = $relation_topic_v;
  1206. }
  1207. $has_topic_gaokao[] = $etl_data_v['topic_id'];
  1208. }
  1209. }
  1210. }
  1211. }else{
  1212. if (isset($val['rules'])) {
  1213. $fc = $this->apiPost('/isp/ai', array(
  1214. 'schoolId' => $v_data['school_id'],
  1215. 'rules' => $val['rules'],
  1216. 'notInTopicIds' => $data['examGroups'][$key]['topicIds'],
  1217. ));
  1218. if ($fc && !isset($fc->error)) {
  1219. $data['examGroups'][$key]['fcTopicIds'] = array();
  1220. $data['examGroups'][$key]['fcCallbacks'] = array();
  1221. foreach ($fc as $k => $v) {
  1222. if (!in_array($v->id, $data['fcTopicIds'])) {
  1223. $data['fcTopicIds'][] = $v->id;
  1224. }
  1225. $data['examGroups'][$key]['fcTopicIds'][] = $v->id;
  1226. $data['examGroups'][$key]['fcCallbacks'][$v->callback][] = $v->id;
  1227. $has_topic_gaokao[] = $v->id;
  1228. $has_topic_gaokao[] = $v->callback;
  1229. }
  1230. }
  1231. }
  1232. }
  1233. }
  1234. }
  1235. $topicDetails=array();
  1236. $topicItems_1 = $this->apiPost('/topic/batchAll', array('topicIds' => array_merge(
  1237. $data['topicIds'],
  1238. (isset($data['fcTopicIds']) ? $data['fcTopicIds'] : array())
  1239. )));
  1240. if (isset($topicItems_1->error)) {
  1241. $error[] = $className.$topicItems_1->error;
  1242. } elseif (! $topicItems_1) {
  1243. $error[] = $className.'Error in pumping system[2]';
  1244. } else {
  1245. foreach ($topicItems_1 as $topicItem) {
  1246. $topicDetails[$topicItem->id] = (object)$topicItem;
  1247. }
  1248. }
  1249. if ($topicDetails) {
  1250. foreach ($topicDetails as $k => $v) {
  1251. $v=(array)$v;
  1252. $v['id'] = (string)$v['id'];
  1253. $teacher_tips= isset($v['teacher_tips'])?$v['teacher_tips']:"";
  1254. if(!$teacher_tips){
  1255. $teacher_tips = $this->dealTeacherTips($v);
  1256. }
  1257. $v['teacher_tips'] = $this->topicProcess($teacher_tips);
  1258. $v['parse_content'] = $this->topicProcess($v['parse_content']);
  1259. if($v['type_id'] == 5){
  1260. $v['title'] = preg_replace("/<img[^>]*[\s]+src[\s]*=[\s]*(([\'\"](\/images\/list_\d\.png)[\'\"])|(\/images\/list_\d\.png))[^>]*>/si", '__________', $v['title']);
  1261. }
  1262. $v['title'] = $this->topicProcess($v['title']);
  1263. if(isset($v['items'][0])){
  1264. $v['items'][0]=(array)$v['items'][0];
  1265. $v['items'][0]['options']=(array)$v['items'][0]['options'];
  1266. if (isset($v['items']) && isset($v['items'][0]) && isset($v['items'][0]['options'])) {
  1267. foreach ($v['items'][0]['options'] as $key => $val) {
  1268. $val=(array)$val;
  1269. $v['items'][0]['options'][$key]=(array)$v['items'][0]['options'][$key];
  1270. $v['items'][0]['options'][$key]['option_content'] = $this->topicProcess($val['option_content']);
  1271. if(isset($data['answer_score_details'][$v['id']]) && $val['option_correct'] == 1){
  1272. $data['answer_score_details'][$v['id']]['answer'] .= $this->numToLetter($key + 1);
  1273. }
  1274. }
  1275. }
  1276. }
  1277. $data['topicDetails'][$v['id']] = $v;
  1278. }
  1279. unset($topicDetails);
  1280. }
  1281. }
  1282. } else { //分层版
  1283. //获取原题以及对应四个层次的提分题
  1284. //$preparation_plan_id = $exam['preparation_plan_id'];
  1285. if($data['level_rule'] == 1){
  1286. $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();
  1287. if($isDiffMin){
  1288. $plan_topic_res = $isDiffMin;
  1289. }else{
  1290. $plan_topic_res = $this->sConn->createCommand(" select template_id,level,topic_id,difficulty_degree from preparation_plan_topic where preparation_plan_id=" . $examId)->queryAll();
  1291. if($plan_topic_res){
  1292. $topicsOrigin = array();
  1293. $topicRelation = array();
  1294. foreach($plan_topic_res as $k=>$v){
  1295. $topicsOrigin[] = $v['template_id'];
  1296. $topicRelation[$v['template_id']][] = $v;
  1297. $has_topic_gaokao[] =$v['template_id'];
  1298. $has_topic_gaokao[] =$v['topic_id'];
  1299. }
  1300. if($topicsOrigin){
  1301. $topicsOrigin = array_unique($topicsOrigin);
  1302. $topicDetails = $this->aipost('/topic/batchAll', array('topicIds' => $topicsOrigin));
  1303. if (!$topicDetails) {
  1304. echo "获取接口batchALL无数据!\n";
  1305. $error[] = $className."无数据";
  1306. continue;
  1307. } elseif (isset($topicDetails['status']) && $topicDetails['status']==0) {
  1308. echo $topicDetails['error'][0]."\n";
  1309. $error[] =$className.$topicDetails['error'][0];
  1310. continue;
  1311. }
  1312. $topicDiff = array();
  1313. foreach($topicDetails as $k=>$v){
  1314. if(isset($v['difficulty_degree'])){
  1315. $diff = $v['difficulty_degree'];
  1316. }elseif(isset($v['experience_degree'])){
  1317. $diff = $v['experience_degree'];
  1318. }else{
  1319. $diff = 0;
  1320. }
  1321. $topicDiff[$v['id']] = $diff;
  1322. }
  1323. $new_plan_topic_res = array();
  1324. foreach($topicDiff as $k=>$v){
  1325. if(isset($topicRelation[$k])){
  1326. $arr1 = array();
  1327. $arr2 = array();
  1328. foreach($topicRelation[$k] as $relation){
  1329. $arr1[] = $relation['difficulty_degree'];
  1330. }
  1331. $x=$v;
  1332. $count=count($arr1);
  1333. for ($i=0; $i <$count ; $i++) {
  1334. $arr2[]=abs($x-$arr1[$i]);
  1335. }
  1336. $min= min($arr2);
  1337. for ($i=0; $i <$count ; $i++) {
  1338. if ($min==$arr2[$i]) {
  1339. $new_plan_topic_res[] = $topicRelation[$k][$i];
  1340. break 1;
  1341. }
  1342. }
  1343. }
  1344. }
  1345. }
  1346. $plan_topic_res = $new_plan_topic_res;
  1347. }
  1348. }
  1349. }else{
  1350. $plan_topic_res = $this->sConn->createCommand(" select template_id,level,topic_id from preparation_plan_topic where preparation_plan_id=" . $examId)->queryAll();
  1351. }
  1352. if (!$plan_topic_res) {
  1353. echo "文件尚未生成\n";
  1354. $error[] = $className."文件尚未生成";
  1355. continue;
  1356. }
  1357. $template_topic_arr = array();
  1358. $isp_id_arr = array();
  1359. foreach ($plan_topic_res as $v) {
  1360. $template_id = $v['template_id'];
  1361. $level = $v['level'];
  1362. $topic_id = $v['topic_id'];
  1363. if (!isset($template_topic_arr[$template_id])) {
  1364. $template_topic_arr[$template_id] = array();
  1365. }
  1366. $template_topic_arr[$template_id][$level] = $topic_id;
  1367. $isp_id_arr[] = $topic_id;
  1368. }
  1369. //试卷中校本题库题是哪些,云题库题是哪些
  1370. $sch_id_arr = array(); //试卷中校本题库题是哪些
  1371. $yun_id_arr = array();
  1372. $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;
  1373. $paper_topic_res = $this->sConn->createCommand($sql)->queryAll();
  1374. if (!$paper_topic_res) {
  1375. echo "文件尚未生成\n";
  1376. $error[] = $className."文件尚未生成";
  1377. continue;
  1378. }
  1379. $topic_no_arr = $this->getTopicNoByPaper($paper_topic_res, $exam['tpl_index']); //获取每道题在试卷中的序号,如 21A,21B
  1380. foreach ($paper_topic_res as $v) {
  1381. $v['mode'] == 1 && $sch_id_arr[] = $v['topic_id'];
  1382. $v['mode'] == 0 && $yun_id_arr [] = $v['topic_id'];
  1383. }
  1384. $isp_id_arr = array_merge($isp_id_arr, $yun_id_arr);
  1385. //获取所有以上题目的详情,以供显示到教师讲案中
  1386. $topic_detail_arr = $this->paperTopicDetail($isp_id_arr, $sch_id_arr, $examId,'分层提分题');
  1387. if (!$topic_detail_arr) {
  1388. echo "获取不到试卷题目内容\n";
  1389. $error[] = $className."获取不到试卷题目内容";
  1390. continue;
  1391. }
  1392. foreach($topic_detail_arr as $k_topic=>$v_topic){
  1393. if(isset($data['answer_score_details'][(string)$k_topic])){
  1394. $data['answer_score_details'][(string)$k_topic]['answer'] = isset($v_topic['answer_format'])?$v_topic['answer_format']:'';
  1395. }
  1396. }
  1397. $diff_id_arr = array_diff($isp_id_arr + $sch_id_arr, array_keys($topic_detail_arr));
  1398. if ($diff_id_arr) {
  1399. //todo 发送消息到补提
  1400. echo "请等待题库老师补题!\n";
  1401. $error[] = $className."请等待题库老师补题!";
  1402. continue;
  1403. } else {
  1404. $data['template_topic_arr'] = $template_topic_arr;
  1405. $data['topic_details'] = $topic_detail_arr;
  1406. $data['topic_no_arr'] = $topic_no_arr;
  1407. unset($template_topic_arr);
  1408. unset($topic_detail_arr);
  1409. }
  1410. }
  1411. // 获取考点名称
  1412. if (isset($data['methodIds']) && $data['methodIds']) {
  1413. if($is_qxk){
  1414. $methods = $this->apiPost('/all_knowledge/knowledge_name', array('knowledgeIds' => $data['methodIds']));
  1415. if ($methods && isset($methods->data) && $methods->data) {
  1416. foreach ($methods->data as $k => $v) {
  1417. $data['methodNames'][$k] = $v;
  1418. }
  1419. unset($methods);
  1420. }
  1421. }else{
  1422. $methods = $this->apiPost('/special/methods', array('methodIds' => $data['methodIds']));
  1423. if ($methods) {
  1424. foreach ($methods as $k => $v) {
  1425. $data['methodNames'][$v->method_id] = $v->method_name;
  1426. }
  1427. unset($methods);
  1428. }
  1429. }
  1430. }
  1431. if (isset($data['examGroupIds']) && $data['examGroupIds'] && is_array($data['examGroupIds'])) {
  1432. // $this->sConn->active = false;
  1433. // $this->sConn = $this->getDbConnection();
  1434. $this->sConn->active = false;
  1435. $sConn = $this->getDbConnection($result_one["database_host"],$result_one["database_name"], $result_one["database_user"],$result_one["database_password"]);
  1436. $this->sConn = $sConn;
  1437. $query = array();
  1438. if(empty($codeNow)){
  1439. $sql = "SELECT sptr.student_id, sptr.paper_id, sptr.topic_id, sptr.is_right, sptr.scoring, e.exam_group_id,sptr.handlerIndex
  1440. FROM student_paper_topic_rs sptr
  1441. JOIN paper p ON p.paper_id = sptr.paper_id
  1442. JOIN exam e ON e.exam_id = p.exam_id
  1443. WHERE e.exam_group_id IN (" . implode(',', $data['examGroupIds']) . ")";
  1444. }else{
  1445. $sql = "SELECT sptr.student_id, sptr.paper_id, sptr.topic_id, sptr.is_right, sptr.scoring, e.exam_group_id,sptr.handlerIndex
  1446. FROM student_paper_topic_rs_".$codeNow." sptr
  1447. JOIN paper p ON p.paper_id = sptr.paper_id
  1448. JOIN exam e ON e.exam_id = p.exam_id
  1449. WHERE e.exam_group_id IN (" . implode(',', $data['examGroupIds']) . ") ";
  1450. }
  1451. $sptrData = $this->sConn->createCommand($sql)->queryAll();
  1452. if($sptrData){
  1453. $paperTopic = array();
  1454. $paperIds = array();
  1455. foreach($sptrData as $k=>$v){
  1456. if(!in_array($v['paper_id'], $paperIds)){
  1457. $paperIds[] = $v['paper_id'];
  1458. }
  1459. }
  1460. if($paperIds){
  1461. $sql = "select score,paper_id,topic_id from paper_topic_relation where paper_id in (" . implode(',', $paperIds) . ")";
  1462. $ptrData = $this->sConn->createCommand($sql)->queryAll();
  1463. if($ptrData){
  1464. foreach($ptrData as $k=>$v){
  1465. $paperTopic[$v['paper_id']][$v['topic_id']] = $v['score'];
  1466. }
  1467. unset($ptrData);
  1468. }
  1469. if($paperTopic){
  1470. foreach($sptrData as $k=>$v){
  1471. if(isset($paperTopic[$v['paper_id']]) && isset($paperTopic[$v['paper_id']][$v['topic_id']])){
  1472. $sptrData[$k]['score'] = $paperTopic[$v['paper_id']][$v['topic_id']];
  1473. }
  1474. }
  1475. $query = $sptrData;
  1476. }
  1477. }
  1478. unset($sptrData);
  1479. }
  1480. /////////newending
  1481. ///
  1482. $grade_topic_score = array();
  1483. if ($query) {
  1484. foreach ($query as $k => $v) {
  1485. if (!isset($data['examGroups'][$v['exam_group_id']]['topics'])) {
  1486. $data['examGroups'][$v['exam_group_id']]['topics'] = array();
  1487. }
  1488. if (!isset($data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']])) {
  1489. $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']] = array();
  1490. $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['fullScore'] = $v['score'];
  1491. $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['totalScore'] = 0;
  1492. $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['avgScore'] = 0;
  1493. $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['avgRate'] = 0;
  1494. $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['numRight'] = 0;
  1495. $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['numWrong'] = 0;
  1496. $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['studentIds'] = array();
  1497. }
  1498. $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['totalScore'] += $v['scoring'];
  1499. if ($v['is_right'] == 1) {
  1500. $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['numRight'] ++;
  1501. } else {
  1502. if($v["handlerIndex"]==1) {//必做题
  1503. $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['numWrong']++;
  1504. }
  1505. }
  1506. if($v["handlerIndex"]==1) {//必做题
  1507. $data['examGroups'][$v['exam_group_id']]['topics'][$v['topic_id']]['studentIds'][] = $v['student_id'];
  1508. }
  1509. //年级得分
  1510. if (!isset($grade_topic_score[$v['topic_id']])) {
  1511. $grade_topic_score[$v['topic_id']] = array();
  1512. }
  1513. $grade_topic_score[$v['topic_id']][] = $v['scoring'];
  1514. }
  1515. foreach ($data['examGroups'] as $key => $val) {
  1516. if (isset($val['topics'])) {
  1517. foreach ($val['topics'] as $k => $v) {
  1518. if (count($v['studentIds']) > 0) {
  1519. $data['examGroups'][$key]['topics'][$k]['avgScore'] = number_format($v['totalScore'] / count($v['studentIds']), 2);
  1520. if (isset($data['examGroups'][$key]['topics'][$k]['fullScore']) && $data['examGroups'][$key]['topics'][$k]['fullScore'] > 0) {
  1521. $data['examGroups'][$key]['topics'][$k]['avgRate'] = number_format($v['totalScore'] / (count($v['studentIds']) * $data['examGroups'][$key]['topics'][$k]['fullScore']), 4) * 100;
  1522. }
  1523. }
  1524. }
  1525. }
  1526. }
  1527. }
  1528. }
  1529. $grade_topic_rate = array();
  1530. if ($grade_topic_score) {
  1531. foreach ($grade_topic_score as $_t_id => $_t_scoring) {
  1532. if (isset($topic_score_arr[$_t_id]) && $topic_score_arr[$_t_id] > 0) {
  1533. $grade_topic_rate[$_t_id] = round(array_sum($_t_scoring)/($topic_score_arr[$_t_id]*count($_t_scoring)),2) * 100;
  1534. }else{
  1535. $grade_topic_rate[$_t_id] = 0;
  1536. }
  1537. }
  1538. }
  1539. unset($grade_topic_score);
  1540. unset($topic_score_arr);
  1541. //高考真题
  1542. $data['gaokao_topic'] = array();
  1543. if($grade == 3){
  1544. $gaokao_topic = array();
  1545. $sql = "select topic_id from gaokao_academicr_topic where class_id ='{$classId}'";
  1546. $gaokao_data = $this->sConn->createCommand($sql)->queryAll();
  1547. if($gaokao_data){
  1548. foreach($gaokao_data as $gao){
  1549. $gaokao_topic[] = $gao['topic_id'];
  1550. }
  1551. }
  1552. if($gen_origin_methods){
  1553. $weak_methodids = array_keys($gen_origin_methods);
  1554. }else{
  1555. $weak_methodids = array();
  1556. }
  1557. if($paper_method_ids){
  1558. $paper_methodids = explode(",",$paper_method_ids);
  1559. }else{
  1560. $paper_methodids = array();
  1561. }
  1562. if($has_topic_gaokao){
  1563. $has_topic = $has_topic_gaokao;
  1564. }else{
  1565. $has_topic = array();
  1566. }
  1567. $gaokao_topic = $this->acadGaokao($examId,$classId,$has_topic,$weak_methodids,$paper_methodids);
  1568. if($gaokao_topic){
  1569. $topicBatchs = $this->aipost('topic/batchall', array('topicIds' => $gaokao_topic));
  1570. if ($topicBatchs && !isset($topicBatchs->error)) {
  1571. $data['gaokao_topic'] = $this->formatDetails($topicBatchs);
  1572. }
  1573. }
  1574. }
  1575. //整理客观题明细数据
  1576. if($data['answer_score_details']){
  1577. $new_answer_score_details = array();
  1578. $a = 0;
  1579. foreach($data['answer_score_details'] as $k=>$v){
  1580. if(isset($v['option']) && $v['option']){
  1581. foreach($v['option'] as $option_type=>$option_count){
  1582. $new_answer_score_details[$a]['id'] = $k;
  1583. $new_answer_score_details[$a]['order'] = $v['order'];
  1584. $new_answer_score_details[$a]['answer'] = $v['answer']?$v['answer']:'';
  1585. $new_answer_score_details[$a]['option'] = $option_type;
  1586. $new_answer_score_details[$a]['option_count'] = $option_count;
  1587. $a++;
  1588. }
  1589. }
  1590. }
  1591. $data['answer_score_details'] = $new_answer_score_details;
  1592. }
  1593. // $this->sConn->active = false; // 关闭连接 close();
  1594. if (isset($data['papers']) && $data['papers'] && is_array($data['papers'])) {
  1595. // 渲染
  1596. foreach ($data['papers'] as $key => $val) {
  1597. if (!isset($val['examId']) || !$val['examId'])
  1598. continue;
  1599. if (!isset($val['examGroupId']) || !$val['examGroupId'])
  1600. continue;
  1601. // $classname = ClassModel::model()->getClassName($classId);
  1602. $data = array_merge($val, array(
  1603. 'methodNames' => (isset($data['methodNames']) ? $data['methodNames'] : array()),
  1604. 'topicDetails' => (isset($data['topicDetails']) ? $data['topicDetails'] : array()),
  1605. 'groupTopics' => (isset($data['examGroups']) && isset($data['examGroups'][$val['examGroupId']]) && isset($data['examGroups'][$val['examGroupId']]['topics']) ? $data['examGroups'][$val['examGroupId']]['topics'] : array()),
  1606. 'fcCallbacks' => (isset($data['examGroups']) && isset($data['examGroups'][$val['examGroupId']]) && isset($data['examGroups'][$val['examGroupId']]['fcCallbacks']) ? $data['examGroups'][$val['examGroupId']]['fcCallbacks'] : array()),
  1607. 'wb_isp_version' => isset($data['wb_isp_version']) ? $data['wb_isp_version'] : 0,
  1608. 'template_topic_arr' => isset($data['template_topic_arr']) ? $data['template_topic_arr'] : array(),
  1609. 'topic_details' => isset($data['topic_details']) ? $data['topic_details'] : array(),
  1610. 'topic_no_arr' => isset($data['topic_no_arr']) ? $data['topic_no_arr']: array(),
  1611. 'level_rule' => isset($data['level_rule']) ? $data['level_rule'] : 0,
  1612. 'gradeTopicRate' => $grade_topic_rate,
  1613. 'studentNames'=>isset($data['studentNames']) ? $data['studentNames'] : array(),
  1614. 'excellent_solution'=>isset($data['excellent_solution']) ? $data['excellent_solution'] : array(),
  1615. 'gen_topics'=>isset($data['gen_topics']) ? $data['gen_topics'] : array(),
  1616. 'gen_topics_detail'=>isset($data['gen_topics_detail']) ? $data['gen_topics_detail'] : array(),
  1617. 'gen_topics_msg'=>isset($data['gen_topics_msg']) ? $data['gen_topics_msg'] : array(),
  1618. 'answer_score_details'=>isset($data['answer_score_details']) ? $data['answer_score_details'] : array(),
  1619. 'gen_origin_methods'=>isset($data['gen_origin_methods'])?$data['gen_origin_methods']:'',
  1620. 'gaokao_topic'=>isset($data['gaokao_topic'])?$data['gaokao_topic']:array(),
  1621. 'setting_arr'=>isset($setting_arr)?$setting_arr:array(),
  1622. 'grade_topic_data'=>isset($data['grade_topic_data']) ? $data['grade_topic_data'] : array(),
  1623. 'is_qxk'=>$is_qxk,
  1624. )
  1625. );
  1626. $data['className'] = $className;
  1627. // $html = $this->renderPartial("academicr", $data, true);
  1628. $data['imgUrl'] = $file_html_url;
  1629. //是否是精准学习宝学校
  1630. $http = http('customer/precision-learning-school/check/'.$v_data['school_id'], 'GET', $authUsername);
  1631. $response = formatResponse($http);
  1632. $data['isPrecise'] = isset($response['data']) ? $response['data'] : 0;
  1633. //教师姓名
  1634. $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";
  1635. $teacher_msg = $this->sConn->createCommand($sql)->queryRow();
  1636. if($teacher_msg){
  1637. $data['teacherName'] = $teacher_msg['teacher_name'];
  1638. }
  1639. $html = $this->viewRender("academicr_1", $data, true);
  1640. //unset($data);
  1641. $htmlpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/academicr/'; //存放生成的HTML路径
  1642. $pdfpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/academicr/' . $v_data['school_id'] . "/"; //存放生成的PDF路径
  1643. $pdfurl = '/upload/tmpDir/academicr/' . $v_data['school_id'] . "/";
  1644. if (!is_dir($htmlpath)) {
  1645. if (!mkdir($htmlpath, 0777, true)) {
  1646. exit('Create directory fail: ' . $htmlpath);
  1647. }else{
  1648. exec('chown -R www:www '.$htmlpath);
  1649. }
  1650. }if (!is_dir($pdfpath)) {
  1651. if (!mkdir($pdfpath, 0777, true)) {
  1652. exit('Create directory fail1: ' . $pdfpath);
  1653. }else{
  1654. exec('chown -R www:www '.$pdfpath);
  1655. }
  1656. }
  1657. $htmlpath.=$examId . ".html";
  1658. echo "开始写入html\n";
  1659. $f = fopen($htmlpath, "w");
  1660. fwrite($f, $html);
  1661. fclose($f);
  1662. echo "写入html结束\n";
  1663. $htmlurl = '/upload/tmpDir/academicr/' . $examId . ".html"; //访问HTML的路径
  1664. if (Yii::app()->basePath == "C:\wamp\www\zsyas2\protected") {//本地的basePath
  1665. $locale='en_US.UTF-8'; // 或 $locale='zh_CN.UTF-8';
  1666. setlocale(LC_ALL,$locale);
  1667. putenv('LC_ALL='.$locale);
  1668. $htmlurl = "http://zsyte.dev.xueping.com/html/%E9%A6%96%E9%A1%B5.html";
  1669. // $pdffname = str_replace(".", "。", $exam_info['class_name'] . "-" . $exam_info['exam_name']);
  1670. // $pdffname = str_replace(" ", "", $pdffname) . ".pdf";
  1671. // $pdffname=iconv("UTF-8", "GBK",$pdffname);
  1672. $pdffname=$classId."-".$examId.".pdf";
  1673. $pdfpath = $pdfpath . $pdffname;
  1674. $pdfurl = $pdfurl . $pdffname;
  1675. $header_str = $school_name.$exam_info['class_name']."+++".$exam_info['exam_name']."+++"."时间:".date("Y-m-d",time());
  1676. $commond = Yii::app()->params['phantomjs_server'] . " "
  1677. . Yii::app()->basePath . '/../js/html2pdf_math.js' . " "
  1678. . " {$htmlurl}"
  1679. . " {$pdfpath}"
  1680. . " 176mm*250mm '{$header_str}'";
  1681. } else {
  1682. $locale='en_US.UTF-8'; // 或 $locale='zh_CN.UTF-8';
  1683. setlocale(LC_ALL,$locale);
  1684. putenv('LC_ALL='.$locale);
  1685. // echo Yii::app()->params['phantomjs'];exit;
  1686. $htmlurl = $file_html_url . $htmlurl;
  1687. // $htmlurl = "http://" . $_SERVER['SERVER_NAME'] . $htmlurl;
  1688. // $pdffname = str_replace(".", "。", $exam_info['class_name'] . "-" . $exam_info['exam_name']);
  1689. // $pdffname = str_replace(" ", "", $pdffname) . ".pdf";
  1690. // $pdffname=iconv("UTF-8", "GBK",$pdffname);
  1691. $pdffname=$classId."-".$examId.".pdf";
  1692. $pdfpath = $pdfpath . $pdffname;
  1693. $pdfurl = $pdfurl . $pdffname;
  1694. $header_str = $school_name.$exam_info['class_name']."+++".$exam_info['exam_name']."+++"."时间:".date("Y-m-d",time());
  1695. $commond = Yii::app()->params['phantomjs_server'] . " "
  1696. . Yii::app()->basePath . '/../js/html2pdf_math.js' . " "
  1697. . " {$htmlurl}"
  1698. . " {$pdfpath}"
  1699. . " 176mm*250mm '{$header_str}'";
  1700. }
  1701. echo "开始转pdf\n";
  1702. exec($commond, $res, $code);
  1703. echo "转pdf结束\n";
  1704. $ucloud = new HuaweiCloud();
  1705. //上传html
  1706. $rehtml = $examId.".html";
  1707. $rehtmlname = 'zsyas2/math_academicr/'.$v_data['school_id'].'/'. date('Y') . '/' . date('m') . '/' . date('d').'/'. uniqid() . '.' . $rehtml;
  1708. $uploadHtmlInfo = $ucloud->putFile($rehtmlname, $htmlpath);
  1709. if($uploadHtmlInfo['status'] == 0){
  1710. // $html_url = "http://" . $_SERVER['SERVER_NAME'].$htmlurl;
  1711. $html_url = $file_html_url.$htmlurl;
  1712. }else{
  1713. $html_url = $uploadHtmlInfo['url'];
  1714. @unlink($htmlpath);
  1715. }
  1716. $this->sConn->createCommand()->update("exam", array("academicr_html_path"=>$html_url), "exam_id = '{$examId}'");
  1717. if(isset($res[0])){
  1718. if (strpos($res[0], 'succeed') !== false) {//命令返回成功
  1719. if ($this->file_exists($pdfpath)) {
  1720. // $pdfurl=iconv("GBK", "UTF-8",$pdfurl);
  1721. $repdf = $examId.".pdf";
  1722. $rename = 'zsyas2/math_academicr/'.$v_data['school_id'].'/'. date('Y') . '/' . date('m') . '/' . date('d').'/'. uniqid() . '.' . $repdf;
  1723. echo "开始上传ucloud\n";
  1724. $uploadInfo = $ucloud->putFile($rename, $pdfpath);
  1725. echo "上传ucloud结束\n";
  1726. //@unlink($pdfpath);
  1727. if ($uploadInfo['status'] == 0) {
  1728. echo "PDF文件上传失败\n";
  1729. echo $uploadInfo['msg']."\n";
  1730. $error[] = $className."PDF文件上传失败";
  1731. }else{
  1732. $this->sConn->active = false;
  1733. $sConn = $this->getDbConnection($result_one["database_host"],$result_one["database_name"], $result_one["database_user"],$result_one["database_password"]);
  1734. $this->sConn = $sConn;
  1735. $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}'");
  1736. $pdfArr[] = $pdfpath;
  1737. $pdfNames[] = $className;
  1738. // @unlink($htmlpath);
  1739. }
  1740. //echo $htmlpath;exit;
  1741. // @unlink($htmlpath);
  1742. } else {
  1743. $this->sConn->createCommand()->update("exam", array("academicr_pdf_path" => "", "academicr_pdf_time" => 0, "is_academicr_pdf" => 0), "exam_id = '{$examId}'");
  1744. // @unlink($htmlpath);
  1745. echo "PDF文件未找到\n";
  1746. $error[] = $className."PDF文件未找到";
  1747. }
  1748. } else {
  1749. // @unlink($htmlpath);
  1750. echo "PDF创建失败1\n";
  1751. $error[] = $className."PDF创建失败1";
  1752. }
  1753. }else{
  1754. // Curl::post(Yii::app()->params['handle_log_api'], array(
  1755. // "exam_group_id" => (string)$val['examGroupId'],
  1756. // "operate_project" => 'zsyas2',
  1757. // "school_id" => $this->schoolId,
  1758. // "title" => '下载教师讲案',
  1759. // "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  1760. // "operate_method" => $this->action,
  1761. // "operate_url" => $this->getRoute(),
  1762. // "operate_sql" => '',
  1763. // "operate_param" =>json_encode(array('post'=>array("examId"=>$examId,"pdf"=>array("commond"=>$commond,"res"=>$res,"code"=>$code),"htmlurl"=>$htmlurl))),
  1764. //
  1765. // ));
  1766. echo "PDF创建失败2!\n";
  1767. $error[] = $className."PDF创建失败2!";
  1768. }
  1769. }
  1770. } else {
  1771. echo "渲染失败!\n";
  1772. $error[] = $className."渲染失败!";
  1773. // throw new CException("系统错误");
  1774. }
  1775. }else{
  1776. $pdfArr[] = $pdfpath;
  1777. $pdfNames[] = $className;
  1778. }
  1779. }
  1780. }
  1781. // var_dump($pdfArr);
  1782. foreach($pdfArr as $k=>$v){
  1783. if(strpos($v,'http') !== false){
  1784. $new_dir_url = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/academicr_batch/'.$v_data['exam_group_id']."/".$v_data['id']."/";
  1785. if (!is_dir($new_dir_url)) {
  1786. if (!mkdir($new_dir_url, 0777, true)) {
  1787. echo 'Create directory fail1: ' . $new_dir_url. "\n";
  1788. }else{
  1789. exec('chown -R www:www '.$new_dir_url);
  1790. }
  1791. }
  1792. $new_file_url = $this->downImgRar($v,$new_dir_url,$k);
  1793. $pdfArr[$k] = $new_file_url;
  1794. // echo $new_file_url;exit;
  1795. }
  1796. }
  1797. //var_dump($pdfArr);exit;
  1798. $this->conn->active = false;
  1799. $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']);
  1800. $this->conn = $conn;
  1801. if($pdfArr){
  1802. echo "开始压缩文件\n";
  1803. if($pdfArr){
  1804. echo $examName.'pdf生成成功!'. "\n";
  1805. // $report_name = $class_name.$year."年度报告.zip";
  1806. $filepath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/academicr_batch/'.$v_data['exam_group_id']."/".$v_data['id']."/"; //存放生成的PDF路径
  1807. if (!is_dir($filepath)) {
  1808. if (!mkdir($filepath, 0777, true)) {
  1809. echo 'Create directory fail1: ' . $filepath. "\n";
  1810. }else{
  1811. exec('chown -R www:www '.$filepath);
  1812. }
  1813. }
  1814. $examName = iconv("UTF-8","GBK//IGNORE",$examName);
  1815. $filename = dirname(dirname(dirname(__FILE__))).'/upload/tmpDir/academicr_batch/'.$v_data['exam_group_id']."/".$v_data['id']."/".$v_data['exam_group_id'].".zip"; //最终生成的文件名(含路径)
  1816. $zip = new ZipArchive();//使用本类,linux需开启zlib,windows需取消php_zip.dll前的注释
  1817. if ($zip->open($filename, ZIPARCHIVE::OVERWRITE)!==TRUE) {
  1818. echo $examName.'zip生成失败!'. "\n";
  1819. }else{
  1820. foreach ($pdfArr as $k=>$val) {
  1821. // $pdfNames[$k] = iconv("UTF-8","GBK//IGNORE",$pdfNames[$k]);
  1822. $pdfname = '-'.$pdfNames[$k].'-教师讲案';
  1823. $pdfname = iconv("UTF-8","GBK//IGNORE",$pdfname);
  1824. $res=$zip->addFile($val,$examName.$pdfname.'.pdf');
  1825. //@unlink($pdfArr[$k]);
  1826. }
  1827. $zip->close();//关闭
  1828. foreach($pdfArr as $k=>$val){
  1829. @unlink($val);
  1830. }
  1831. //生成完成
  1832. // $filename = addslashes($filename);
  1833. $time = time();
  1834. $filename = $this->characet($filename);
  1835. $ucloud = new HuaweiCloud();
  1836. $filename = iconv("UTF-8","GBK//IGNORE",$filename);
  1837. $examName = $this->characet($examName);
  1838. $meg = $ucloud->putFile('zsyas2/academicr_batch/'.$v_data['exam_group_id'].'/'.$v_data['id'].'/'.$examName.'.zip',$filename);
  1839. if($meg['status'] == 0){
  1840. $error[] = $className.$meg['msg'];
  1841. }else{
  1842. $url = $meg['url'];
  1843. $url = str_replace("%2F","/",$url);
  1844. $sql = "update download_table_setting set status = 2,zip_url = '{$url}',update_time = {$time} where id = {$v_data['id']}";
  1845. $this->conn->createCommand($sql)->execute();
  1846. $is_success = 1;
  1847. echo $examName.'zip生成成功!'. "\n";
  1848. }
  1849. @unlink($filename);
  1850. // if($pdfArr){
  1851. // $sql = "update download_table_setting set status = 2,zip_url = '{$url}',update_time = {$time} where id = {$v_data['id']}";
  1852. // $this->conn->createCommand($sql)->execute();
  1853. // echo $examName.'zip生成成功!'. "\n";
  1854. // }
  1855. }
  1856. }else{
  1857. echo 'pdf生成失败!'. "\n";
  1858. }
  1859. }
  1860. }else{
  1861. echo '连接学校ID'.$v_data['school_id']."失败\n";
  1862. continue;
  1863. }
  1864. }else{
  1865. echo '暂无学校ID'.$v_data['school_id']."的信息\n";
  1866. continue;
  1867. }
  1868. $this->sConn->active = false;
  1869. }
  1870. if(!$is_success){
  1871. if($error){
  1872. $time = time();
  1873. $sql = "update download_table_setting set error_msg='".implode(",",$error)."',update_time = {$time},status=3 where id = {$v_data['id']}";
  1874. $this->conn->createCommand($sql)->execute();
  1875. echo $examName.'zip生成失败!'. "\n";
  1876. }else{
  1877. $time = time();
  1878. $sql = "update download_table_setting set update_time = {$time},status=3 where id = {$v_data['id']}";
  1879. $this->conn->createCommand($sql)->execute();
  1880. echo $examName.'zip生成失败!'. "\n";
  1881. }
  1882. }else{
  1883. if($error){
  1884. $time = time();
  1885. $sql = "update download_table_setting set error_msg='".implode(",",$error)."',update_time = {$time} where id = {$v_data['id']}";
  1886. $this->conn->createCommand($sql)->execute();
  1887. }
  1888. }
  1889. // $this->conn->active = false;
  1890. }
  1891. }catch(Exception $e){
  1892. $sql = "update download_table_setting set status=3,error_msg='系统异常' where id = {$v_data['id']}";
  1893. $this->conn->createCommand($sql)->execute();
  1894. echo $e->getMessage();
  1895. }
  1896. }
  1897. }else{
  1898. echo "暂无要生成的数据\n";
  1899. }
  1900. $this->conn->active = false;
  1901. }else{
  1902. echo "连接业务库失败\n";
  1903. }
  1904. }
  1905. function characet($data){
  1906. if( !empty($data) ){
  1907. $fileType = mb_detect_encoding($data , array('UTF-8','GBK','LATIN1','BIG5')) ;
  1908. if( $fileType != 'UTF-8'){
  1909. $data = mb_convert_encoding($data ,'utf-8' , $fileType);
  1910. }
  1911. }
  1912. return $data;
  1913. }
  1914. public function apiPost($path, $arr, $type = 0)
  1915. {
  1916. $ch = @curl_init();
  1917. $result = FALSE;
  1918. if ($ch) {
  1919. $data = json_encode($arr);
  1920. $url = Yii::app()->params['api'][$type]['prefix'] . $path;
  1921. $username = Yii::app()->params['api'][$type]['username'];
  1922. $password = Yii::app()->params['api'][$type]['password'];
  1923. // Digest认证
  1924. curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  1925. curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);
  1926. // 不输出头部
  1927. curl_setopt($ch, CURLOPT_HEADER, 0);
  1928. // curl_exec 获取到的内容不直接输出, 而是返回
  1929. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1930. // 请求重启路由器的地址 传参 进行重启
  1931. curl_setopt($ch, CURLOPT_URL, $url);
  1932. curl_setopt($ch, CURLOPT_USERAGENT, 'Api Client/1.0.0 (chengfei@liancaitech.com)');
  1933. curl_setopt($ch, CURLOPT_POST, 1);
  1934. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  1935. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  1936. 'Content-Type: application/json',
  1937. 'Content-Length: ' . strlen($data),
  1938. ));
  1939. if (!curl_errno($ch)) {
  1940. $result = json_decode(curl_exec($ch));
  1941. }
  1942. // 释放资源
  1943. curl_close($ch);
  1944. }
  1945. return $result;
  1946. }
  1947. public function aipost($url, $array = array(), $timeout = 5, $type = 0)
  1948. {
  1949. $url = Yii::app()->params['api'][$type]['prefix'] . $url;
  1950. $username = Yii::app()->params['api'][$type]['username'];
  1951. $password = Yii::app()->params['api'][$type]['password'];
  1952. $ch = curl_init();
  1953. curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
  1954. curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
  1955. curl_setopt($ch, CURLOPT_URL, $url);
  1956. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1957. curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  1958. curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);
  1959. if ($array) {
  1960. $array = http_build_query($array);
  1961. curl_setopt($ch, CURLOPT_POSTFIELDS, $array);
  1962. }
  1963. //curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  1964. $data = curl_exec($ch);
  1965. if (!curl_errno($ch)) {
  1966. $result = json_decode($data, 1);
  1967. return $result;
  1968. }
  1969. curl_close($ch);
  1970. return false;
  1971. }
  1972. private function check_zip($file_path) {
  1973. if (substr($file_path, strlen($file_path) - 4, 4) == ".zip") {
  1974. if (file_exists($file_path)) {
  1975. return true;
  1976. }
  1977. }
  1978. return false;
  1979. }
  1980. /**
  1981. * 获取接口数据
  1982. * @param $url
  1983. * @param $method
  1984. * @param array $params
  1985. * @return array
  1986. */
  1987. private function getHttp($url,$method,$params = array()){
  1988. $res = http($url, $method, $this->authUsername, $params);
  1989. $res = $this->handleRes($res);
  1990. return $res;
  1991. }
  1992. /**
  1993. * 处理接口返回的数据
  1994. * @param $res
  1995. * @return array
  1996. */
  1997. public function handleRes($res){
  1998. $result = array(
  1999. 'status' => 0,
  2000. 'data' => array(),
  2001. 'msg' => '暂无数据',
  2002. );
  2003. if($res){
  2004. $res = json_decode($res,true);
  2005. if(isset($res['errCode']) && $res['errCode'] == '00'){
  2006. $result['status'] = 1;
  2007. $result['data'] = isset($res['data'])?$res['data']:array();
  2008. $result['msg'] = $res['errMsg'];
  2009. }else{
  2010. if(isset($res['errMsg'])){
  2011. $result['msg'] = $res['errMsg'];
  2012. }
  2013. }
  2014. }
  2015. unset($res);
  2016. return $result;
  2017. }
  2018. function file_exists($url)
  2019. {
  2020. $ch = curl_init();
  2021. $timeout = 10;
  2022. curl_setopt($ch, CURLOPT_URL, $url);
  2023. curl_setopt($ch, CURLOPT_HEADER, 1);
  2024. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  2025. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  2026. $contents = curl_exec($ch);
  2027. if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == 404) {
  2028. return false;
  2029. }
  2030. return true;
  2031. // $ch = curl_init();
  2032. // curl_setopt ($ch, CURLOPT_URL, $url);
  2033. // //不下载
  2034. // curl_setopt($ch, CURLOPT_NOBODY, 1);
  2035. // //设置超时
  2036. // curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 3);
  2037. // curl_setopt($ch, CURLOPT_TIMEOUT, 3);
  2038. // //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  2039. // curl_exec($ch);
  2040. // $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  2041. // if($http_code == 200) {
  2042. // return true;
  2043. // }
  2044. // return false;
  2045. }
  2046. public function viewRender($viewName, $data)
  2047. {
  2048. extract($data, EXTR_PREFIX_SAME,'data');
  2049. ob_start();
  2050. ob_implicit_flush(0);
  2051. require(dirname(dirname(dirname(__FILE__))).'/protected/views/export/'.$viewName . '.php');
  2052. return ob_get_clean();
  2053. }
  2054. public function getDbConnection($database_host,$database_name,$database_user,$database_password)
  2055. {
  2056. if($database_host && $database_name && $database_user && $database_password){
  2057. $myDbDsn = 'mysql:host=' . $database_host . ';dbname=' . $database_name;
  2058. $my_connection = new CDbConnection($myDbDsn, $database_user, $database_password);
  2059. $my_connection->emulatePrepare = true;
  2060. $my_connection->enableProfiling = true;
  2061. $my_connection->enableParamLogging = true;
  2062. $myDbDsn = null;
  2063. return $my_connection;
  2064. }else{
  2065. return null;
  2066. }
  2067. }
  2068. private function img_process($img)
  2069. {
  2070. $widthArr = array();
  2071. $heightArr = array();
  2072. $width = '';
  2073. $height = '';
  2074. if (preg_match('/[\s\'"]width\s*:\s*(\d+\.*\d*)\s*([a-zA-Z]+)*/si',$img,$widthArr)) {
  2075. $width = $this->length_process($widthArr);
  2076. } else {
  2077. if (preg_match('/[\s\'"]width\s*=\s*[\'"]\s*(\d+\.*\d*)\s*([a-zA-Z]+)*;?[\'"]/si',$img,$widthArr)) {
  2078. $width = $this->length_process($widthArr);
  2079. }
  2080. }
  2081. if ($width) {
  2082. $width = "width=".$width;
  2083. }
  2084. if (preg_match('/[\s\'"]height\s*:\s*(\d+\.*\d*)\s*([a-zA-Z]+)*/si',$img,$heightArr)) {
  2085. $height = $this->length_process($heightArr);
  2086. } else {
  2087. if (preg_match('/[\s\'"]height\s*=\s*[\'"]\s*(\d+\.*\d*)\s*([a-zA-Z]+)*;?[\'"]/si',$img,$heightArr)) {
  2088. $height = $this->length_process($heightArr);
  2089. }
  2090. }
  2091. if ($height) {
  2092. $height = "height=".$height;
  2093. }
  2094. $return_img = preg_replace('/<img[^>]*[\s]+(src[\s]*=[\s]*(([\"]([^\"]*)[\"])|([\']([^\']*)[\'])|([^\s]*)))([^>]*>)/si',"<img ".$width." ".$height." $1 />",$img);
  2095. return $return_img;
  2096. }
  2097. private function length_process($length_arr){
  2098. $length = 0.6*$length_arr[1];
  2099. $unit_keys = array_keys($this->units);
  2100. if (isset($length_arr[2])) {
  2101. //将直接连接单位改为 单位换算
  2102. if(in_array($length_arr[2],$unit_keys)){
  2103. $length = $length*$this->units[$length_arr[2]];
  2104. }else {
  2105. $length .= $length_arr[2];
  2106. }
  2107. }
  2108. return $length;
  2109. }
  2110. public function getCodeByExamId($examId){
  2111. $code = 0;
  2112. $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}'";
  2113. $data_sem = $this->sConn->createCommand($sql)->queryRow();
  2114. if($data_sem && $data_sem['status'] != 1){
  2115. $code = $data_sem['refer_code']?$data_sem['refer_code']:0;
  2116. }
  2117. return $code;
  2118. }
  2119. private function check_pdf($pdf_path) {
  2120. if (substr($pdf_path, strlen($pdf_path) - 4, 4) == ".pdf") {
  2121. if (file_exists($pdf_path)) {
  2122. return true;
  2123. }
  2124. }
  2125. return false;
  2126. }
  2127. function get_version($class_id)
  2128. {
  2129. if($class_id){
  2130. $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;
  2131. $product_res = $this->sConn->createCommand($sql)->queryRow();
  2132. if (!$product_res) { //没有找到班级与设置的关系表
  2133. $sql = 'select wb_isp_version from class where class_id='.$class_id;
  2134. $res = $this->sConn->createCommand($sql)->queryRow();
  2135. return $res['wb_isp_version'];
  2136. } else {
  2137. if ($product_res['set_type'] == 1) { //如果是错题本,还是找以前的配置
  2138. $sql = 'select wb_isp_version from class where class_id='.$class_id;
  2139. $res = $this->sConn->createCommand($sql)->queryRow();
  2140. return $res['wb_isp_version'];
  2141. } else{
  2142. return $product_res['show_level'];
  2143. }
  2144. }
  2145. }
  2146. return 0;
  2147. }
  2148. function get_level_rule($class_id)
  2149. {
  2150. if($class_id){
  2151. $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;
  2152. $product_res = $this->sConn->createCommand($sql)->queryRow();
  2153. if (!$product_res) { //没有找到班级与设置的关系表
  2154. return 0;
  2155. } else {
  2156. return $product_res['level_rule'];
  2157. }
  2158. }
  2159. return 0;
  2160. }
  2161. function transferOrders($paperIds,$is_qxk=0)
  2162. {
  2163. $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';
  2164. $paper_topcic_relation_res = $this->sConn->createCommand($sql)->queryAll();
  2165. $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).')' ;
  2166. $tpl_index_res = $this->sConn->createCommand($sql)->queryAll();
  2167. $tpl_index_arr = array();
  2168. $changeDoToicNo = $tpl_data_arr = array();
  2169. foreach ($tpl_index_res as $v) {
  2170. $tpl_index_arr[$v['paper_id']] = $v['tpl_index'];
  2171. if($v['tpl_data']){
  2172. $v['tpl_data'] = preg_replace('/:\s*(-?\d{15,})/', ': "$1"', $v['tpl_data']);//把15位的int转成string
  2173. $tplData = json_decode($v['tpl_data'],true);
  2174. if($tplData){
  2175. $tplstatus = 0;
  2176. if(isset($tplData['tplstatus'])){
  2177. $tpl_data_arr[$v['paper_id']] = $tplData['tplstatus'];
  2178. }else{
  2179. $tpl_data_arr[$v['paper_id']] = 0;
  2180. }
  2181. }
  2182. }
  2183. //选做题题号
  2184. if (isset($tplData['new_items']) && $tplData['new_items']) {
  2185. $new_items = array_values($tplData['new_items']);
  2186. foreach ($new_items as $key => &$item) {
  2187. if (isset($item['sameAliasNo']) && $item['sameAliasNo']>0) {
  2188. $no =$item['alias'];
  2189. $item['topicId'] = (string)$item['topicId'];
  2190. $changeDoToicNo[$v['paper_id']]["list"][$item['topicId']]["sameAliasNo"] = $item['sameAliasNo'];//选做题组id
  2191. $changeDoToicNo[$v['paper_id']]["list"][$item['topicId']]["smTopicLen"] = $item['smTopicLen'];//选做题组必做数量
  2192. $changeDoToicNo[$v['paper_id']]["list"][$item['topicId']]["no"] = $no;//题号
  2193. $changeDoToicNo[$v['paper_id']]["list"][$item['topicId']]["topicId"] = $item['topicId'];//题目id
  2194. $changeDoToicNo[$v['paper_id']]["gather"][$item['sameAliasNo']][]=$item['topicId'];
  2195. }
  2196. }
  2197. }
  2198. }
  2199. $paper_topcic_relation_arr = array();
  2200. foreach ( $paper_topcic_relation_res as $v) {
  2201. $paper_id = $v['paper_id'];
  2202. $type = $v['type'];
  2203. $order = $v['order'];
  2204. $topic_id = $v['topic_id'];
  2205. $stem_id = (string)$v['stem_id'];
  2206. if (!isset($paper_topcic_relation_arr[$paper_id])) {
  2207. $paper_topcic_relation_arr[$paper_id] = array();
  2208. }
  2209. $paper_topcic_relation_arr[$paper_id][] = array(
  2210. 'type' => $type,
  2211. 'order' => $order,
  2212. 'topic_id'=>$topic_id,
  2213. 'stem_id'=>$stem_id
  2214. );
  2215. }
  2216. $paper_topic_no_arr = array();
  2217. foreach ($paper_topcic_relation_arr as $paper_id => $paper_topic_relation) {
  2218. $tpl_index = $tpl_index_arr[$paper_id];
  2219. $tplstatus = isset($tpl_data_arr[$paper_id])?$tpl_data_arr[$paper_id]:0;
  2220. $change_do_toicno = isset($changeDoToicNo[$paper_id])?$changeDoToicNo[$paper_id]:array();
  2221. $paper_topic_no_arr[$paper_id] =$this->topic_number($paper_topic_relation,$tpl_index,$tplstatus,$is_qxk,$change_do_toicno);
  2222. }
  2223. return $paper_topic_no_arr;
  2224. }
  2225. function topic_number($paper_topcic_relation_arr, $tpl_index,$tplstatus,$is_qxk=0,$change_do_toicno=array())
  2226. {
  2227. $topic_no_arr = array(); //每道题的序号
  2228. if($is_qxk){
  2229. $_order = 1;
  2230. $small_no = 1;
  2231. $temp_stem_arr = array();
  2232. foreach($paper_topcic_relation_arr as $v){
  2233. if(isset($v['stem_id']) && $v['stem_id']){
  2234. $temp_stem_arr[$v['stem_id']][] = $v['topic_id'];
  2235. }
  2236. }
  2237. foreach ($paper_topcic_relation_arr as $v) {
  2238. if(!isset($temp_stem_arr[$v['stem_id']]) || count($temp_stem_arr[$v['stem_id']]) == 1){
  2239. if(!empty($change_do_toicno["list"]) && isset($change_do_toicno["list"][$v['topic_id']]) &&
  2240. count($change_do_toicno["gather"][$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]])>1) {//判断是否选做题
  2241. if (isset($change_no_arr[$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]])) {
  2242. $change_no = $change_no_arr[$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]];
  2243. } else {
  2244. $change_no = 65;//从A开始
  2245. }
  2246. $topic_no_arr[$v['topic_id']] = $_order . chr($change_no);
  2247. $change_no_arr[$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]] = $change_no +1;
  2248. }else{
  2249. $topic_no_arr[$v['topic_id']] = $_order;
  2250. $_order++;
  2251. }
  2252. $small_no = 1;
  2253. }else{
  2254. if(!empty($change_do_toicno["list"]) && isset($change_do_toicno["list"][$v['topic_id']]) &&
  2255. count($change_do_toicno["gather"][$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]])>1) {//判断是否选做题
  2256. if(isset($change_no_arr[$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]])){
  2257. $change_no = $change_no_arr[$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]];
  2258. }else{
  2259. $change_no = 65;//从A开始
  2260. }
  2261. $_order = $_order . chr($change_no);
  2262. }
  2263. $topic_no_arr[$v['topic_id']] = $_order.'('.$small_no.')';
  2264. if($small_no == count($temp_stem_arr[$v['stem_id']])){
  2265. $small_no = 1;
  2266. $_order++;
  2267. }
  2268. $small_no++;
  2269. }
  2270. }
  2271. }else if ($tpl_index == 10 || $tpl_index == 1010 || $tplstatus == 3 || $tplstatus == 4) { //10,1010 表示江苏那个有a,b,c,d选做题的模板,编号不能按表里的编号来
  2272. $prefix_no = 0;
  2273. $num = 0;
  2274. $index_arr = array('A','B','C','D','E');
  2275. $_order = 0;
  2276. foreach($paper_topcic_relation_arr as $v) {
  2277. if (!$prefix_no && $v['type'] == 17) {
  2278. $_order += 1; //序号加1
  2279. $prefix_no = $_order;
  2280. $topic_no_arr[$v['topic_id']] = $prefix_no.'A';
  2281. } elseif ($prefix_no && $v['type'] == 17) {
  2282. $num += 1;
  2283. $topic_no_arr[$v['topic_id']] = $prefix_no.$index_arr[$num];
  2284. }
  2285. if ($v['type'] == 27) {
  2286. $prefix_no += 1;
  2287. $topic_no_arr[$v['topic_id']] = $prefix_no;
  2288. }
  2289. if ($v['type'] != 17 && $v['type'] != 27){
  2290. $_order += 1;
  2291. $topic_no_arr[$v['topic_id']] = $_order;
  2292. }
  2293. }
  2294. } else { //其他模板都是根据order就行
  2295. $_order = 0;
  2296. foreach ($paper_topcic_relation_arr as $v) {
  2297. if(!empty($change_do_toicno["list"]) && isset($change_do_toicno["list"][$v['topic_id']]) &&
  2298. count($change_do_toicno["gather"][$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]])>1) {//判断是否选做题
  2299. if (isset($change_no_arr[$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]])) {
  2300. $change_no = $change_no_arr[$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]];
  2301. } else {
  2302. $change_no = 65;//从A开始
  2303. $_order += 1;
  2304. }
  2305. $topic_no_arr[$v['topic_id']] = $_order . chr($change_no);
  2306. $change_no_arr[$change_do_toicno["list"][$v['topic_id']]["sameAliasNo"]] = $change_no + 1;
  2307. }else{
  2308. $_order += 1;
  2309. $topic_no_arr[$v['topic_id']] = $_order;
  2310. }
  2311. }
  2312. }
  2313. return $topic_no_arr;
  2314. }
  2315. private function topicProcess($html) {
  2316. if (preg_match_all('/(<img[^>]*[\s]+)((src)[\s]*=[\s]*(([\"]([^\"]*)[\"])|([\']([^\']*)[\'])|([^\s]*)))([^>]*>)/si', $html, $arr)) {
  2317. foreach ($arr[0] as $v) {
  2318. $process_str = $this->img_process($v);
  2319. ;
  2320. $html = str_replace($v, $process_str, $html);
  2321. }
  2322. }
  2323. $html = preg_replace('/style\s*=\s*(([\"]([^\"]*)[\"])|([\']([^\']*)[\']))/si', '', $html);
  2324. $html = preg_replace('/<p\s*>/', '', $html);
  2325. $html = preg_replace('/<\/p>/', '', $html);
  2326. $html = preg_replace('/<br\/*>/', '', $html);
  2327. $html = preg_replace('/<big\s*>/', '', $html);
  2328. $html = preg_replace('/<\/big>/', '', $html);
  2329. $html = str_replace("&nbsp;", '', $html);
  2330. //将图片地址改成二进制地址
  2331. return $html;
  2332. if(preg_match_all("/http:\/\/zxhx[\s\S]*?png/i",$html,$matches)){
  2333. $need_replace = array();
  2334. foreach($matches[0] as $v){
  2335. //$image_info = getimagesize($v);
  2336. $er = 'data:image/png;base64,' . chunk_split(base64_encode(file_get_contents($v)));
  2337. $need_replace[] = array(
  2338. "origin_url" => $v,
  2339. "after_url" => $er
  2340. );
  2341. }
  2342. unset($matches);
  2343. if($need_replace){
  2344. foreach($need_replace as $v){
  2345. $html = str_replace($v["origin_url"],$v["after_url"],$html);
  2346. }
  2347. unset($need_replace);
  2348. }
  2349. }
  2350. return $html;
  2351. }
  2352. private function getTopicNoByPaper($paper_topcic_relation_arr, $tpl_index)
  2353. {
  2354. $topic_no_arr = array(); //每道题的序号
  2355. if ($tpl_index == 10 || $tpl_index == 1010) { //10,1010 表示江苏那个有a,b,c,d选做题的模板,编号不能按表里的编号来
  2356. $prefix_no = 0;
  2357. $num = 0;
  2358. $index_arr = array('A','B','C','D','E');
  2359. foreach($paper_topcic_relation_arr as $v) {
  2360. if (!$prefix_no && $v['type'] == 17) {
  2361. $prefix_no = $v['no'];
  2362. $topic_no_arr[$v['topic_id']] = $prefix_no.'A';
  2363. } elseif ($prefix_no && $v['type'] == 17) {
  2364. $num += 1;
  2365. $topic_no_arr[$v['topic_id']] = $prefix_no.$index_arr[$num];
  2366. }
  2367. if ($v['type'] == 27) {
  2368. $prefix_no += 1;
  2369. $topic_no_arr[$v['topic_id']] = $prefix_no;
  2370. }
  2371. if ($v['type'] != 17 && $v['type'] != 27){
  2372. $topic_no_arr[$v['topic_id']] = $v['no'];
  2373. }
  2374. }
  2375. } else {
  2376. foreach ($paper_topcic_relation_arr as $v) {
  2377. $topic_no_arr[$v['topic_id']] = $v['no'];
  2378. }
  2379. }
  2380. return $topic_no_arr;
  2381. }
  2382. private function paperTopicDetail($yun_id_arr, $sch_id_arr, $exam_id, $typestr) {
  2383. try {
  2384. $all_id_arr = array_merge($yun_id_arr,$sch_id_arr);
  2385. if (!$all_id_arr ) {
  2386. return false;
  2387. }
  2388. $data = array();
  2389. $total_count = count($all_id_arr);
  2390. $page_size = 100;
  2391. $page = ceil($total_count/$page_size);
  2392. for ($i = 0; $i<$page; $i++) {
  2393. $offset = $i * $page_size;
  2394. $id_arr = array_slice($all_id_arr,$offset, $page_size);
  2395. $topicBatchs = $this->apiPost('topic/batchall', array('topicIds' => $id_arr));
  2396. if (!$topicBatchs) {
  2397. throw new Exception('获取接口topic/batchALL数据时无任何返回,type is '.$typestr.' ,exam_id is ('.$exam_id.')');
  2398. }if(isset($topicBatchs->status) && $topicBatchs->status == 0 ){
  2399. throw new Exception($topicBatchs->error[0]);
  2400. } else{
  2401. $data += $this->formatDetails($topicBatchs);
  2402. }
  2403. }
  2404. return $data;
  2405. } catch (Exception $e) {
  2406. return false;
  2407. }
  2408. }
  2409. public function formatDetails($topicBatches) {
  2410. $optionIndex = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K');
  2411. $topicDetails = array();
  2412. foreach ($topicBatches AS $ke=>$topic) {
  2413. if(!isset($topic["teacher_tips"]) || !$topic["teacher_tips"]){
  2414. $topicBatches[$ke]["teacher_tips"] = $this->dealTeacherTips($topic);
  2415. }
  2416. $topic = (object) $topic;
  2417. $topic->id = (string)$topic->id;
  2418. $type = $topic->type_id;
  2419. 6 == $type && $type = 5; //6表示多空题,多空题也是5
  2420. $topicDetails[$topic->id] = array();
  2421. $topicDetails[$topic->id]['type'] = $type;
  2422. $topicDetails[$topic->id]['methods'] = ''; //考点
  2423. $topicDetails[$topic->id]['method_id_arr'] = ''; //考点id数组
  2424. $topicDetails[$topic->id]['kps'] = ''; //知识点
  2425. $topicDetails[$topic->id]['queBody'] = $this->topicProcess($topic->title); //题目详情
  2426. $topicDetails[$topic->id]['options'] = '';
  2427. $topicDetails[$topic->id]['parse_video_qrcode'] = isset($topic->parse_video_qrcode) ? $topic->parse_video_qrcode : '';
  2428. $topicDetails[$topic->id]['answer'] = ''; //每题的正确答案
  2429. $topicDetails[$topic->id]['analysis'] = $this->topicProcess($topic->parse_content); //答题解析
  2430. $topicDetails[$topic->id]['teacher_tips'] = $this->topicProcess($topic->teacher_tips); //名师点评
  2431. $topicDetails[$topic->id]['difficulty_degree'] = isset($topic->difficulty_degree) ? $topic->difficulty_degree : null;
  2432. $topicDetails[$topic->id]['difficulty'] = $topic->difficulty;
  2433. $topicDetails[$topic->id]['type_name'] = $topic->type_name;
  2434. $topicDetails[$topic->id]['source'] = $topic->source;
  2435. $_methods = array();
  2436. $_method_id_arr = array();
  2437. if ($topic->specials) {
  2438. foreach ($topic->specials AS $_method) {
  2439. $_method = (object) $_method;
  2440. if ($_method->method_name) {
  2441. $_methods[] = $_method->method_name;
  2442. }
  2443. if (isset($_method->method_id)) {
  2444. $_method_id_arr[] = $_method->method_id;
  2445. }
  2446. }
  2447. $topicDetails[$topic->id]['methods'] = implode('|', array_unique($_methods)); //考点
  2448. $topicDetails[$topic->id]['method_id_arr'] = $_method_id_arr;
  2449. }
  2450. $_kps = array();
  2451. if (isset($topic->kps) && $topic->kps) {
  2452. foreach ($topic->kps as $_kp) {
  2453. $_kp = (object) $_kp;
  2454. if ($_kp->kp_name) {
  2455. $_kps[$_kp->kp_id] = $_kp->kp_name;
  2456. }
  2457. }
  2458. $topicDetails[$topic->id]['kps'] = $_kps; //考点
  2459. }
  2460. if ($topic->type_id == 1 || $topic->type_id == 2) { //选择题有选项
  2461. if ($topic->items) {
  2462. if (isset($topic->items[0])) {
  2463. $topic->items[0] = (object) $topic->items[0];
  2464. if (isset($topic->items[0]->options)) {
  2465. $options = $topic->items[0]->options;
  2466. if ($options) {
  2467. $_tmp_options = array();
  2468. $anwer_str = "";
  2469. foreach ($options AS $_optionIndex => $_option) {
  2470. $_option = (object) $_option;
  2471. $_tmp_options[$_optionIndex] = $this->topicProcess($_option->option_content);
  2472. if ($_option->option_correct) {
  2473. if($anwer_str == ""){
  2474. $anwer_str = $this->topicProcess($optionIndex[$_optionIndex]);
  2475. // $topicDetails[$topic->id]['answer'] = $this->topicProcess($optionIndex[$_optionIndex]);
  2476. }else{
  2477. $anwer_str .= "、".$this->topicProcess($optionIndex[$_optionIndex]);
  2478. }
  2479. }
  2480. }
  2481. $topicDetails[$topic->id]['answer'] = $anwer_str;
  2482. $topicDetails[$topic->id]['answer_format'] = str_replace('、', '', $anwer_str);
  2483. $_list_type = (int) $topic->items[0]->list_type;
  2484. $topicDetails[$topic->id]['options'] = $this->option_process($_tmp_options, $_list_type);
  2485. }
  2486. }
  2487. }
  2488. }
  2489. } else {
  2490. if ($topic->items) {
  2491. if (isset($topic->items[0])) {
  2492. $topic->items[0] = (object) $topic->items[0];
  2493. if (isset($topic->items[0]->options)) {
  2494. $options = $topic->items[0]->options;
  2495. if ($options) {
  2496. $_answer = '';
  2497. foreach ($options as $v) {
  2498. $_option = (object) $v;
  2499. if (trim($_answer) != '') {
  2500. $_answer .= ' ; ';
  2501. }
  2502. $_answer .= $_option->option_content;
  2503. }
  2504. $topicDetails[$topic->id]['answer'] = $this->topicProcess($_answer);
  2505. }
  2506. }
  2507. }
  2508. }
  2509. }
  2510. }
  2511. return $topicDetails;
  2512. }
  2513. private function option_process($options, $list_type) {
  2514. $option_index = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
  2515. if ($list_type == 0) { //纵向排列,即1行1个
  2516. $option_str = "";
  2517. foreach ($options as $key => $option) {
  2518. $option_str.="<li class='fl lis-one'>$option_index[$key].$option</li>";
  2519. }
  2520. } elseif ($list_type == 1) { //横向排列,即1行4个
  2521. $option_str = "";
  2522. foreach ($options as $key => $option) {
  2523. $option_str.="<li class='fl lis-four'>$option_index[$key].$option</li>";
  2524. }
  2525. } elseif ($list_type == 2) { //1行2个
  2526. $option_str = "";
  2527. foreach ($options as $key => $option) {
  2528. if ($key % 2 == 0) {
  2529. $option1 = $options[$key];
  2530. $option_str2 = "<li class='fl lis-two'>$option_index[$key].$option1</li>";
  2531. $key1 = $key + 1;
  2532. if (isset($options[$key1])) {
  2533. $option2 = $options[$key1];
  2534. $option_str2.="<li class='fl lis-two'>$option_index[$key1].$option2</li>";
  2535. }
  2536. $option_str.=$option_str2;
  2537. } else {
  2538. continue;
  2539. }
  2540. }
  2541. }
  2542. return $option_str;
  2543. }
  2544. public function numToUpper($number)
  2545. {
  2546. $number = substr($number, 0, 2);
  2547. $arr = array('零', '一', '二', '三', '四', '五', '六', '七', '八', '九');
  2548. if (strlen($number) == 1) {
  2549. $result = $arr[$number];
  2550. } else {
  2551. if ($number == 10) {
  2552. $result = '十';
  2553. } else {
  2554. if ($number < 20) {
  2555. $result = '十';
  2556. } else {
  2557. $result = $arr[substr($number, 0, 1)] .'十';
  2558. }
  2559. if (substr($number, 1, 1) != '0') {
  2560. $result .= $arr[substr($number, 1, 1)];
  2561. }
  2562. }
  2563. }
  2564. return $result;
  2565. }
  2566. public function numToLetter($number)
  2567. {
  2568. $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');
  2569. $number = (int)$number;
  2570. $result = '';
  2571. if ($number >= 1 AND $number <= 26) {
  2572. $result = $letters[$number - 1];
  2573. }
  2574. return $result;
  2575. }
  2576. //远程路径,名称,文件后缀
  2577. function downImgRar($url,$rename,$name){
  2578. $ch = curl_init($url);
  2579. curl_setopt($ch, CURLOPT_HEADER, 0);
  2580. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  2581. curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
  2582. $rawdata=curl_exec ($ch);
  2583. curl_close ($ch);
  2584. // 使用中文文件名需要转码
  2585. $fp = fopen($rename.$name.".pdf",'w');
  2586. fwrite($fp, $rawdata);
  2587. fclose($fp);
  2588. // 返回路径
  2589. return $rename.$name.".pdf";
  2590. }
  2591. /**
  2592. * 教师讲案高考真题
  2593. * @exam_id 考试ID
  2594. * @class_id 班级ID
  2595. * @has_topic 教师讲案其他题集合
  2596. * @weak_methodids 共性题考点
  2597. * @paper_methodids 试卷考点
  2598. */
  2599. function acadGaokao($exam_id,$class_id,$has_topic,$weak_methodids,$paper_methodids){
  2600. //最终抽出来的题
  2601. $final_topic = array();
  2602. if(!$weak_methodids){
  2603. return $final_topic;
  2604. }else{
  2605. $topic_data = $this->aipost('/relation_math/true_topic', array('methodIds' => $weak_methodids));
  2606. if($topic_data && isset($topic_data['data']) && $topic_data['data']){
  2607. $topic_pool = $topic_data['data'];
  2608. }else{
  2609. return $final_topic;
  2610. }
  2611. }
  2612. //step1 过滤已经存在的题
  2613. if($has_topic){
  2614. foreach($topic_pool as $k=>$v){
  2615. if(in_array($k,$has_topic)){
  2616. unset($topic_pool[$k]);
  2617. }
  2618. }
  2619. }
  2620. //step2 过滤超纲的题
  2621. if($paper_methodids){
  2622. foreach($topic_pool as $k=>$v){
  2623. foreach($v as $method){
  2624. if(!in_array($method,$paper_methodids)){
  2625. unset($topic_pool[$k]);
  2626. continue;
  2627. }
  2628. }
  2629. }
  2630. }
  2631. //step3 优先抽全部薄弱考点的题,如果题不够,逐一减少薄弱考点,直到抽到2题为止 $weak_methodids(薄弱考点)
  2632. if($topic_pool){
  2633. //整理数据
  2634. $topic_methods_count = array();//题目对应薄弱考点数量
  2635. $count_to_topic = array();//薄弱考点数量对应题目
  2636. foreach($topic_pool as $k=>$v){
  2637. foreach($v as $method){
  2638. if(in_array($method,$weak_methodids)){
  2639. if(!isset($topic_methods_count[$k])){
  2640. $topic_methods_count[$k] = 1;
  2641. }else{
  2642. $topic_methods_count[$k] ++;
  2643. }
  2644. }
  2645. }
  2646. }
  2647. if($topic_methods_count){
  2648. foreach($topic_methods_count as $k=>$v){
  2649. for($a=1;$a<=$v;$a++){
  2650. if(!isset($count_to_topic[$a])){
  2651. $count_to_topic[$a] = array();
  2652. }
  2653. $count_to_topic[$a][] = $k;
  2654. }
  2655. }
  2656. }
  2657. if($count_to_topic){
  2658. krsort($count_to_topic);//根据薄弱考点数量倒序
  2659. foreach($count_to_topic as $k=>$v){
  2660. foreach($v as $topic_id){
  2661. if(count($final_topic) > 1){
  2662. break;
  2663. }
  2664. if(!in_array($topic_id,$final_topic)){
  2665. $final_topic[] = $topic_id;
  2666. }
  2667. }
  2668. }
  2669. }
  2670. }
  2671. //过滤完没题就随机抽两题
  2672. if(!$final_topic || count($final_topic) < 2){
  2673. $topic_keys = array_keys($topic_pool);
  2674. shuffle($topic_keys);
  2675. foreach($topic_keys as $k=>$v){
  2676. if(count($final_topic) > 1){
  2677. break;
  2678. }
  2679. if(!in_array($v,$final_topic)){
  2680. $final_topic[] = $v;
  2681. }
  2682. }
  2683. }
  2684. //插入数据
  2685. if($final_topic){
  2686. $delSql = "delete from gaokao_academicr_topic where exam_id = '".$exam_id."'";
  2687. $insertSql="insert into gaokao_academicr_topic (`exam_id`,`class_id`,`topic_id`,`create_time`) values";
  2688. $insertSqlStr = "";
  2689. foreach($final_topic as $k=>$v){
  2690. $insertSqlStr.="('".$exam_id."','".$class_id."','".$v."','".time()."'),";
  2691. }
  2692. $insertSql .= substr($insertSqlStr, 0, -1);
  2693. $this->sConn->createCommand($delSql)->execute();
  2694. $this->sConn->createCommand($insertSql)->execute();
  2695. }
  2696. return $final_topic;
  2697. }
  2698. /**
  2699. * 获取订单
  2700. */
  2701. function getOrderStu($eid, $cid, $typeVal,$relateStudentRes,$semesterId, $grade,$schoolId,$coachName)
  2702. {
  2703. $data = array();
  2704. $sql = "select semester_id,refer_code from semester where semester_id='{$semesterId}'";
  2705. $code = $this->sConn->createCommand($sql)->queryRow();
  2706. $sql = "select subject_id,create_time from exam where exam_id = '{$eid}'";
  2707. $examInfo = $this->sConn->createCommand($sql)->queryRow();
  2708. $sql = "select add_time from class_exam_printer where exam_id = '{$eid}' and class_id = '{$cid}' and type=0";
  2709. $print_time = $this->sConn->createCommand($sql)->queryRow();
  2710. if($print_time && $print_time['add_time']){
  2711. $exam_time = $print_time['add_time'];
  2712. }else{
  2713. $exam_time = $examInfo['create_time'];
  2714. }
  2715. $intarr=array(
  2716. "schoolId"=>$schoolId,
  2717. "clazzId"=>$cid,
  2718. "semester"=>$code['refer_code'],
  2719. "grade"=>$grade,
  2720. "examTime"=>$exam_time,
  2721. "students"=>array(),
  2722. "classify"=>$typeVal,
  2723. );
  2724. $intarr['subject']=$examInfo['subject_id'];
  2725. if(in_array($intarr['subject'],array(3,6,51))){
  2726. $intarr['subject']=3;
  2727. }
  2728. foreach($relateStudentRes as $key => $val){
  2729. $intarr['students'][] = $val['student_id'];
  2730. }
  2731. $basic = imsBasicAuth($schoolId.'_'.$coachName,Yii::app()->params["zsy_api_key"]);
  2732. $rs = json_decode(Curl::http_post_Basic_json(Yii::app()->params["get_limit_url"], json_encode($intarr),$basic));
  2733. if(!$rs){
  2734. //Yii::app()->jump->error("接口错误");
  2735. return false;
  2736. }
  2737. if($rs->errCode!="00"){
  2738. //Yii::app()->jump->error($rs->errMsg);
  2739. //exit();
  2740. return false;
  2741. }
  2742. if(!empty($rs->data)){
  2743. foreach($rs->data as $v){
  2744. $data['limitstu'][$v]=$v;
  2745. }
  2746. }else{
  2747. $data['limitstu']=-1;
  2748. }
  2749. return $data;
  2750. }
  2751. /**
  2752. * 获取班级设置
  2753. */
  2754. function getClassSet($classId,$semesterId){
  2755. $is_set = 0;
  2756. $temp_swich = 3;
  2757. $temp_bate = 0;
  2758. $switch_arr = array(3=>0,4=>1);
  2759. $sql = "select switch from producut_set_edition";
  2760. $switch_data = $this->sConn->createCommand($sql)->queryRow();
  2761. if($switch_data && $switch_data['switch'] && in_array($switch_data['switch'],array(3,4))){
  2762. $temp_swich = $switch_data['switch'];
  2763. $temp_bate = $switch_arr[$temp_swich];
  2764. }
  2765. if($classId && $semesterId){
  2766. $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}";
  2767. $res = $this->sConn->createCommand($sql)->queryAll();
  2768. if($res){
  2769. foreach($res as $res_k=>$res_v){
  2770. $setting_arr = array();
  2771. $setting_arr[1] = $res_v['wrong_book'];
  2772. $setting_arr[2] = $res_v['isp'];
  2773. $setting_arr[3] = $res_v['wb_isp'];
  2774. foreach($setting_arr as $k=>$v){
  2775. $sql = "select config_text from product_template where template_id = '{$v}'";
  2776. $data = $this->sConn->createCommand($sql)->queryRow();
  2777. if($data){
  2778. $json_data = $data['config_text'];
  2779. $json_data_arr = json_decode($json_data,true);
  2780. if(isset($json_data_arr['studentLevelDivide']) && isset($json_data_arr['studentLevelDivide']['isPushSameTrain']) && $json_data_arr['studentLevelDivide']['isPushSameTrain']){
  2781. $is_set = 1;
  2782. break 2;
  2783. }
  2784. }
  2785. }
  2786. }
  2787. }else{
  2788. $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}";
  2789. $data = $this->sConn->createCommand($sql)->queryAll();
  2790. if($data){
  2791. foreach($data as $k=>$v){
  2792. $json_data = $v['config_text'];
  2793. $json_data_arr = json_decode($json_data,true);
  2794. if(isset($json_data_arr['studentLevelDivide']) && isset($json_data_arr['studentLevelDivide']['isPushSameTrain']) && $json_data_arr['studentLevelDivide']['isPushSameTrain']){
  2795. $is_set = 1;
  2796. break;
  2797. }
  2798. }
  2799. }
  2800. }
  2801. }
  2802. return $is_set;
  2803. }
  2804. /**获取名师指点信息
  2805. * @param $topicInfo
  2806. * @return mixed|string
  2807. */
  2808. public function dealTeacherTips($topicInfo){
  2809. if(isset($topicInfo["teacher_tips"]) && $topicInfo["teacher_tips"]){//如果有的话直接返回
  2810. return $topicInfo["teacher_tips"];
  2811. }
  2812. //兼容全学科题目
  2813. if(!isset($topicInfo["topic_type_config"]) || empty($topicInfo["topic_type_config"]) || !isset($topicInfo["affiliate"])|| empty($topicInfo["affiliate"])){
  2814. return "";
  2815. }
  2816. $topicTypeConfig = $topicInfo["topic_type_config"];
  2817. if(is_object($topicTypeConfig)){
  2818. $topicTypeConfig = json_decode(json_encode($topicTypeConfig),true);
  2819. }
  2820. //$topicTypeConfig = json_decode($topicInfo["topic_type_config"],true);
  2821. if(!isset($topicTypeConfig["subject_custom"]) || !isset($topicTypeConfig["subject_custom"]["custom_column"])){
  2822. return "";
  2823. }
  2824. if(!isset($topicTypeConfig["subject_custom"]["custom_column"][$topicInfo["subject_id"]])){
  2825. return "";
  2826. }
  2827. $customColumnArr = $topicTypeConfig["subject_custom"]["custom_column"][$topicInfo["subject_id"]];
  2828. $field_name = "";
  2829. foreach($customColumnArr as $value){//获取题型对应的 名师指点定制标签
  2830. if(isset($value["field_describe"]) && strpos($value["field_describe"],"名师指点") !==false){
  2831. $field_name =$value["field_name"];
  2832. break;
  2833. }
  2834. }
  2835. if(!$field_name){
  2836. return "";
  2837. }
  2838. $returnTeacherTips ="";
  2839. $affiliate = $topicInfo["affiliate"];
  2840. if(is_object($affiliate)){
  2841. $affiliate = json_decode(json_encode($affiliate),true);
  2842. }
  2843. foreach($affiliate as $affValue){//获取定制标签的值
  2844. if(is_object($affValue)){
  2845. $affValue = json_decode(json_encode($affValue),true);
  2846. }
  2847. if(isset($affValue["field_key"]) && $affValue["field_key"] == $field_name){
  2848. $returnTeacherTips = isset($affValue["field_value"])?$affValue["field_value"]:"";
  2849. break;
  2850. }
  2851. }
  2852. return $returnTeacherTips;
  2853. }
  2854. }