orders aggs_biz_ding_piao_rpt, add export excel2
This commit is contained in:
@@ -127,6 +127,8 @@ class Orders extends HD_Controller
|
||||
|
||||
public function lists_aggs(){
|
||||
# http://admin.dev.liche.cn/#/receiver/orderv2/orders/lists_aggs?today_start=2021-12-01&today_end=2022-06-06&total_start=2021-12-01&title_today=start 2021-12-01&title_ding_today=当日订单&title_piao_today=当日开票
|
||||
# http://admin.dev.liche.cn/#/receiver/orderv2/orders/lists_aggs?today_start=2022-01-01&today_end=2022-07-01&total_start=2022-01-01&total_end=2023-01-01&title_today=start 2022-01~06&title_ding_today=上半年订单&title_ding=全年订单&title_piao_today=上半年开票&title_piao=全年开票
|
||||
# http://admin.dev.liche.cn/#/receiver/orderv2/orders/lists_aggs?today_start=2022-12-01&today_end=2023-01-01&total_start=2022-10-01&total_end=2023-01-01&title_today=start 2022-12&title_ding_today=12月订单&title_ding=季度订单&title_piao_today=12月开票&title_piao=季度开票
|
||||
$today_start = date('Y-m-d 00:00:00');
|
||||
$today_end = date('Y-m-d 00:00:00', strtotime('+1 day'));
|
||||
$total_start = date('Y-m-01 00:00:00');
|
||||
@@ -169,17 +171,137 @@ class Orders extends HD_Controller
|
||||
}
|
||||
if ($export == 'image' || $export == 'img'){
|
||||
if ($img_path){
|
||||
#$http = $_SERVER['HTTPS'] ? 'https://' : 'http://';
|
||||
#$img_path = $http.$_SERVER['HTTP_HOST'].'/'.$img_path;
|
||||
echo '<img src="/' . $img_path . '"/><br>';
|
||||
if ($img_path_ding) echo '<img src="/' . $img_path_ding . '"/><br>';
|
||||
if ($img_path_piao) echo '<img src="/' . $img_path_piao . '"/><br>';
|
||||
exit();
|
||||
$http = $_SERVER['HTTPS'] ? 'https://' : 'http://';
|
||||
$img_url = $http.$_SERVER['HTTP_HOST'].'/'.$img_path;
|
||||
echo '<img src="'. $img_url . '"/>';exit();
|
||||
}
|
||||
return $this->excel->out_csv($biz_aggs, $indexs, $filename);
|
||||
}
|
||||
return $this->excel->out($biz_aggs, $indexs, $filename);
|
||||
|
||||
if ($export == 'excel2'){
|
||||
#var_dump($indexs);echo('<br>');var_dump($biz_aggs[0]);echo('<br>');var_dump($biz_aggs[1]);exit();
|
||||
|
||||
#生成品牌对应的系列数,用于表头合并列
|
||||
$series_names = $data['series_names'];
|
||||
$indexs_keys = array_keys($indexs);
|
||||
$brand_series_nums = array();
|
||||
foreach ($series_names as $k => $v){
|
||||
$nums = 0;
|
||||
if (in_array($k.'_ding', $indexs_keys)){
|
||||
$nums++;
|
||||
}
|
||||
foreach ($v as $k2 => $v2){
|
||||
if (in_array($k.'_'.$v2.'_ding', $indexs_keys)){
|
||||
$nums++;
|
||||
}
|
||||
}
|
||||
$nums && $brand_series_nums[$k.'_ding'] = $nums;
|
||||
|
||||
$nums = 0;
|
||||
if (in_array($k.'_piao', $indexs_keys)){
|
||||
$nums++;
|
||||
}
|
||||
foreach ($v as $k2 => $v2){
|
||||
if (in_array($k.'_'.$v2.'_piao', $indexs_keys)){
|
||||
$nums++;
|
||||
}
|
||||
}
|
||||
$nums && $brand_series_nums[$k.'_piao'] = $nums;
|
||||
}
|
||||
#var_dump($brand_series_nums);exit();
|
||||
|
||||
#require_once COMMPATH . 'third_party/PHPExcel.php';
|
||||
set_time_limit(0); // 设置页面等待时间
|
||||
ini_set('memory_limit', -1); // 不限制内存
|
||||
$objPHPExcel = new PHPExcel();
|
||||
#$objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
|
||||
$objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT); // 单元格整体居右
|
||||
$objPHPExcel->setActiveSheetIndex(0); // 选中默认的第一个sheet
|
||||
$objPHPExcel->getActiveSheet()->setTitle('小狸播报'); // 给 Sheet 设置名字
|
||||
|
||||
# 先生成表头
|
||||
$i = 0;
|
||||
foreach ($indexs as $k => $v){
|
||||
$columnkey = PHPExcel_Cell::stringFromColumnIndex($i);
|
||||
if ((strpos($k,'_ding') !== false || strpos($k,'_piao') !== false) && !in_array($k, array('doc_ding_today', 'doc_ding', 'doc_piao_today', 'doc_piao'))){
|
||||
if ($brand_series_nums[$k]){
|
||||
# 第一行需合并多列的列
|
||||
$columnkey2 = PHPExcel_Cell::stringFromColumnIndex($i + $brand_series_nums[$k] - 1);
|
||||
$pRange = $columnkey.'1:'.$columnkey2.'1';
|
||||
$pCoordinate = $columnkey.'1';
|
||||
$objPHPExcel->getActiveSheet()->mergeCells($pRange);
|
||||
$objPHPExcel->setActiveSheetIndex(0)->setCellValue($pCoordinate, $v);
|
||||
|
||||
# PHPExcel常用属性使用 http://t.zoukankan.com/lglblogadd-p-7117486.html
|
||||
# 水平居中
|
||||
$objStyle = $objPHPExcel->getActiveSheet()->getStyle($pCoordinate); //获取要设置单元格的样式,括号里的内容也可是:('A1:E1')
|
||||
$objAlign = $objStyle->getAlignment(); //用来设置对齐属性和单元格内文本换行的一个变量
|
||||
$objAlign->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
|
||||
}
|
||||
|
||||
# 第二行的列
|
||||
$pCoordinate = $columnkey.'2';
|
||||
$objPHPExcel->setActiveSheetIndex(0)->setCellValue($pCoordinate, $v);
|
||||
}
|
||||
else{
|
||||
# 第一二行需合并的列
|
||||
$pRange = $columnkey.'1:'.$columnkey.'2';
|
||||
$pCoordinate = $columnkey.'1';
|
||||
$objPHPExcel->getActiveSheet()->mergeCells($pRange);
|
||||
$objPHPExcel->setActiveSheetIndex(0)->setCellValue($pCoordinate, $v);
|
||||
|
||||
# 垂直居中
|
||||
$objStyle = $objPHPExcel->getActiveSheet()->getStyle($pCoordinate);
|
||||
$objAlign = $objStyle->getAlignment();
|
||||
$objAlign->setVertical(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
# 再生成数据
|
||||
$biz_aggs = array_slice($biz_aggs, 1);
|
||||
$j = 3;
|
||||
foreach ($biz_aggs as $val) {
|
||||
$i = 0;
|
||||
// 内循环产生每一行
|
||||
foreach ($indexs as $k => $v){
|
||||
// 数字列转换为字母列 如:27变为AA
|
||||
$objPHPExcel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex($i) . $j, $val[$k]);
|
||||
$i++;
|
||||
}
|
||||
$j++;
|
||||
}
|
||||
|
||||
$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');
|
||||
return $objWriter->save('php://output');
|
||||
}
|
||||
|
||||
if (count($indexs) <= 26){
|
||||
return $this->excel->out($biz_aggs, $indexs, $filename);
|
||||
}
|
||||
|
||||
$sheet['小狸播报'] = array();
|
||||
foreach ($biz_aggs as $k => $v) {
|
||||
$list[1] = array();
|
||||
foreach ($indexs as $k2 => $v2){
|
||||
$list[1][] = $v[$k2];
|
||||
}
|
||||
$sheet['小狸播报'][] = $list[1];
|
||||
}
|
||||
return $this->excel->exportExcel($sheet, $filename);
|
||||
}
|
||||
|
||||
#var_dump($indexs);var_dump($biz_aggs[0]);
|
||||
|
||||
@@ -7,9 +7,15 @@
|
||||
<div class="am-form-group fl ml10" style="display: none">
|
||||
<button type="submit" class="am-btn am-btn-success am-btn-sm w100">搜索</button>
|
||||
</div>
|
||||
<div class="am-form-group fl ml10">
|
||||
<button type="button" @click="export_out('csv')" class="am-btn am-btn-success am-btn-sm w100">导出csv</button>
|
||||
</div>
|
||||
<div class="am-form-group fl ml10">
|
||||
<button type="button" @click="export_out('excel')" class="am-btn am-btn-success am-btn-sm w100">导出Excel</button>
|
||||
</div>
|
||||
<div class="am-form-group fl ml10">
|
||||
<button type="button" @click="export_out('excel2')" class="am-btn am-btn-success am-btn-sm w100">导出Excel2</button>
|
||||
</div>
|
||||
<div class="am-form-group fl ml10">
|
||||
<button type="button" @click="export_out('image')" class="am-btn am-btn-success am-btn-sm w100">导出Image</button>
|
||||
</div>
|
||||
|
||||
@@ -1378,7 +1378,7 @@ class Orders_v2_entity{
|
||||
$img_path_ding = $this->create_table_image($data_ding, $index_img_ding, $indexs_total, '小狸播报 - 订单', 'aggs_biz_rpt_ding.png');
|
||||
$img_path_piao = $this->create_table_image($data_piao, $index_img_piao, $indexs_total, '小狸播报 - 开票', 'aggs_biz_rpt_piao.png');
|
||||
}
|
||||
return array('biz_aggs'=>$biz_aggs, 'indexs'=>$indexs, 'img_path'=>$img_path, 'img_path_ding'=>$img_path_ding, 'img_path_piao'=>$img_path_piao);
|
||||
return array('biz_aggs'=>$biz_aggs, 'indexs'=>$indexs, 'img_path'=>$img_path, 'img_path_ding'=>$img_path_ding, 'img_path_piao'=>$img_path_piao, 'brand_names'=>$brand_names, 'series_names'=>$series_names);
|
||||
}
|
||||
|
||||
// 商家下定+开票统计 simple, 只拆分品牌列
|
||||
|
||||
Reference in New Issue
Block a user