ConfigHelper.php
7.23 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?php
namespace App\Helpers;
use App\Models\Activity;
use App\Models\SystemConfig;
use Arr;
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
use Illuminate\Support\Collection as SupportCollection;
use Str;
class ConfigHelper
{
public const DEMO_TAG_KEY = 'CtGly-jsLjAu5yJvLrN7L';
public const DEMO_USER_KEY = 'n3HCbruqL_DemfX9MHj-K';
public const LISTEN_USER_KEY = '-BIGBAR9rPOMwCrw4hIuQ';
public const SING_USER_KEY = 'Jy-zgPbcSXSGnvHIx8moq';
public const SINGER_TAG_KEY = 'auth_singer_tag';
public const BUSINESS_SINGER_LIMIT = 'svMC9TNFz2Acx8ccPdAIH';
public const INFO_SCORE_LIMIT_KEY = 'iymo-wZcV2F0UWFUKJR5m';
public const INFO_SCORE_TEXT_KEY = 'YmSNBXwMB6cUo-zRT26s-';
public const INFO_SCORE_CONTENT_KEY = 'TeZnnaB-Pfwyz8IADs0SM';
/**
* @param string $identifier
* @param string $column
* @return ?string
*/
public static function getContent(string $identifier, string $column = 'content'): ?string
{
return SystemConfig::withoutGlobalScope('show')->where('status', 1)->where('identifier', $identifier)->value($column);
}
/**
* @param string|array $identifier
* @param string $column
* @return \Illuminate\Support\Collection
*/
public static function getList(string|array $identifier, string $column = 'content'): SupportCollection
{
return SystemConfig::withoutGlobalScope('show')->where('status', 1)->whereIn('identifier', Arr::wrap($identifier))->pluck($column, 'identifier');
}
/**
* @param string|array $identifier
* @param string $column
* @return \Illuminate\Support\Collection
*/
public static function getChildrenList(string|array $identifier, string $column = 'content'): SupportCollection
{
return SystemConfig::withoutGlobalScope('show')->parentKey($identifier)->where('status', 1)->pluck($column, 'identifier');
}
/**
* 获取歌手标签Ids
* @return array
*/
public static function getSingerTagIds(): array
{
return array_filter(explode(',', self::getContent(self::SINGER_TAG_KEY)));
}
/**
* 获取Demo标签Ids
* @return array
*/
public static function getDemoTagIds(): array
{
return array_filter(explode(',', self::getContent(self::DEMO_TAG_KEY)));
}
/**
* 获取Demo白名单用户Ids
* @return array
*/
public static function getDemoUserIds(): array
{
return array_filter(explode(',', self::getContent(self::DEMO_USER_KEY)));
}
/**
* @return \Illuminate\Support\Collection
*/
public static function getDemoList(): SupportCollection
{
return self::getList([self::DEMO_TAG_KEY, self::DEMO_USER_KEY])?->map(fn($item) => array_filter(explode(',', $item)));
}
/**
* 获取试听权限白名单用户Ids
* @return array
*/
public static function getListenUserIds(): array
{
return array_filter(explode(',', self::getContent(self::LISTEN_USER_KEY)));
}
/**
* 获取试听&试唱权限白名单用户Ids
* @return array
*/
public static function getSingUserIds(): array
{
return array_filter(explode(',', self::getContent(self::SING_USER_KEY)));
}
/**
* 获取试听与试唱白名单Ids
* @return \Illuminate\Support\Collection
*/
public static function getListenAndSingUserList(): SupportCollection
{
return self::getList([self::LISTEN_USER_KEY, self::SING_USER_KEY])?->map(fn($item) => array_filter(explode(',', $item)));
}
/**
* @return int
*/
public static function getProjectLimitDay(): int
{
return intval(self::getContent('i9V0wD_FitcGXR3HxUK5C')) ?? 7;
}
/**
* @return int
*/
public static function getBusinessSingerLimit(): int
{
return intval(self::getContent(self::BUSINESS_SINGER_LIMIT)) ?? 3;
}
/**
* @return array
*/
public static function getTelescopeIpList(): array
{
return array_filter(explode(',', self::getContent('telescope_ip')));
}
/**
* @param array|int $tagIds
* @param array|null $singerTagIds
* @return bool
*/
public static function hasSingerTag(array|int $tagIds, array $singerTagIds = NULL): bool
{
return filled(array_intersect(Arr::wrap($tagIds), $singerTagIds ?? self::getSingerTagIds()));
}
/**
* @param array|int $tagIds
* @param array|NULL $demoTagIds
* @return bool
*/
public static function hasDemoTag(array|int $tagIds, array $demoTagIds = NULL): bool
{
return filled(array_intersect(Arr::wrap($tagIds), $demoTagIds ?? self::getDemoTagIds()));
}
/**
* @return \Illuminate\Support\Collection
*/
public static function getInfoScore(): SupportCollection
{
return self::getList([self::INFO_SCORE_LIMIT_KEY, self::INFO_SCORE_TEXT_KEY])->map(fn($item, $key) => match ($key) {
self::INFO_SCORE_LIMIT_KEY => (int)$item,
self::INFO_SCORE_TEXT_KEY => Str::isJson($item) ? json_decode($item, false, 512, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE) : [],
default => $item,
})->put(self::INFO_SCORE_CONTENT_KEY, self::getChildrenList(self::INFO_SCORE_CONTENT_KEY));
}
/**
* @return \Illuminate\Database\Eloquent\Collection
*/
public static function getActivityDictionary(): EloquentCollection
{
return SystemConfig::parentKey(['activity_mark', 'activity_lang', 'activity_speed', 'activity_sex'])->where('status', 1)->get(['name', 'identifier', 'content']);
}
/**
* @param \App\Models\Activity $activity
* @param \Illuminate\Database\Eloquent\Collection|null $dictionary
* @return \App\Models\Activity
*/
public static function formatActivityDictionary(Activity $activity, EloquentCollection $dictionary = NULL): Activity
{
$dictionary = $dictionary ?? self::getActivityDictionary();
$activity->loadMissing('linkArranger:id,nick_name');
$activity->setAttribute('sex', $dictionary->where('identifier', $activity->getAttribute('sex'))->value('name', ''));
$activity->setAttribute('speed', $dictionary->where('identifier', $activity->getAttribute('speed'))->value('name', ''));
$activity->setAttribute('mark', $dictionary->where('identifier', $activity->getAttribute('mark'))->value('content', ''));
$activity->setAttribute('lang', $dictionary->whereIn('identifier', $activity->getAttribute('lang'))->pluck('name'));
$activity->setAttribute('arranger', ['in_side' => $activity->getAttribute('linkArranger'), 'out_side' => data_get($activity->getAttribute('expand'), 'arranger.supplement', [])]);
return $activity;
}
/**
* @param \Illuminate\Database\Eloquent\Collection|\Illuminate\Support\Collection $collection
* @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Support\Collection
*/
public static function formatManyActivityDictionary(EloquentCollection|SupportCollection $collection): EloquentCollection|SupportCollection
{
$dictionary = self::getActivityDictionary();
return $collection->each(fn($item) => self::formatActivityDictionary($item, $dictionary));
}
}