From ec7f900c87577d470ddc3409677f53d3ef988587 Mon Sep 17 00:00:00 2001 From: "lmr@hainatravel.com" <59361885@qq.com> Date: Fri, 14 Jul 2017 11:03:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=87=E4=BB=B6=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/controllers/tools.php | 46 ++++++++++++++++++++++++++++++- application/views/tools/old.php | 6 ++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/application/controllers/tools.php b/application/controllers/tools.php index 77f1f33b..ac95ded2 100644 --- a/application/controllers/tools.php +++ b/application/controllers/tools.php @@ -27,14 +27,58 @@ class Tools extends CI_Controller $data['yeardiff'] = $this->input->get_post('yeardiff'); $data['nopub'] = $this->input->get_post('nopub'); $data['emptyinfo'] = $this->input->get_post('emptyinfo'); + $data['csv'] = $this->input->get_post('csv'); //参数 if (!$data['yeardiff']) $data['yeardiff'] = 3; //老旧信息 $data['info'] = $this->Information_model->get_oldest_info($data['yeardiff'], $data['nopub'], $data['emptyinfo']); //视图 - $this->load->view('tools/old', $data); + if ($data['csv']) + { + $csv_header = array('id', 'file', 'date', 'public'); + $csv_data = array(); + foreach ($data['info'] as $key => $it) + { + $temp = array(); + $temp[0] = $key; + $temp[1] = $it->ic_url; + $temp[2] = date('Y-m-d', strtotime($it->ic_datetime)); + $it->ic_status ? $temp[3] = 'yes' : $temp[3] = 'no'; + array_push($csv_data, $temp); + } + $this->csv($csv_header, $csv_data, 'old_info.csv'); + } else { + $this->load->view('tools/old', $data); + } } + /** + * 导出CSV文件 + * @param array $data 数据 + * @param array $header_data 首行数据 + * @param string $file_name 文件名称 + * @return string + */ + public function csv($header_data, $data, $file_name) + { + header('Content-Type: application/vnd.ms-excel'); + header('Content-Disposition: attachment;filename='.$file_name); + header('Cache-Control: max-age=0'); + $fp = fopen('php://output', 'a'); + if (!empty($header_data)) { + fputcsv($fp, $header_data); + } + $count = count($data); + if ($count > 0) + { + for ($i = 0; $i < $count; $i++) + { + $row = $data[$i]; + fputcsv($fp, $row); + } + } + fclose($fp); + } } //end of Cache diff --git a/application/views/tools/old.php b/application/views/tools/old.php index 54117707..826e97bd 100644 --- a/application/views/tools/old.php +++ b/application/views/tools/old.php @@ -94,6 +94,12 @@ $(function() { > 显示内容为空的信息 +   + + +