UserRegisterExcel.php
1.37 KB
<?php
namespace App\Excel;
use App\Enums\UserSexEnum;
use App\Support\ExcelExport;
use Illuminate\Support\Arr;
class UserRegisterExcel extends ExcelExport
{
protected function beforeHandle(): void
{
$this->builder->addSelect(['company'])->with(['styleTags:id,name']);
$this->setHeader(['用户艺名', '用户真名', '性别', '用户邮箱', '手机号码', '注册时间', '用户权限', '是否关注公众号', '公司', '常居地', '擅长的曲风', '状态']);
$this->setColumns(['A:L' => 20]);
}
protected function setData($item): array
{
return Arr::map([
$item->getAttribute('nick_name'),
$item->getAttribute('real_name'),
UserSexEnum::tryFrom($item->getAttribute('sex'))?->label(),
$item->getAttribute('email'),
sprintf('(%s)%s', $item->getFullPhone()->getPrefixedIDDCode('+'), $item->getFullPhone()->getNumber()),
(string)$item->getAttribute('created_at'),
$item->getAttribute('scope')?->label(),
$item->getAttribute('official_status')?->label(),
$item->getAttribute('company'),
$item->getFullAddress(),
$item->getRelation('styleTags')?->implode('name', ',') ?? '无',
$item->getAttribute('status')?->label(),
], static fn($value) => empty($value) ? '无' : $value);
}
}