48 lines
1.3 KiB
PHP
48 lines
1.3 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Exports;
|
||
|
|
|
||
|
|
use Maatwebsite\Excel\Concerns\WithHeadings; //设置标题
|
||
|
|
use Maatwebsite\Excel\Concerns\WithStrictNullComparison; //为空时零填充
|
||
|
|
use Maatwebsite\Excel\Concerns\ShouldAutoSize; //自动单元格尺寸
|
||
|
|
use PhpOffice\PhpSpreadsheet\Style\NumberFormat; //设置单元格数据格式
|
||
|
|
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
|
||
|
|
use Maatwebsite\Excel\Concerns\FromCollection;
|
||
|
|
use App\Models\Wechat;
|
||
|
|
use App\Models\User;
|
||
|
|
use App\Models\ReferreAwardHistory;
|
||
|
|
use Illuminate\Support\Collection;
|
||
|
|
class RedPacketExport implements FromCollection ,WithHeadings,WithStrictNullComparison,WithColumnFormatting,ShouldAutoSize
|
||
|
|
{
|
||
|
|
private $data;
|
||
|
|
public function __construct($data)
|
||
|
|
{
|
||
|
|
$this->data = $data;
|
||
|
|
}
|
||
|
|
public function headings(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'id',
|
||
|
|
'用户id',
|
||
|
|
'类型',
|
||
|
|
'openid',
|
||
|
|
'金额',
|
||
|
|
'是否发放',
|
||
|
|
'手机号',
|
||
|
|
'名字'
|
||
|
|
];
|
||
|
|
}
|
||
|
|
//设置列格式
|
||
|
|
public function columnFormats(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'A' => NumberFormat::FORMAT_TEXT,
|
||
|
|
];
|
||
|
|
}
|
||
|
|
public function collection()
|
||
|
|
{
|
||
|
|
$data = collect($this->data);
|
||
|
|
return $data;
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|