ActivityExcel.php
3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
namespace App\Excel;
use App\Models\SystemConfig;
use App\Support\ExcelExport;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Collection;
class ActivityExcel extends ExcelExport
{
protected Collection $config;
protected function beforeHandle(): void
{
$this->builder->with(['project:id,name', 'user:id,real_name,nick_name,identity', 'tags:id,name', 'submitUsers:id,nick_name,real_name', 'links:id,nick_name,real_name']);
$this->builder->withCount(['viewUsers', 'collectionUsers', 'submitUsers']);
$this->setHeader(['歌曲名称', '推荐描述', '曲风标签', '歌曲语种', '歌曲速度', '关联厂牌', '词作者', '曲作者', '编曲', '性别要求', '预期发行日期', '试听人数', '收藏人数', '提交人数', '提交用户', '创建人艺名', '创建人真名', '创建时间', '通过时间 ', '确认时间', '匹配时间', '状态']);
$this->setColumns(['A:I' => 18, 'J:U' => 20]);
$this->config = SystemConfig::query()
->whereHas('parent', fn(Builder $builder) => $builder->whereIn('identifier', ['activity_lang', 'activity_speed', 'activity_sex']))
->pluck('name', 'identifier');
}
protected function setData($item): array
{
$lyricistIds = data_get($item, 'expand.lyricist.ids', []);
$lyricistNames = data_get($item, 'expand.lyricist.supplement', []);
$composerIds = data_get($item, 'expand.composer.ids', []);
$composerNames = data_get($item, 'expand.composer.supplement', []);
$arrangerIds = data_get($item, 'expand.arranger.ids', []);
$arrangerNames = data_get($item, 'expand.arranger.supplement', []);
$lang = data_get($item, 'lang', []);
return [
$item->song_name,
$item->sub_title,
$item->getRelation('tags')?->implode('name', ',') ?? '',
$this->config->only($lang)?->implode(','),
$this->config->get($item->speed),
$item->getRelation('project')?->getAttribute('name') ?? '无关联厂牌',
$item->getRelation('links')->whereIn('id', $lyricistIds)->pluck('nick_name')?->unique()?->merge($lyricistNames)?->implode(','),
$item->getRelation('links')->whereIn('id', $composerIds)->pluck('nick_name')?->unique()?->merge($composerNames)?->implode(','),
$item->getRelation('links')->whereIn('id', $arrangerIds)->pluck('nick_name')?->unique()?->merge($arrangerNames)?->implode(','),
$this->config->get($item->sex),
$item->estimate_release_at,
$item->view_users_count ?? 0,
$item->collection_users_count ?? 0,
$item->submit_users_count ?? 0,
$item->getRelation('submitUsers')?->implode('nick_name', ','),
$item->getRelation('user')?->getAttribute('nick_name'),
$item->getRelation('user')?->getAttribute('real_name'),
(string)$item->created_at,
(string)$item->audit_at,
(string)$item->match_at,
$item->match_day . ' 天',
$item->status?->label(),
];
}
}