链街Dcat后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

115 lines
3.4 KiB

<?php
namespace App\Admin\Actions\Exporter;
use Maatwebsite\Excel\Concerns\FromArray;
use Maatwebsite\Excel\Concerns\WithStrictNullComparison;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithStyles;
use Maatwebsite\Excel\Concerns\WithTitle;
use App\Admin\Repositories\v3\ReportCommunity as ReportCommunityRepository;
use App\Models\v3\Market as MarketModel;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
class ReportCommunity implements FromArray, WithStrictNullComparison, ShouldAutoSize, WithTitle, WithHeadings, WithStyles
{
protected $params = [];
public function __construct($params)
{
$this->params = $params;
}
public function headings(): array
{
$startTime = $this->params['start_time'] ?? null;
$endTime = $this->params['end_time'] ?? null;
$nowDay = date('Y年m月d日', time());
if(empty($startTime)){
$startTime = '2020年7月1日';
}else if(empty($endTime)){
$endTime = $nowDay;
}
return [
'统计时间:'.$startTime.' 至 '.$endTime
];
}
public function styles(Worksheet $sheet)
{
$sheet->mergeCells('A1:H1');// 合并
$sheet->getRowDimension(1)->setRowHeight(40); // 行高
$sheet->getRowDimension(2)->setRowHeight(25); // 行高
$sheet->getStyle('A1:H1')->getAlignment()->setVertical('center');// 垂直居中
$sheet->getStyle('A1:H1')->getAlignment()->setHorizontal('center');// 水平居中
$sheet->getStyle('A2:H2')->getAlignment()->setVertical('center');// 垂直居中
return [
1 => ['font' => ['bold' => true,'size' => 18, 'name' => '微软雅黑 Light']],
2 => ['font' => ['bold' => true,'size' => 12, 'name' => '微软雅黑 Light']],
];
}
public function array(): array
{
$result = [[
'市场',
'懒ID',
'姓名',
'新拓展代理点数',
'新增绑定用户数',
'平台新增用户数',
'绑定用户线上订单总数',
'平台新增用户线上订单数'
]];
$data = $this->getData($this->params);
if(!isset($data['data']) ){
$data['data'] = [];
}
$markets = MarketModel::getMarketArray();
foreach ($data['data'] as $value){
$item = [
$markets[$value['market_id']] ?? '',
$value['user_id'] ?? 0,
$value['name'] ?? '',
$value['new_cs_count'] ?? 0,
$value['new_bind_user_count'] ?? 0,
$value['plat_new_user_count'] ?? 0,
$value['bound_order_online_count'] ?? 0,
$value['plat_new_user_order_online_count'] ?? 0,
];
$result[] = $item;
}
return $result;
}
/**
* 获取数据
*/
public function getData($option = [])
{
$params = $option;
$repository = new ReportCommunityRepository();
$selects = 'id,user_id,market_id,name';
$data = $repository->getDataModel($selects,$params,false);
return $data;
}
/**
* sheet 表名称
* @return string
*/
public function title(): string
{
return '统计';
}
}