Exemplo n.º 1
0
 function _itoolsSave($lis, $type)
 {
     foreach ($lis as $k => $li) {
         $array['title'] = pq($li)->find('.ios_app_cur')->find('.ios_app_curTxt')->eq(0)->text();
         $array['ranking'] = $k + 1;
         $array['type'] = $type;
         $array['searchtime'] = date("Y-m-d H:i:s");
         $tongji = new TongjiData();
         $tongji->insertData($array);
     }
 }
Exemplo n.º 2
0
 public function actionOutExcel()
 {
     $start = isset($_GET['start']) ? $_GET['start'] : date("Y-m-d");
     $end = isset($_GET['end']) ? $_GET['end'] : date("Y-m-d");
     $name = isset($_GET['name']) ? $_GET['name'] : '';
     $type = isset($_GET['type']) ? $_GET['type'] : '';
     $page = isset($_GET['page']) ? $_GET['page'] : 1;
     $where = '';
     $whereArray = array(':start' => $start . ' 00:00:00', ':end' => $end . ' 23:59:59');
     if (!empty($name)) {
         $where .= ' and title like :name';
         $whereArray[':name'] = $name . '%';
     }
     $tongji = new TongjiData();
     $criteria = new CDbCriteria();
     $criteria->condition = 'searchtime >= :start and searchtime <= :end' . $where;
     $criteria->params = $whereArray;
     if (!empty($type)) {
         $typeIds = TongjiType::model()->getTypeIdsByPid($type);
         $criteria->addInCondition("type_id", $typeIds);
     }
     $criteria->order = 'type_id,id';
     $criteria->offset = ($page - 1) * 40;
     $criteria->limit = 40;
     $datas = $tongji->findAll($criteria);
     ob_end_clean();
     ob_start();
     $objPHPExcel = new PHPExcel();
     $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")->setLastModifiedBy("Maarten Balliauw")->setTitle("Office 2007 XLSX Test Document")->setSubject("Office 2007 XLSX Test Document")->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")->setKeywords("office 2007 openxml php")->setCategory("Test result file");
     $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', 'ID')->setCellValue('B1', '名称')->setCellValue('C1', '平台渠道')->setCellValue('D1', '排名')->setCellValue('E1', '采集时间');
     if (!empty($datas)) {
         $i = 2;
         foreach ($datas as $v) {
             $objPHPExcel->setActiveSheetIndex(0)->setCellValue("A{$i}", $v['id'])->setCellValue("B{$i}", $v['title'])->setCellValue("C{$i}", $v->types->type)->setCellValue("D{$i}", $v['ranking'])->setCellValue("E{$i}", $v['searchtime']);
             $i++;
         }
     }
     $objPHPExcel->getActiveSheet()->setTitle('采集数据');
     $objPHPExcel->setActiveSheetIndex(0);
     $objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
     header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
     header("Content-Type:application/force-download");
     header("Content-Type:application/vnd.ms-execl");
     header("Content-Type:application/octet-stream");
     header("Content-Type:application/download");
     $fireName = date("YmdHis") . '数据导出';
     header("Content-Disposition:attachment;filename={$fireName}.xls");
     header("Content-Transfer-Encoding:binary");
     $objWriter->save("php://output");
     Yii::app()->end();
     spl_autoload_register(array('YiiBase', 'autoload'));
 }
Exemplo n.º 3
0
 private function _tryGetAishiData($url, $page, $pagesize = 20, $count = 3)
 {
     $url = $url . '&pageno=' . $page;
     $xml = Crawler::curl($url);
     $have_utf = false;
     if (strpos($xml, 'UTF-8') != false) {
         $have_utf = true;
     }
     if (strpos($xml, 'utf-8') != false) {
         $have_utf = true;
     }
     if ($have_utf == false) {
         return array();
     }
     $xml = simplexml_load_string($xml);
     if ($xml) {
         //首页banner入库
         if ($page == 1 && isset($xml->adlist)) {
             $b = 0;
             foreach ($xml->adlist->adinfo as $v) {
                 $banner['title'] = $v->name;
                 $banner['ranking'] = ++$b;
                 $banner['type'] = 13;
                 $banner['searchtime'] = date("Y-m-d H:i:s");
                 $tongji = new TongjiData();
                 $tongji->insertData($banner);
             }
         }
         $k = 0;
         foreach ($xml->applist->app as $v) {
             $datas[$k]['title'] = $v->appname;
             $datas[$k]['ranking'] = ($page - 1) * $pagesize + $k + 1;
             $k++;
         }
         return $datas;
     } elseif ($count !== 0) {
         $count--;
         sleep(1);
         return $this->_tryGetAishiData($url, $page, $count);
     }
     return array();
 }