params["default_server"]['addr'].';dbname='.Yii::app()->params["default_db"]['name'].';'; $school_dbh = new PDO($school_dsn,Yii::app()->params["default_server"]['username'],Yii::app()->params["default_server"]['password'],array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES "utf8";')); if($class_zip_id && !$school_id){ exit('请指定学校Id!'); } $school_str = ''; //测试 // $school_id = 3854; if ($school_id) { $school_str = $school_id; } else { // 获取所有可用的学校 $school_obj = $school_dbh->query('SELECT school_id FROM `school` WHERE `status`=0'); $school_info= $school_obj->fetchAll(PDO::FETCH_ASSOC); if (empty($school_info)) { exit('未找到可用的学校!'); } $school_array = array(); foreach ($school_info as $school) { array_push($school_array, $school['school_id']); } $school_str = implode(',', $school_array); } if(!$school_str){ exit('未找到学校数据库链接信息!'); } // 找出学校的链接信息 $data_obj = $school_dbh->query('SELECT * FROM `database` WHERE `school_id` IN ('.$school_str.')'); if(!$data_obj){ exit('未找到学校数据库链接信息!'); } $data_info= $data_obj->fetchAll(PDO::FETCH_ASSOC); if (empty($data_info)) { exit('未找到学校数据库链接信息!'); } $coach_obj = $school_dbh->query('select coach_id,coach_name,school_id from coach where `status` = 0 and school_id in ('.$school_str.')'); if($coach_obj){ $coach_info= $coach_obj->fetchAll(PDO::FETCH_ASSOC);//获取学管 if($coach_info){ foreach($coach_info as $k=>$v){ $coachName['school_id'] = $v['coach_name']; } } } // 关闭链接 $school_dbh = null; $my_path = dirname(dirname(dirname(__FILE__))); foreach ($data_info as $data) { echo 'STARTING==>'.$data['school_id']. "\n"; $schoolId = $data['school_id']; $temp_dsn = 'mysql:host='.$data['database_host'].';dbname='.$data['database_name'].';'; $temp_dbh = new PDO($temp_dsn,$data['database_user'],$data['database_password'],array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES "utf8";')); if(isset($coachName[$data['school_id']])){ $this->authUsername = $data['school_id'].'_'.$coachName[$data['school_id']]; } $temp_obj = $temp_dbh->query('select semester_id from semester where `status` = 1'); $temp_info= $temp_obj->fetchAll(PDO::FETCH_ASSOC);//获取当前学期 $temp_obj = $temp_dbh->query('select semester_id from semester where `status` = 1'); $temp_info= $temp_obj->fetchAll(PDO::FETCH_ASSOC);//获取当前学期 if($temp_info){ foreach($temp_info as $sem){ $semesterId = $sem['semester_id']; } if($semesterId){ if($class_zip_id){ $temp_obj = $temp_dbh->query("select class_id,class_name,report_status from class where class_id = {$class_zip_id} and semester_id = {$semesterId}"); $temp_info= $temp_obj->fetchAll(PDO::FETCH_ASSOC);//获取当前指定学校指定班级 if(!$temp_info){ exit('学校Id或班级Id错误!'); }else{ $class_info= $temp_info; } }else{ $class_obj = $temp_dbh->query("select class_id,class_name,report_status from class where semester_id = {$semesterId}"); $class_info= $class_obj->fetchAll(PDO::FETCH_ASSOC);//获取学校下的班级 } if($class_info){ foreach($class_info as $class){ // if($class['class_id'] != '25937518121715281'){ // continue; // } if(!$force){ if($class['report_status'] == 2){ continue; } } echo 'STARTING==>'.$class['class_name']. "\n"; $classId = $class['class_id']; $studentIds = array(); $pdfArr = array(); $pdfNames = array(); $stu_obj = $temp_dbh->query("select student_id from student_class_relation where class_id = {$class['class_id']} and status = 0"); $stu_info= $stu_obj->fetchAll(PDO::FETCH_ASSOC);//获取班级下的学生 if($stu_info){ if($class['report_status'] != 1){ $temp_dbh->exec("update class set report_status = 1 where class_id = {$class['class_id']}");//正在生成 } $class_name = $class['class_name'];//班级名称 foreach($stu_info as $studentId){ //初始化数据 $methodIds = array(); $bestExam = array(); $totalExamIds = array(); $totalExamIds_subjectId = array(); $exam_count = array( 9=>array(//语文 'total_count' => 0, 'real_count' => 0, 'del_count' => 0 ), 3=>array(//数学 'total_count' => 0, 'real_count' => 0, 'del_count' => 0 ), 8=>array(//英语 'total_count' => 0, 'real_count' => 0, 'del_count' => 0 ), 15=>array(//政治 'total_count' => 0, 'real_count' => 0, 'del_count' => 0 ), 16=>array(//历史 'total_count' => 0, 'real_count' => 0, 'del_count' => 0 ), 17=>array(//地理 'total_count' => 0, 'real_count' => 0, 'del_count' => 0 ), 12=>array(//物理 'total_count' => 0, 'real_count' => 0, 'del_count' => 0 ), 13=>array(//化学 'total_count' => 0, 'real_count' => 0, 'del_count' => 0 ), 14=>array(//生物 'total_count' => 0, 'real_count' => 0, 'del_count' => 0 ), 19=>array(//文综 'total_count' => 0, 'real_count' => 0, 'del_count' => 0 ), 18=>array(//理综 'total_count' => 0, 'real_count' => 0, 'del_count' => 0 ), );//考试状况 $method_mes = array( 'count' => 0, 'name' => array(), );//数学考点状况 $isp_mes = array( 'isp_days' => 0, 'isp_create' => 0, 'isp_down' => 0, 'isp_down_ratio' => 0 );//数学个性化学习宝状况 $best_exam_mes = array( 9=>array(//语文 'name' => '', 'score' => 0, 'scoring' => 0, 'grade_no' => 0, 'grade_total_no'=>0, 'class_no'=>0, 'class_total_no'=>0, ), 3=>array(//数学 'name' => '', 'score' => 0, 'scoring' => 0, 'grade_no' => 0, 'grade_total_no'=>0, 'class_no'=>0, 'class_total_no'=>0, ), 8=>array(//英语 'name' => '', 'score' => 0, 'scoring' => 0, 'grade_no' => 0, 'grade_total_no'=>0, 'class_no'=>0, 'class_total_no'=>0, ), 15=>array(//政治 'name' => '', 'score' => 0, 'scoring' => 0, 'grade_no' => 0, 'grade_total_no'=>0, 'class_no'=>0, 'class_total_no'=>0, ), 16=>array(//历史 'name' => '', 'score' => 0, 'scoring' => 0, 'grade_no' => 0, 'grade_total_no'=>0, 'class_no'=>0, 'class_total_no'=>0, ), 17=>array(//地理 'name' => '', 'score' => 0, 'scoring' => 0, 'grade_no' => 0, 'grade_total_no'=>0, 'class_no'=>0, 'class_total_no'=>0, ), 12=>array(//物理 'name' => '', 'score' => 0, 'scoring' => 0, 'grade_no' => 0, 'grade_total_no'=>0, 'class_no'=>0, 'class_total_no'=>0, ), 13=>array(//化学 'name' => '', 'score' => 0, 'scoring' => 0, 'grade_no' => 0, 'grade_total_no'=>0, 'class_no'=>0, 'class_total_no'=>0, ), 14=>array(//生物 'name' => '', 'score' => 0, 'scoring' => 0, 'grade_no' => 0, 'grade_total_no'=>0, 'class_no'=>0, 'class_total_no'=>0, ), 19=>array(//文综 'name' => '', 'score' => 0, 'scoring' => 0, 'grade_no' => 0, 'grade_total_no'=>0, 'class_no'=>0, 'class_total_no'=>0, ), 18=>array(//理综 'name' => '', 'score' => 0, 'scoring' => 0, 'grade_no' => 0, 'grade_total_no'=>0, 'class_no'=>0, 'class_total_no'=>0, ), );//最佳考试 $score_mes = array( 9=>array(//语文 'rise_count' => 0, 'drop_count' => 0, 'class_top_ten' => 0, 'unified_top_ten' => 0, ), 3=>array(//数学 'rise_count' => 0, 'drop_count' => 0, 'class_top_ten' => 0, 'unified_top_ten' => 0, ), 8=>array(//英语 'rise_count' => 0, 'drop_count' => 0, 'class_top_ten' => 0, 'unified_top_ten' => 0, ), 15=>array(//政治 'rise_count' => 0, 'drop_count' => 0, 'class_top_ten' => 0, 'unified_top_ten' => 0, ), 16=>array(//历史 'rise_count' => 0, 'drop_count' => 0, 'class_top_ten' => 0, 'unified_top_ten' => 0, ), 17=>array(//地理 'rise_count' => 0, 'drop_count' => 0, 'class_top_ten' => 0, 'unified_top_ten' => 0, ), 12=>array(//物理 'rise_count' => 0, 'drop_count' => 0, 'class_top_ten' => 0, 'unified_top_ten' => 0, ), 13=>array(//化学 'rise_count' => 0, 'drop_count' => 0, 'class_top_ten' => 0, 'unified_top_ten' => 0, ), 14=>array(//生物 'rise_count' => 0, 'drop_count' => 0, 'class_top_ten' => 0, 'unified_top_ten' => 0, ), 19=>array(//文综 'rise_count' => 0, 'drop_count' => 0, 'class_top_ten' => 0, 'unified_top_ten' => 0, ), 18=>array(//理综 'rise_count' => 0, 'drop_count' => 0, 'class_top_ten' => 0, 'unified_top_ten' => 0, ), );//成绩状况 $contin_weeks = 1;//连续周数 $student_id = (string)$studentId['student_id']; //个性化学习宝使用天数 $res = $this->getHttp('order/coach/days/'.$student_id.'/'.$year, 'get'); if($res && $res['data']){ $isp_mes['isp_days'] = $res['data']; } //获取学生姓名 $stu_name_obj = $temp_dbh->query("select realname from student_info where student_id = {$student_id}"); $stu_name_info= $stu_name_obj->fetchAll(PDO::FETCH_ASSOC);//获取学生姓名 if($stu_name_info){ foreach($stu_name_info as $realname){ $stu_name = $realname['realname']; } } //考试状况 $sql = "select e.create_time,e.name,e.exam_id,e.exam_group_id,e.subject_id,spr.is_del,spr.scoring,spr.is_isp_pdf,spr.is_wbisp_pdf,spr.is_two_isp_download,spr.is_three_isp_download,p.method_ids,p.score from exam e " . "left join exam_group eg on e.exam_group_id = eg.exam_group_id " . "left join paper p on p.exam_id = e.exam_id " . "left join student_paper_relation spr on e.exam_id = spr.exam_id " . "where spr.student_id = {$student_id} and e.status = 1 and e.upload_status = 2 and eg.status = 2 and eg.mark_status = 2 and e.create_time > {$start_time} and e.create_time < {$end_time} " . "order by e.create_time asc"; $exam_obj = $temp_dbh->query($sql); $exam_info= $exam_obj->fetchAll(PDO::FETCH_ASSOC);//获取考试情况 if($exam_info){ foreach($exam_info as $k=>$v){ //考试状况 //var_dump($v);exit; if($v['subject_id'] == 3 || $v['subject_id'] == 6){ $totalExamIds_subjectId[$v['exam_id']] = 3; $exam_count[3]['total_count'] ++; if($v['is_del'] == 1){ $exam_count[3]['del_count'] ++; }else{ $exam_count[3]['real_count'] ++; } //考点状况 $methodArr = explode(",",$v['method_ids']); if($methodArr){ foreach($methodArr as $method){ if(is_numeric($method)){ $methodIds[] = $method; } } } //个性化学习宝状况 if($v['is_isp_pdf'] == 1){ $isp_mes['isp_create'] ++; if($v['is_two_isp_download'] == 1){ $isp_mes['isp_down'] ++; } } if($v['is_wbisp_pdf'] == 1){ $isp_mes['isp_create'] ++; if($v['is_three_isp_download'] == 1){ $isp_mes['isp_down'] ++; } } //最佳考试 $bestExam[$v['exam_group_id']]['exam_id'] = $v['exam_id']; $bestExam[$v['exam_group_id']]['name'] = $v['name']; $bestExam[$v['exam_group_id']]['subject_id'] = 3; $bestExam[$v['exam_group_id']]['score'] = $v['score']; $bestExam[$v['exam_group_id']]['scoring'] = $v['scoring']; }else{ $totalExamIds_subjectId[$v['exam_id']] = $v['subject_id']; $exam_count[$v['subject_id']]['total_count'] ++; if($v['is_del'] == 1){ $exam_count[$v['subject_id']]['del_count'] ++; }else{ $exam_count[$v['subject_id']]['real_count'] ++; } //最佳考试 $bestExam[$v['exam_group_id']]['exam_id'] = $v['exam_id']; $bestExam[$v['exam_group_id']]['name'] = $v['name']; $bestExam[$v['exam_group_id']]['subject_id'] = $v['subject_id']; $bestExam[$v['exam_group_id']]['score'] = $v['score']; $bestExam[$v['exam_group_id']]['scoring'] = $v['scoring']; } //连续周数 $totalExamIds[] = $v['exam_id']; if(!isset($current_week)){ $current_week = date("W",$v['create_time']); }else{ $week_cur = date("W",$v['create_time']); if($week_cur = $current_week + 1){ $contin_weeks ++; } } } $totalExamIds = array_unique($totalExamIds); //考点状况 if($methodIds){ $count_methods = array(); foreach($methodIds as $kmed=>$vmed){ if(!isset($count_methods[$vmed])){ $count_methods[$vmed] = 1; }else{ $count_methods[$vmed]++; } } $method_mes['count'] = count(array_unique($methodIds)); unset($methodIds); if($count_methods){ arsort($count_methods); $i = 1; $methodArrIds = array(); foreach($count_methods as $k=>$v){ if($i < 6){ $methodArrIds[] = $k; } $i++; } $methods = $this->apiPost('/special/methods', array('methodIds' => $methodArrIds)); if($methods && !isset($methods->error)){ foreach($methods as $k=>$v){ $method_mes['name'][] = $v->method_name; } } } } //数学个性化学习宝状况 if($isp_mes['isp_down'] && $isp_mes['isp_create']){ $isp_mes['isp_down_ratio'] = round($isp_mes['isp_down']/$isp_mes['isp_create'],4) * 100 .'%'; } //最佳考试信息 if($bestExam){ $best_exam_msg = array(); foreach($bestExam as $k=>$v){ $examIds = array(); $examid_obj = $temp_dbh->query("select exam_id from exam where exam_group_id = {$k}"); $examid_info= $examid_obj->fetchAll(PDO::FETCH_ASSOC);////获取groupId对应的examId if($examid_info){ foreach($examid_info as $edata){ $examIds[] = $edata['exam_id']; } } if($examIds){ foreach($examIds as $examIdSc){ $msg_obj = $temp_dbh->query("select class_id,student_id,is_del,scoring from student_paper_relation where exam_id = {$examIdSc} order by scoring desc"); $msg_info= $msg_obj->fetchAll(PDO::FETCH_ASSOC); if($msg_info){ $no = 1; $no_grade = 1;//年级排名 $no_class = 1;//班级排名 $stu_no_grade = 1;//学生年级排名 $stu_no_class = 1;//学生班级排名 $total_grade = 0; $total_real_grade = 0; $total_class = 0; $total_real_class = 0; foreach($msg_info as $kk=>$vv){ if($no == 1){ $current_scoring = $vv['scoring']; }else{ if($vv['scoring'] < $current_scoring){ $no_grade ++; } } if($vv['is_del'] == 0){ $total_real_grade ++; } if((string)$vv['class_id'] === (string)$classId){ if(!isset($current_class_scoring)){ $current_class_scoring = $vv['scoring']; }else{ if($vv['scoring'] < $current_class_scoring){ $no_class ++; } } if($vv['is_del'] == 0){ $total_real_class ++; } $total_class ++; } if((string)$vv['student_id'] === (string)$student_id){ $stu_no_grade = $no_grade; $stu_no_class = $no_class; } $total_grade ++; $no++; } //最佳考试定义:数值“年级排名/年级有效人数”最小的一次考试 if(!isset($best_exam_msg[$v['subject_id']])){ if($stu_no_grade==0 || $total_real_grade==0){ $temp_min = 0; }else{ $temp_min = round($stu_no_grade/$total_real_grade,4); } if($temp_min != 0){ $best_exam_mes[$v['subject_id']]['name'] = $v['name']; $best_exam_mes[$v['subject_id']]['score'] = $v['score']; $best_exam_mes[$v['subject_id']]['scoring'] = $v['scoring']; $best_exam_mes[$v['subject_id']]['grade_no'] = $stu_no_grade; $best_exam_mes[$v['subject_id']]['grade_total_no'] = $total_grade; $best_exam_mes[$v['subject_id']]['class_no'] = $stu_no_class; $best_exam_mes[$v['subject_id']]['class_total_no'] = $total_class; } }else{ if($stu_no_grade==0 || $total_real_grade==0){ $tep = 0; }else{ $tep = round($stu_no_grade/$total_real_grade,4); } //$tep = round($stu_no_grade/$total_real_grade,4); if($tep < $temp_min && $tep!=0){ $temp_min = $tep; $best_exam_mes[$v['subject_id']]['name'] = $v['name']; $best_exam_mes[$v['subject_id']]['score'] = $v['score']; $best_exam_mes[$v['subject_id']]['scoring'] = $v['scoring']; $best_exam_mes[$v['subject_id']]['grade_no'] = $stu_no_grade; $best_exam_mes[$v['subject_id']]['grade_total_no'] = $total_grade; $best_exam_mes[$v['subject_id']]['class_no'] = $stu_no_class; $best_exam_mes[$v['subject_id']]['class_total_no'] = $total_class; } } //成绩状况(统计班级上升下降次数,班级前十) if($stu_no_class <= $total_real_class * 0.1){ $score_mes[$v['subject_id']]['class_top_ten']++; } if(!isset($current_class_no)){ $current_class_no = $stu_no_class; }else{ if($stu_no_class > $current_class_no){ $score_mes[$v['subject_id']]['rise_count']++; }else if($stu_no_class < $current_class_no){ $score_mes[$v['subject_id']]['drop_count']++; } } } unset($msg); } } } } //统考排名 $tj_obj = $temp_dbh->query("select examinfo from cylet where cylet_type = 2 and create_time > {$start_time} and create_time < {$end_time}"); $tj_info= $tj_obj->fetchAll(PDO::FETCH_ASSOC);//获取统考情况 $cylet_exam_ids = array(); if($tj_info){ foreach($tj_info as $cylet){ $cyletArr = json_decode($cylet['examinfo'],true); if(isset($cyletArr['exam'])){ foreach($cyletArr['exam'] as $examCy){ if(in_array($examCy,$totalExamIds)){ $cylet_exam_ids[] = $examCy; } } } } unset($tj_info); } if($cylet_exam_ids){ foreach($cylet_exam_ids as $cexamId){ $tempp_obj = $temp_dbh->query("select class_id,student_id,is_del,scoring from student_paper_relation where exam_id = {$cexamId} order by scoring desc"); $tempp_info= $tempp_obj->fetchAll(PDO::FETCH_ASSOC);//获取统考情况 if($tempp_info){ $no_cylet_grade = 1;//年级排名 $stu_no_cylet_grade = 1;//学生年级排名 $total_cylet_grade = 0; $total_cylet_real_grade = 0; foreach($tempp_info as $cyScore){ if($cyScore['is_del'] == 0){ $total_cylet_real_grade ++; } $total_cylet_grade ++; if(!isset($current_cylet_scoring)){ $current_cylet_scoring = $cyScore['scoring']; }else{ if($cyScore['scoring'] < $current_cylet_scoring){ $no_cylet_grade ++; } } if((string)$vv['student_id'] === (string)$studentId){ $stu_no_cylet_grade = $no_cylet_grade; } } if($stu_no_cylet_grade <= $total_cylet_real_grade * 0.1){ $score_mes[$totalExamIds_subjectId[$cexamId]]['unified_top_ten']++; } } } } } unset($exam_info); //var_dump(dirname(dirname(dirname(__FILE__))));exit; $data['stu_name'] = isset($stu_name)?$stu_name:'';//学生姓名 $data['class_name'] = isset($class_name)?$class_name:'';//班级名称 $data['year'] = $year; $data['year_next'] = $year_next; $data['days'] = $days; $data['weeks'] = $weeks; $data['contin_weeks'] = $contin_weeks; $data['exam_count'] = $exam_count;//考试状况 $data['score_mes'] = $score_mes;//成绩状况 $data['best_exam_mes'] = $best_exam_mes;//最佳考试 $data['method_mes'] = $method_mes;//考点状况 $data['isp_mes'] = $isp_mes;//个性化学习宝状况 $html = $this->viewRender("year_report", $data, true); $htmlpath = str_replace("protected", "", Yii::app()->basePath) . '/assets/'; //存放生成的HTML路径 $pdfpath = str_replace("protected", "", Yii::app()->basePath) . '/assets/pdf/yearReport/' . $schoolId . "/"; //存放生成的PDF路径 $pdfurl = '/assets/pdf/yearReport/' . $schoolId . "/"; if (!is_dir($htmlpath)) { if (!mkdir($htmlpath, 0777, true)) { exit('Create directory fail: ' . $htmlpath); } }if (!is_dir($pdfpath)) { if (!mkdir($pdfpath, 0777, true)) { exit('Create directory fail1: ' . $pdfpath); } } $htmlpath.=$student_id . ".html"; $f = fopen($htmlpath, "w"); fwrite($f, $html); $htmlurl = '/assets/' . $student_id . ".html"; //访问HTML的路径 if (Yii::app()->basePath == "C:\wamp\www\zsyas2\protected") {//本地的basePath $htmlurl = "http://zsyte.dev.xueping.com/html/%E9%A6%96%E9%A1%B5.html"; // $pdffname = str_replace(".", "。", $exam_info['class_name'] . "-" . $exam_info['exam_name']); // $pdffname = str_replace(" ", "", $pdffname) . ".pdf"; // $pdffname=iconv("UTF-8", "GBK",$pdffname); $pdffname=$classId."-".$studentId.".pdf"; $pdfpath = $pdfpath . $pdffname; $pdfurl = $pdfurl . $pdffname; $commond = Yii::app()->params['phantomjs'] . " " . Yii::app()->params['html2pdf'] . " " . " file://" . $htmlpath . " {$pdfpath}" . " 176mm*250mm ''"; } else { $htmlurl = $file_html_url . $htmlurl; // $htmlurl = "http://coa.cn/assets/25631607280893986.html"; $pdffname=$classId.'-'.$student_id.".pdf"; $pdfpath = $pdfpath . $pdffname; $pdfurl = $pdfurl . $pdffname; $top_meg = $class_name.'-'.$stu_name."-年度使用报告"; $commond = Yii::app()->params['phantomjs_server'] . " " . Yii::app()->basePath . '/../js/html2pdf.js' . " " . " {$htmlurl}" . " {$pdfpath}" . " 176mm*250mm {$top_meg}"; } $set_charset = 'export LANG=en_US.UTF-8;'; exec($set_charset.$commond, $res, $code); if(isset($res[0])){ if (strpos($res[0], 'succeed') !== false) { if ($this->file_exists($pdfpath)) { $pdfArr[] = $pdfpath; $pdfNames[] = $stu_name; echo $stu_name.'pdf生成成功!'. "\n"; } } else { } @unlink($htmlpath); } } if($pdfArr){ echo $class_name.'pdf生成成功!'. "\n"; $report_name = $class_name.$year."年度报告.zip"; $filepath = str_replace("protected", "", Yii::app()->basePath) . '/upload/year_report/'.$schoolId."/"; //存放生成的PDF路径 if (!is_dir($filepath)) { if (!mkdir($filepath, 0777, true)) { echo 'Create directory fail1: ' . $filepath. "\n"; } } $filename = dirname(dirname(dirname(__FILE__))).'/upload/year_report/'.$schoolId."/".$classId.'_'.$year.".zip"; //最终生成的文件名(含路径) $zip = new ZipArchive();//使用本类,linux需开启zlib,windows需取消php_zip.dll前的注释 if ($zip->open($filename, ZIPARCHIVE::OVERWRITE)!==TRUE) { echo $class_name.'zip生成失败!'. "\n"; }else{ foreach ($pdfArr as $k=>$val) { $pdfNames[$k] = iconv("UTF-8","GBK//IGNORE",$pdfNames[$k]); $res=$zip->addFile($val,$classId.$pdfNames[$k].'.pdf'); } $zip->close();//关闭 //生成完成 $filename = addslashes($filename); $temp_dbh->exec("update class set report_status = 2,report_url='{$filename}' where class_id = {$classId}"); echo $class_name.'zip生成成功!'. "\n"; } }else{ echo $class_name.'pdf生成失败!'. "\n"; } } } } unset($class_info); } } } } public function apiPost($path, $arr, $type = 0) { $ch = @curl_init(); $result = FALSE; if ($ch) { $data = json_encode($arr); $url = Yii::app()->params['api'][$type]['prefix'] . $path; $username = Yii::app()->params['api'][$type]['username']; $password = Yii::app()->params['api'][$type]['password']; // Digest认证 curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password); // 不输出头部 curl_setopt($ch, CURLOPT_HEADER, 0); // curl_exec 获取到的内容不直接输出, 而是返回 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 请求重启路由器的地址 传参 进行重启 curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERAGENT, 'Api Client/1.0.0 (chengfei@liancaitech.com)'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: ' . strlen($data), )); if (!curl_errno($ch)) { $result = json_decode(curl_exec($ch)); } // 释放资源 curl_close($ch); } return $result; } private function check_zip($file_path) { if (substr($file_path, strlen($file_path) - 4, 4) == ".zip") { if (file_exists($file_path)) { return true; } } return false; } /** * 获取接口数据 * @param $url * @param $method * @param array $params * @return array */ private function getHttp($url,$method,$params = array()){ $res = http($url, $method, $this->authUsername, $params); $res = $this->handleRes($res); return $res; } /** * 处理接口返回的数据 * @param $res * @return array */ public function handleRes($res){ $result = array( 'status' => 0, 'data' => array(), 'msg' => '暂无数据', ); if($res){ $res = json_decode($res,true); if(isset($res['errCode']) && $res['errCode'] == '00'){ $result['status'] = 1; $result['data'] = isset($res['data'])?$res['data']:array(); $result['msg'] = $res['errMsg']; }else{ if(isset($res['errMsg'])){ $result['msg'] = $res['errMsg']; } } } unset($res); return $result; } function file_exists($url) { $ch = curl_init(); $timeout = 10; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $contents = curl_exec($ch); if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == 404) { return false; } return true; // $ch = curl_init(); // curl_setopt ($ch, CURLOPT_URL, $url); // //不下载 // curl_setopt($ch, CURLOPT_NOBODY, 1); // //设置超时 // curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 3); // curl_setopt($ch, CURLOPT_TIMEOUT, 3); // //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // curl_exec($ch); // $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); // if($http_code == 200) { // return true; // } // return false; } public function viewRender($viewName, $data) { extract($data, EXTR_PREFIX_SAME,'data'); ob_start(); ob_implicit_flush(0); require(dirname(dirname(dirname(__FILE__))).'/protected/views/classes/'.$viewName . '.php'); return ob_get_clean(); } }