海工商新版后台
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.
 
 

73 lines
2.2 KiB

<?php
namespace App\Admin\Extensions\Exporter;
use App\Models\UserFollowStatus;
use Dcat\Admin\Grid\Exporters\AbstractExporter;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Events\AfterSheet;
class FollowStatisticsExporter extends AbstractExporter implements WithMapping, WithHeadings, FromCollection
{
use Exportable;
protected $titles = [];
public function __construct()
{
$this->fileName = '新生回访统计数据-' . date('Y-m-d') . '.xlsx'; //拼接下载文件名称
$this->titles = ['学院基础信息', '', '总录取', '', '', '未联系', '', ''];
foreach (UserFollowStatus::query()->orderBy('id', 'asc')->get('name')->toArray() as $key => $item) {
$this->titles[] = $item['name'];
$this->titles[] = '';
$this->titles[] = '';
}
parent::__construct();
}
public function export()
{
// TODO: Implement export() method.
$this->download($this->fileName)->prepare(request())->send();
exit;
}
public function collection()
{
$data = $this->buildData();
$newData[2] = ['二级学院', '专业', '总人数', '男生', '女生', '总人数', '男生', '女生'];
foreach (UserFollowStatus::query()->get('id')->toArray() as $key => $item) {
$newData[2][] = '总人数';
$newData[2][] = '男生';
$newData[2][] = '女生';
}
foreach ($data as $key => $item) {
$newData[] = $item;
}
// TODO: Implement collection() method.
return collect($newData);
}
public function headings(): array
{
// TODO: Implement headings() method.
return $this->titles;
}
public function map($row): array
{
// 直接返回row 导出全部字段 dd($row);
// return $row;
foreach ($row as $k => $v) {
$row[$k] = (string)$v;
}
// TODO: Implement map() method.
return $row;
}
}