BrokerPushMatchRecordExcel.php 1.39 KB
<?php

namespace App\Excel;

use App\Enums\BrokerPushMatchRecordStatusEnum;
use App\Support\ExcelExport;

class BrokerPushMatchRecordExcel extends ExcelExport
{
    protected function beforeHandle(): void
    {
        $this->builder->with(['activity:id,song_name', 'project:id,name', 'user:id,nick_name', 'broker:id,nick_name']);
        $this->setHeader(['经纪人ID', '经纪人', '分类', '试唱用户ID', '试唱用户', '试唱用户认证', '歌曲厂牌', '关联歌曲ID', '关联歌曲', '通知内容', '发送时间', '发送状态', '用户行为'], 'A1:M1');
        $this->setColumns(['A:E' => 20, 'F:K' => 32, 'L:M' => 20]);
    }

    protected function setData($item): array
    {
        return [
            $item->broker?->id,
            $item->broker?->nick_name,
            $item->broker_level,
            $item->user?->id,
            $item->user?->nick_name,
            $item->user_tag,
            $item->project?->name,
            $item->activity?->id,
            $item->activity?->song_name,
            $item->content,
            $item->send_at,
            BrokerPushMatchRecordStatusEnum::tryFrom($item->status)?->label(),
            $this->formatReadStatus($item->read_at)
        ];
    }

    /**
     * @param $status
     * @return string
     */
    protected function formatReadStatus($status): string
    {
        return is_null($status) ? '未查看' : '已查看';
    }
}