userslog_713
This commit is contained in:
@@ -115,9 +115,9 @@ class Userslog extends HD_Controller
|
||||
$customers += $nums;
|
||||
if ($params['size'] != 10000) {
|
||||
if ($customer_info) {
|
||||
$customer_info = $customer_info . '+' . $value1['name'] . '(' . $nums . ')';
|
||||
$customer_info .= "<br>{$value1['name']}:{$nums}";
|
||||
} else {
|
||||
$customer_info = $value1['name'] . '(' . $nums . ')';
|
||||
$customer_info = "<br>{$value1['name']}:{$nums}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -125,9 +125,9 @@ class Userslog extends HD_Controller
|
||||
$c_num += $nums_c_num;
|
||||
if ($params['size'] != 10000) {
|
||||
if ($c_num_info) {
|
||||
$c_num_info = $c_num_info . '+' . $value1['name'] . '(' . $nums_c_num . ')';
|
||||
$c_num_info .= "<br>{$value1['name']}:{$nums_c_num}";
|
||||
} else {
|
||||
$c_num_info = $value1['name'] . '(' . $nums_c_num . ')';
|
||||
$c_num_info = "<br>{$value1['name']}:{$nums_c_num}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -135,9 +135,9 @@ class Userslog extends HD_Controller
|
||||
$orders += $nums_orders;
|
||||
if ($params['size'] != 10000) {
|
||||
if ($order_info) {
|
||||
$order_info = $order_info . '+' . $value1['name'] . '(' . $nums_orders . ')';
|
||||
$order_info .= "<br>{$value1['name']}:{$nums_orders}";
|
||||
} else {
|
||||
$order_info = $value1['name'] . '(' . $nums_orders . ')';
|
||||
$order_info = "<br>{$value1['name']}:{$nums_orders}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -152,12 +152,9 @@ class Userslog extends HD_Controller
|
||||
}
|
||||
}
|
||||
}
|
||||
$customer_info && $customers = $customers . '=' . $customer_info;
|
||||
$c_num_info && $c_num = $c_num . '=' . $c_num_info;
|
||||
$order_info && $orders = $orders . '=' . $order_info;
|
||||
$temp['customers'] = $customers;
|
||||
$temp['c_num'] = $c_num;
|
||||
$temp['orders'] = $orders;
|
||||
$temp['customers'] = $customer_info ? "总数:{$customers}{$customer_info}" : $customers;
|
||||
$temp['c_num'] = $c_num_info ? "总数:{$c_num}{$c_num_info}" : $c_num;
|
||||
$temp['orders'] = $order_info ? "总数:{$orders}{$order_info}" : $orders;
|
||||
$lists[] = $temp;
|
||||
}
|
||||
}
|
||||
@@ -361,80 +358,107 @@ class Userslog extends HD_Controller
|
||||
$params['page'] = 1;
|
||||
$params['size'] = 10000;
|
||||
$data = $indexs = [];
|
||||
$this->load->library('excel');
|
||||
if ($params['tab'] == 1) {//客户统计
|
||||
$res = $this->dataUsersSelect($params);
|
||||
$offlineSources = $this->mdCustomers->offlineSources();
|
||||
$indexs = ['uname' => '顾问', 'customers' => '客户数︾'];
|
||||
foreach ($offlineSources as $key1 => $value1) {
|
||||
$indexs['customer_' . $key1] = '【' . $value1['name'] . '】';
|
||||
foreach ($value1['list'] as $key2 => $value2) {
|
||||
$indexs['customer_' . $key2] = $value2;
|
||||
$fileName = $res['_title'] . '_' . $this->tabAry[$params['tab']] . "_" . date('YmdHis');
|
||||
$list[1] = ['顾问', '日期', '客户数', '进店人数', '订单数', '试驾数', '战败数', '开票数', '新增企微', '删除企微'];
|
||||
$list[2] = ['顾问', '日期', '客户数'];
|
||||
$list[3] = ['顾问', '日期', '进店人数'];
|
||||
$list[4] = ['顾问', '日期', '订单数'];
|
||||
foreach ($offlineSources as $k1 => $v1) {
|
||||
$list[2][] = "【{$v1['name']}】";
|
||||
$list[3][] = "【{$v1['name']}】";
|
||||
$list[4][] = "【{$v1['name']}】";
|
||||
foreach ($v1['list'] as $k2 => $v2) {
|
||||
$list[2][] = $v2;
|
||||
$list[3][] = $v2;
|
||||
$list[4][] = $v2;
|
||||
}
|
||||
}
|
||||
$indexs['c_num'] = '进店人数︾';
|
||||
foreach ($offlineSources as $key1 => $value1) {
|
||||
$indexs['c_num_' . $key1] = '【' . $value1['name'] . '】';
|
||||
foreach ($value1['list'] as $key2 => $value2) {
|
||||
$indexs['c_num_' . $key2] = $value2;
|
||||
//第一条标题
|
||||
$sheet['总览'][] = $list[1];
|
||||
$sheet['客户'][] = $list[2];
|
||||
$sheet['进店'][] = $list[3];
|
||||
$sheet['订单'][] = $list[4];
|
||||
foreach ($res['lists'] as $k => $v) {
|
||||
$list[1] = [$v['uname'], $v['log_date'], $v['customers'], $v['c_num'], $v['orders'], $v['t_num'], $v['defeats']
|
||||
, $v['bills'], $v['qy_adds'], $v['qy_dels']];
|
||||
$list[2] = [$v['uname'], $v['log_date'], $v['customers']];
|
||||
$list[3] = [$v['uname'], $v['log_date'], $v['c_num']];
|
||||
$list[4] = [$v['uname'], $v['log_date'], $v['orders']];
|
||||
foreach ($offlineSources as $k2 => $v2) {
|
||||
$list[2][] = $v['customer_' . $k2];
|
||||
$list[3][] = $v['c_num_' . $k2];
|
||||
$list[4][] = $v['order_' . $k2];
|
||||
foreach ($v2['list'] as $k3 => $v3) {
|
||||
$list[2][] = $v['customer_' . $k3];
|
||||
$list[3][] = $v['c_num_' . $k3];
|
||||
$list[4][] = $v['order_' . $k3];
|
||||
}
|
||||
}
|
||||
$sheet['总览'][] = $list[1];
|
||||
$sheet['客户'][] = $list[2];
|
||||
$sheet['进店'][] = $list[3];
|
||||
$sheet['订单'][] = $list[4];
|
||||
}
|
||||
$indexs['orders'] = '订单数︾';
|
||||
foreach ($offlineSources as $key1 => $value1) {
|
||||
$indexs['order_' . $key1] = '【' . $value1['name'] . '】';
|
||||
foreach ($value1['list'] as $key2 => $value2) {
|
||||
$indexs['order_' . $key2] = $value2;
|
||||
}
|
||||
}
|
||||
$indexs['t_num'] = '试驾数';
|
||||
$indexs['defeats'] = '战败数';
|
||||
$indexs['bills'] = '开票数';
|
||||
$indexs['qy_adds'] = '新增企微';
|
||||
$indexs['qy_dels'] = '删除企微';
|
||||
$indexs['log_date'] = '日期';
|
||||
$fileName = $res['_title'] . '_' . $this->tabAry[$params['tab']];
|
||||
$this->excel->exportExcel($sheet, $fileName);
|
||||
} else if ($params['tab'] == 2) {//回访统计
|
||||
$res = $this->visitSelect($params);
|
||||
$indexs = ['biz_name' => '门店', 'uname' => '顾问', 'follows' => '计划跟进数', 'h_follows' => '已跟进数'
|
||||
, 't_follows' => '今日新增未跟进数', 'w_follows' => '逾期未跟进数', 't_day' => '日期'];
|
||||
$fileName = $res['_title'] . '_' . $this->tabAry[$params['tab']];
|
||||
} else {
|
||||
foreach ($res['lists'] as $key => $value) {
|
||||
$data[] = $value;
|
||||
}
|
||||
array_unshift($data, $indexs);
|
||||
$this->excel->out_csv($data, $indexs, $fileName . "_" . date('YmdHis'));
|
||||
} else {//门店统计
|
||||
$res = $this->dataBizSelect($params);
|
||||
$offlineSources = $this->mdCustomers->offlineSources();
|
||||
$indexs = ['biz_name' => '门店', 'customers' => '客户数︾'];
|
||||
foreach ($offlineSources as $key1 => $value1) {
|
||||
$indexs['customer_' . $key1] = '【' . $value1['name'] . '】';
|
||||
foreach ($value1['list'] as $key2 => $value2) {
|
||||
$indexs['customer_' . $key2] = $value2;
|
||||
$fileName = $res['_title'] . "_" . date('YmdHis');
|
||||
$list[1] = ['门店', '日期', '客户数', '进店人数', '订单数', '试驾数', '战败数', '开票数', '企微数', '改派数', '接收数'];
|
||||
$list[2] = ['门店', '日期', '客户数'];
|
||||
$list[3] = ['门店', '日期', '进店人数'];
|
||||
$list[4] = ['门店', '日期', '订单数'];
|
||||
foreach ($offlineSources as $k1 => $v1) {
|
||||
$list[2][] = "【{$v1['name']}】";
|
||||
$list[3][] = "【{$v1['name']}】";
|
||||
$list[4][] = "【{$v1['name']}】";
|
||||
foreach ($v1['list'] as $k2 => $v2) {
|
||||
$list[2][] = $v2;
|
||||
$list[3][] = $v2;
|
||||
$list[4][] = $v2;
|
||||
}
|
||||
}
|
||||
$indexs['c_num'] = '进店人数︾';
|
||||
foreach ($offlineSources as $key1 => $value1) {
|
||||
$indexs['c_num_' . $key1] = '【' . $value1['name'] . '】';
|
||||
foreach ($value1['list'] as $key2 => $value2) {
|
||||
$indexs['c_num_' . $key2] = $value2;
|
||||
//第一条标题
|
||||
$sheet['总览'][] = $list[1];
|
||||
$sheet['客户'][] = $list[2];
|
||||
$sheet['进店'][] = $list[3];
|
||||
$sheet['订单'][] = $list[4];
|
||||
foreach ($res['lists'] as $k => $v) {
|
||||
$list[1] = [$v['biz_name'], $v['log_date'], $v['customers'], $v['c_num'], $v['orders'], $v['t_num'], $v['defeats']
|
||||
, $v['bills'], $v['qy_adds'], $v['reassigns'], $v['receives']];
|
||||
$list[2] = [$v['biz_name'], $v['log_date'], $v['customers']];
|
||||
$list[3] = [$v['biz_name'], $v['log_date'], $v['c_num']];
|
||||
$list[4] = [$v['biz_name'], $v['log_date'], $v['orders']];
|
||||
foreach ($offlineSources as $k2 => $v2) {
|
||||
$list[2][] = $v['customer_' . $k2];
|
||||
$list[3][] = $v['c_num_' . $k2];
|
||||
$list[4][] = $v['order_' . $k2];
|
||||
foreach ($v2['list'] as $k3 => $v3) {
|
||||
$list[2][] = $v['customer_' . $k3];
|
||||
$list[3][] = $v['c_num_' . $k3];
|
||||
$list[4][] = $v['order_' . $k3];
|
||||
}
|
||||
}
|
||||
$sheet['总览'][] = $list[1];
|
||||
$sheet['客户'][] = $list[2];
|
||||
$sheet['进店'][] = $list[3];
|
||||
$sheet['订单'][] = $list[4];
|
||||
}
|
||||
$indexs['orders'] = '订单数︾';
|
||||
foreach ($offlineSources as $key1 => $value1) {
|
||||
$indexs['order_' . $key1] = '【' . $value1['name'] . '】';
|
||||
foreach ($value1['list'] as $key2 => $value2) {
|
||||
$indexs['order_' . $key2] = $value2;
|
||||
}
|
||||
}
|
||||
$indexs['t_num'] = '试驾数';
|
||||
$indexs['defeats'] = '战败数';
|
||||
$indexs['bills'] = '开票数';
|
||||
$indexs['qy_adds'] = '企微数';
|
||||
$indexs['reassigns'] = '改派数';
|
||||
$indexs['receives'] = '接收数';
|
||||
$indexs['log_date'] = '日期';
|
||||
$fileName = $res['_title'];
|
||||
$this->excel->exportExcel($sheet, $fileName);
|
||||
}
|
||||
foreach ($res['lists'] as $key => $value) {
|
||||
$data[] = $value;
|
||||
}
|
||||
array_unshift($data, $indexs);
|
||||
$this->load->library('excel');
|
||||
$this->excel->out_csv($data, $indexs, $fileName . "_" . date('YmdHis'));
|
||||
}
|
||||
}
|
||||
@@ -81,10 +81,10 @@
|
||||
<table class="am-table am-table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="17%"><span>门店</span></th>
|
||||
<th width="15%"><span>客户数</span></th>
|
||||
<th width="15%"><span>进店人数</span></th>
|
||||
<th width="15%"><span>订单数</span></th>
|
||||
<th width="20%"><span>门店</span></th>
|
||||
<th width="12%"><span>客户数</span></th>
|
||||
<th width="12%"><span>进店人数</span></th>
|
||||
<th width="12%"><span>订单数</span></th>
|
||||
<th width="9%"><span>试驾数</span></th>
|
||||
<th width="9%"><span>战败数</span></th>
|
||||
<th width="9%"><span>开票数</span></th>
|
||||
|
||||
@@ -6,20 +6,24 @@ defined('WXAPP_APP') OR exit('No direct script access allowed');
|
||||
* User: lcc
|
||||
* Date: 2021/06/23
|
||||
* Time: 14:08
|
||||
*/
|
||||
require_once APPPATH.'controllers/wxapp/Wxapp.php';
|
||||
class Employees extends Wxapp{
|
||||
*/
|
||||
require_once APPPATH . 'controllers/wxapp/Wxapp.php';
|
||||
|
||||
function __construct($inputs, $app_key){
|
||||
class Employees extends Wxapp
|
||||
{
|
||||
|
||||
function __construct($inputs, $app_key)
|
||||
{
|
||||
parent::__construct($inputs, $app_key);
|
||||
|
||||
$this->login_white = array();//登录白名单
|
||||
$this->check_status = array();//用户状态校验
|
||||
$this->check_mobile = array();//需要手机号
|
||||
$this->check_headimg =array();//授权微信信息
|
||||
$this->check_headimg = array();//授权微信信息
|
||||
}
|
||||
|
||||
public function get(){
|
||||
|
||||
public function get()
|
||||
{
|
||||
$ifconf = $this->input_param('ifconf');
|
||||
$page = $this->input_param('page');
|
||||
$size = $this->input_param('size');
|
||||
@@ -27,14 +31,14 @@ class Employees extends Wxapp{
|
||||
!$page && $page = 1;
|
||||
!$size && $size = 10;
|
||||
$uid = $this->session['uid'];
|
||||
$biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']);
|
||||
$biz_id = $this->get_biz_id();
|
||||
|
||||
if($ifconf){
|
||||
if ($ifconf) {
|
||||
$where = [
|
||||
"(biz_id=$biz_id or id=$uid)" => null,
|
||||
'status' => 1
|
||||
];
|
||||
}else{
|
||||
} else {
|
||||
$where = [
|
||||
'biz_id' => $biz_id,
|
||||
'status>' => -1
|
||||
@@ -43,9 +47,9 @@ class Employees extends Wxapp{
|
||||
|
||||
$count = $this->app_user_model->count($where);
|
||||
$lists = [];
|
||||
if($count){
|
||||
if ($count) {
|
||||
$fileds = 'id,uname,mobile,status';
|
||||
$rows = $this->app_user_model->select($where,'id desc',$page,$size,$fileds);
|
||||
$rows = $this->app_user_model->select($where, 'id desc', $page, $size, $fileds);
|
||||
$lists = $rows;
|
||||
}
|
||||
$this->load->model("biz/biz_model");
|
||||
@@ -64,21 +68,21 @@ class Employees extends Wxapp{
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function post(){
|
||||
$biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']);
|
||||
protected function post()
|
||||
{
|
||||
$biz_id = $this->get_biz_id();
|
||||
$group_id = $this->session['group_id'];
|
||||
$name = $this->input_param('name');
|
||||
$mobile = $this->input_param('mobile');
|
||||
|
||||
if($group_id == 1){
|
||||
if ($group_id == 1) {
|
||||
throw new Exception('无法添加店员', ERR_PARAMS_ERROR);
|
||||
}
|
||||
if(!mobile_valid($mobile)||!$name){
|
||||
if (!mobile_valid($mobile) || !$name) {
|
||||
throw new Exception('请输入正确手机号和姓名', ERR_PARAMS_ERROR);
|
||||
}
|
||||
|
||||
$row = $this->app_user_model->get(['mobile'=>$mobile,'status>=0'=>null]);
|
||||
if($row){
|
||||
|
||||
$row = $this->app_user_model->get(['mobile' => $mobile, 'status>=0' => null]);
|
||||
if ($row) {
|
||||
throw new Exception('手机号已存在', ERR_PARAMS_ERROR);
|
||||
}
|
||||
$data = [
|
||||
@@ -90,43 +94,49 @@ class Employees extends Wxapp{
|
||||
'c_time' => time()
|
||||
];
|
||||
$result = $this->app_user_model->add($data);
|
||||
if($result){
|
||||
if ($result) {
|
||||
throw new Exception('创建成功', API_CODE_SUCCESS);
|
||||
}else{
|
||||
} else {
|
||||
throw new Exception('创建失败', ERR_PARAMS_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
protected function put(){
|
||||
protected function put()
|
||||
{
|
||||
$id = $this->input_param('id');
|
||||
$status = $this->input_param('status');
|
||||
$biz_id = $this->get_biz_id();
|
||||
$where = [
|
||||
'pid' => $this->session['uid'],
|
||||
//'pid' => $this->session['uid'],
|
||||
'biz_id' => $biz_id,
|
||||
'id' => $id
|
||||
];
|
||||
$row = $this->app_user_model->get($where);
|
||||
if(!$row){
|
||||
if (!$row) {
|
||||
throw new Exception('用户不存在', ERR_PARAMS_ERROR);
|
||||
}
|
||||
$update = [];
|
||||
if(strlen($status)){
|
||||
if (strlen($status)) {
|
||||
$update['status'] = $status ? 1 : 0;
|
||||
}
|
||||
$this->app_user_model->update($update,$where);
|
||||
$this->app_user_model->update($update, $where);
|
||||
throw new Exception('更新成功', API_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
protected function delete(){
|
||||
protected function delete()
|
||||
{
|
||||
$id = $this->input_param('id');
|
||||
$biz_id = $this->get_biz_id();
|
||||
$where = [
|
||||
'pid' => $this->session['uid'],
|
||||
//'pid' => $this->session['uid'],
|
||||
'biz_id' => $biz_id,
|
||||
'id' => $id
|
||||
];
|
||||
$row = $this->app_user_model->get($where);
|
||||
if(!$row){
|
||||
if (!$row) {
|
||||
throw new Exception('用户不存在', ERR_PARAMS_ERROR);
|
||||
}
|
||||
$this->app_user_model->update(['status'=>-1],$where);
|
||||
$this->app_user_model->update(['status' => -1], $where);
|
||||
throw new Exception('删除成功', API_CODE_SUCCESS);
|
||||
}
|
||||
}
|
||||
}
|
||||
+83
-30
@@ -8,9 +8,10 @@
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
require_once COMMPATH.'third_party/PHPExcel.php';
|
||||
require_once COMMPATH . 'third_party/PHPExcel.php';
|
||||
|
||||
class Excel extends PHPExcel {
|
||||
class Excel extends PHPExcel
|
||||
{
|
||||
|
||||
/*
|
||||
* 导出Excel
|
||||
@@ -20,21 +21,18 @@ class Excel extends PHPExcel {
|
||||
*/
|
||||
public function out($data, $indexs = array(), $filename = '')
|
||||
{
|
||||
if($data)
|
||||
{
|
||||
if ($data) {
|
||||
$excel = new PHPExcel();
|
||||
$sheet = $excel->getActiveSheet();
|
||||
$cells = 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');
|
||||
$cells = 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');
|
||||
$startRow = 1;
|
||||
|
||||
$indexs_key = $indexs ? array_keys($indexs) : array_keys($data);
|
||||
$indexs_name = $indexs ? array_values($indexs) : array_keys($data);
|
||||
|
||||
foreach ($data as $row)
|
||||
{
|
||||
foreach ($indexs_key as $key => $value)
|
||||
{
|
||||
$startRow == 1 ? $sheet->setCellValue($cells[$key].$startRow, $indexs_name[$key]) : $sheet->setCellValue($cells[$key].$startRow, $row[$value]);
|
||||
foreach ($data as $row) {
|
||||
foreach ($indexs_key as $key => $value) {
|
||||
$startRow == 1 ? $sheet->setCellValue($cells[$key] . $startRow, $indexs_name[$key]) : $sheet->setCellValue($cells[$key] . $startRow, $row[$value]);
|
||||
}
|
||||
|
||||
$startRow++;
|
||||
@@ -49,7 +47,7 @@ class Excel extends PHPExcel {
|
||||
header("Content-Type:application/vnd.ms-execl");
|
||||
header("Content-Type:application/octet-stream");
|
||||
header("Content-Type:application/download");;
|
||||
header('Content-Disposition:attachment;filename='. $filename .'.xlsx');
|
||||
header('Content-Disposition:attachment;filename=' . $filename . '.xlsx');
|
||||
header("Content-Transfer-Encoding:binary");
|
||||
|
||||
$writer = PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
|
||||
@@ -57,6 +55,60 @@ class Excel extends PHPExcel {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出 Excel支持多个 sheet
|
||||
* @param array $content 内容
|
||||
* @param string $fileName 文件名
|
||||
* @throws PHPExcel_Exception
|
||||
* @throws PHPExcel_Reader_Exception
|
||||
* @throws PHPExcel_Writer_Exception
|
||||
*/
|
||||
public function exportExcel($content = [], $fileName = '')
|
||||
{
|
||||
if (empty($content)) die('内容不能为空!');
|
||||
if (empty($fileName)) die('文件名不能为空!');
|
||||
// 设置页面等待时间
|
||||
set_time_limit(0);
|
||||
// 不限制内存
|
||||
ini_set('memory_limit', -1);
|
||||
$objPHPExcel = new PHPExcel();
|
||||
// 所有单元格居中
|
||||
$objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
|
||||
$i = 0;
|
||||
// 外循环产生每一项 Sheet
|
||||
foreach ($content as $key => $value) {
|
||||
// 创建新的工作空间 sheet
|
||||
if ($i > 0) $objPHPExcel->createSheet();
|
||||
$objPHPExcel->setActiveSheetIndex($i);
|
||||
// 给 Sheet 设置名字
|
||||
$objPHPExcel->getActiveSheet()->setTitle($key);
|
||||
// 内容
|
||||
$j = 1;
|
||||
// 外循环产生每一列
|
||||
foreach ($value as $val) {
|
||||
// 内循环产生每一行
|
||||
foreach ($val as $k => $v) {
|
||||
// 数字列转换为字母列 如:27变为AA
|
||||
$objPHPExcel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex($k) . $j, $v);
|
||||
}
|
||||
$j++;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
$filename = iconv('UTF-8', 'UTF-8', $fileName) . '.xls';
|
||||
header('Pragma: public');
|
||||
header('Expires: 0');
|
||||
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');
|
||||
header("Content-Disposition: attachment; filename=$filename");
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
|
||||
$objWriter->save('php://output');
|
||||
}
|
||||
|
||||
/**
|
||||
* cvs格式导出
|
||||
* @param $data
|
||||
@@ -64,7 +116,8 @@ class Excel extends PHPExcel {
|
||||
* @param string $filename
|
||||
* @return bool
|
||||
*/
|
||||
public function out_csv($data, $indexs = array(), $filename = ''){
|
||||
public function out_csv($data, $indexs = array(), $filename = '')
|
||||
{
|
||||
header("Pragma: public");
|
||||
header("Expires: 0");
|
||||
header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
|
||||
@@ -72,18 +125,18 @@ class Excel extends PHPExcel {
|
||||
header("Content-Type:application/vnd.ms-execl");
|
||||
header("Content-Type:application/octet-stream");
|
||||
header("Content-Type:application/download");;
|
||||
header('Content-Disposition:attachment;filename='. $filename .'.csv');
|
||||
header('Content-Disposition:attachment;filename=' . $filename . '.csv');
|
||||
header("Content-Transfer-Encoding:binary");
|
||||
|
||||
|
||||
$fp = fopen('php://output','a');
|
||||
$fp = fopen('php://output', 'a');
|
||||
|
||||
$indexs_key = $indexs ? array_keys($indexs) : array_keys($data);
|
||||
|
||||
//每隔$limit行,刷新一下输出buffer,不要太大,也不要太小
|
||||
$limit = 100000;
|
||||
$num = 0;
|
||||
foreach($data as $k => $v){
|
||||
foreach ($data as $k => $v) {
|
||||
$num++;
|
||||
//刷新一下输出buffer,防止由于数据过多造成问题
|
||||
if ($limit == $num) {
|
||||
@@ -93,8 +146,8 @@ class Excel extends PHPExcel {
|
||||
}
|
||||
|
||||
$row = array();
|
||||
foreach($indexs_key as $col){
|
||||
if(in_array($col, array('sid', 'refund_no')) && is_numeric($v[$col])){
|
||||
foreach ($indexs_key as $col) {
|
||||
if (in_array($col, array('sid', 'refund_no')) && is_numeric($v[$col])) {
|
||||
$row[] = iconv('utf-8', 'GBK//IGNORE', "=\"{$v[$col]}\"");
|
||||
} else {
|
||||
$row[] = iconv('utf-8', 'GBK//IGNORE', $v[$col]);
|
||||
@@ -114,27 +167,26 @@ class Excel extends PHPExcel {
|
||||
* @param $mode "a追加"
|
||||
* @return bool
|
||||
*/
|
||||
public function save($data, $indexs, $file, $mode = ''){
|
||||
public function save($data, $indexs, $file, $mode = '')
|
||||
{
|
||||
$dir = substr($file, 0, strrpos($file, '/'));
|
||||
if (!file_exists($dir) && !mkdir($dir, 0777, true)) {//创建文件夹失败
|
||||
return false;
|
||||
}
|
||||
if('a' == $mode && file_exists($file)){
|
||||
if ('a' == $mode && file_exists($file)) {
|
||||
$excel = PHPExcel_IOFactory::load($file);
|
||||
$sheet = $excel->getActiveSheet();
|
||||
$startRow = $sheet->getHighestRow()+1;
|
||||
$startRow = $sheet->getHighestRow() + 1;
|
||||
} else {
|
||||
$excel = new PHPExcel();
|
||||
$sheet = $excel->getActiveSheet();
|
||||
$startRow = 1;
|
||||
}
|
||||
$cells = 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');
|
||||
$cells = 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');
|
||||
|
||||
foreach ($data as $row)
|
||||
{
|
||||
foreach ($indexs as $key => $value)
|
||||
{
|
||||
$sheet->setCellValue($cells[$key].$startRow, $row[$value]);
|
||||
foreach ($data as $row) {
|
||||
foreach ($indexs as $key => $value) {
|
||||
$sheet->setCellValue($cells[$key] . $startRow, $row[$value]);
|
||||
}
|
||||
|
||||
$startRow++;
|
||||
@@ -153,7 +205,8 @@ class Excel extends PHPExcel {
|
||||
* @param string $mode
|
||||
* @return bool
|
||||
*/
|
||||
function csv($data, $indexs, $file, $mode = 'a'){
|
||||
function csv($data, $indexs, $file, $mode = 'a')
|
||||
{
|
||||
$dir = substr($file, 0, strrpos($file, '/'));
|
||||
if (!file_exists($dir) && !mkdir($dir, 0777, true)) {//创建文件夹失败
|
||||
return false;
|
||||
@@ -164,7 +217,7 @@ class Excel extends PHPExcel {
|
||||
//每隔$limit行,刷新一下输出buffer,不要太大,也不要太小
|
||||
$limit = 100000;
|
||||
$num = 0;
|
||||
foreach($data as $k => $v){
|
||||
foreach ($data as $k => $v) {
|
||||
$num++;
|
||||
//刷新一下输出buffer,防止由于数据过多造成问题
|
||||
if ($limit == $num) {
|
||||
@@ -174,8 +227,8 @@ class Excel extends PHPExcel {
|
||||
}
|
||||
|
||||
$row = array();
|
||||
foreach($indexs as $col){
|
||||
if(in_array($col, array('sid', 'refund_no')) && is_numeric($v[$col])){
|
||||
foreach ($indexs as $col) {
|
||||
if (in_array($col, array('sid', 'refund_no')) && is_numeric($v[$col])) {
|
||||
$row[] = iconv('utf-8', 'GBK//IGNORE', "=\"{$v[$col]}\"");
|
||||
} else {
|
||||
$row[] = iconv('utf-8', 'GBK//IGNORE', $v[$col]);
|
||||
|
||||
Reference in New Issue
Block a user