50 lines
1.6 KiB
PHP
50 lines
1.6 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 ActivityApplyUserExport implements FromCollection ,WithHeadings,WithStrictNullComparison,WithColumnFormatting,ShouldAutoSize
|
|
{
|
|
private $data;
|
|
public function __construct($data)
|
|
{
|
|
$this->data = $data;
|
|
}
|
|
public function headings(): array
|
|
{
|
|
return [
|
|
'姓名',
|
|
'手机号',
|
|
'是否签到',
|
|
'签到时间',
|
|
];
|
|
}
|
|
//设置列格式
|
|
public function columnFormats(): array
|
|
{
|
|
return [
|
|
'A' => NumberFormat::FORMAT_TEXT,
|
|
];
|
|
}
|
|
public function collection()
|
|
{
|
|
$arr = [];
|
|
foreach ($this->data as $data) {
|
|
$arr[] = ['name'=>$data->name, 'mobile'=>$data->mobile, 'sex'=>(empty($data->sex)?"未知":($data->sex == 1?"男":"女")), 'hidden_profile'=>$data->hidden_profile == 'ALLSEX'?"已关闭":"未关闭",
|
|
'is_sign'=>$data->is_sign?'已签到':'未签到','sign_time'=>$data->sign_time];
|
|
}
|
|
$arr = collect($arr);
|
|
return $arr;
|
|
}
|
|
|
|
}
|