1
0
Files
lkafu/app/Admin/Exporters/CardExporters.php
2020-08-06 14:45:56 +08:00

44 lines
1.4 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Admin\Exporters;
use App\Models\User;
use Encore\Admin\Grid\Exporters\CsvExporter;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\WithStrictNullComparison;
class CardExporters extends CsvExporter implements WithMapping, WithStrictNullComparison
{
protected $fileName = '联卡蝠激活卡.csv';
protected $mapTrue = true;
protected $users = [];
public function __construct()
{
$this->fileName = '联卡蝠激活卡' . date('YmdHis') . '.csv';
$this->users = User::pluck('username', 'id')->toArray();
}
protected $headings = ['卡序号', '归属', '卡号', '打印卡号', '卡密', '类型', '专项', '状态', '激活用户', '激活时间', '创建时间', '更改时间'];
public function map($info): array
{
$data = [
$info->id,
$this->users[$info->user_id] ?? '无',
'`' . $info->code,
$info->type . $info->code,
$info->pass,
$info->type,
$info->type == 'K' ? '商品ID' . $info->source['goods'] . '规格ID' . $info->source['param'] : '非专项',
$info->status_text,
$this->users[$info->active_id] ?? '无',
$info->actived_at,
$info->created_at,
$info->updated_at,
];
return $data;
}
}