Commit fc667db0 authored by zw's avatar zw

pk

parent 88b0b40f
...@@ -3,6 +3,7 @@ namespace app\index\controller; ...@@ -3,6 +3,7 @@ namespace app\index\controller;
use app\index\extend\Basic; use app\index\extend\Basic;
use app\index\service\RankingListService; use app\index\service\RankingListService;
use app\index\untils\ExportExcelUntil;
use think\Request; use think\Request;
/** /**
...@@ -32,4 +33,16 @@ class RankingList extends Basic{ ...@@ -32,4 +33,16 @@ class RankingList extends Basic{
return $this->response("200","success",$result); return $this->response("200","success",$result);
} }
} }
public function exportReport(){
$params = $this->params;
/* $params["position"] = 1;
$this->siteId = 10001;*/
$export = new ExportExcelUntil();
$result = $this->service_->RankingList( $params["position"],$this->siteId);
$title = [ '经纪人ID', '门店编号','部门编号', '经纪人姓名', '经纪人电话', '业绩'];
$export->exportTables('PK明细表', $result, 6, 'PK明细表', $title);
return '';
}
} }
\ No newline at end of file
...@@ -46,4 +46,40 @@ class ExportExcelUntil ...@@ -46,4 +46,40 @@ class ExportExcelUntil
$class_xls->writeToStdOut(); $class_xls->writeToStdOut();
die; die;
} }
/**
* 导出Excel
*
* @param string $file_name 文件名
* @param array $data 数据
* @param int $field_num 字段数量
* @param string $table_title 表格title
* @param array $title 表格字段
*/
public function exportTables(string $file_name, array $data, int $field_num, $table_title = "", array $title = []) {
$filename = $file_name. '-' .date('YmdHis').".xlsx";
//设置 header,用于浏览器下载
header('Content-disposition: attachment; filename="'.\XLSXWriter::sanitize_filename($filename).'"');
header("Content-Type: application/vnd.openXmlFormats-officeDocument.spreadSheetMl.sheet");
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revaLiDate');
header('Pragma: public');
$class_xls = new \XLSXWriter();
$styles1 = array( 'font'=>'Arial','font-size'=>12,'font-style'=>'bold', 'fill'=>'#eee', 'halign'=>'center', 'border'=>'left,right,top,bottom','border-style'=>'thin','Valign'=>'center','height'=>20);
foreach ($data as $k=>$v) {
$sheet = $k + 1;
$class_xls->writeSheetHeader('Sheet'.$sheet, ['string'],['suppress_row'=>true,'widths'=>[20,25,20,30,30,20,30,20,30]]);
$class_xls->writeSheetRow('Sheet'.$sheet, [$table_title],['height'=>32,'font-size'=>20,'font-style'=>'bold','halign'=>'center','valign'=>'center']);
$class_xls->writeSheetRow('Sheet'.$sheet, $title, $styles1);
foreach ($v as $key=>$item){
$row_data = array_values($item);
$class_xls->writeSheetRow('Sheet'.$sheet, $row_data, ['height'=>16]);
}
$class_xls->markMergedCell('Sheet'.$sheet, $start_row = 0, $start_col = 0, $end_row = 0, $end_col = $field_num);
}
$class_xls->writeToStdOut();
die;
}
} }
\ No newline at end of file
...@@ -359,6 +359,7 @@ Route::group('index', [ ...@@ -359,6 +359,7 @@ Route::group('index', [
'getRandKingList' => ['index/RankingList/getRandKingList', ['method' => 'GET|POST']], //设置角色站点 'getRandKingList' => ['index/RankingList/getRandKingList', ['method' => 'GET|POST']], //设置角色站点
'exportReport' => ['index/RankingList/exportReport', ['method' => 'GET|POST']],
]); ]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment