Activity.php
9.26 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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<?php
namespace App\Models;
use App\Enums\ActivityStatusEnum;
use App\Enums\ActivityWorkTypeEnum;
use App\Models\Pivots\ActivityLinkPivot;
use App\Models\Pivots\ActivityTagPivot;
use App\Models\Pivots\UserActivityCollectionPivot;
use App\Models\Pivots\UserActivityViewPivot;
use App\Models\Pivots\UserProjectPivot;
use App\Models\Views\UserManageActivity;
use App\Support\Model;
use App\Traits\JsonColumnDirtyTrait;
use Awobaz\Compoships\Database\Eloquent\Relations\BelongsTo;
use Awobaz\Compoships\Database\Eloquent\Relations\HasMany;
use Awobaz\Compoships\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* @method static Builder statusOfUp()
*/
class Activity extends Model
{
use SoftDeletes, JsonColumnDirtyTrait;
protected $table = 'activitys';
protected $guarded = [];
/**
* @var string[]
*/
protected $hidden = ['deleted_at'];
/**
* @var array<string,mixed>
*/
protected $casts = [
'status' => ActivityStatusEnum::class,
'created_form' => 'int',
'audit_status' => 'int',
'is_push' => 'int',
'song_type' => 'int',
'weight' => 'int',
'expand' => 'json',
'lang' => 'array',
'send_url' => 'array',
'push_type' => 'array',
'user_id' => 'int'
];
/**
* @var array<string,string>
*/
public array $columnMap = [
'cover' => '封面图片',
'song_name' => '歌曲名称',
'lang' => '语种',
'speed' => '语速',
'mark' => '角标',
'is_official' => '奖励标识',
'push_type' => '推送方式',
'sub_title' => '歌曲简介',
'project_id' => '关联厂牌',
'sex' => '性别要求',
'lyric' => '歌词文本',
'clip_lyric' => '片段歌词',
'manage_link' => '外部管理员',
'estimate_release_at' => '预计发行日期',
'expand->tag_ids' => '曲风标签',
'expand->lyricist->ids' => '词作者(用户)',
'expand->lyricist->supplement' => '词作者(未注册)',
'expand->composer->ids' => '曲作者(用户)',
'expand->composer->supplement' => '曲作者(未注册)',
'expand->arranger->ids' => '编曲(用户)',
'expand->arranger->supplement' => '编曲(未注册)',
'expand->guide_source->url' => '导唱文件',
'expand->karaoke_source->url' => '伴奏文件',
'expand->track_source->url' => '分轨文件',
];
public function scopeStatusOfUp(Builder $builder): Builder
{
return $builder->where($this->qualifyColumn('audit_status'), 1)->where($this->qualifyColumn('status'), 1);
}
/**
* @param $clip_lyric
* @return string
*/
public function getClipLyricAttribute($clip_lyric): string
{
return $clip_lyric ?? '';
}
/**
* @param $lang
* @return array
* @throws \JsonException
*/
public function getLangAttribute($lang): array
{
return is_null($lang) ? [] : json_decode($lang, false, 512, JSON_THROW_ON_ERROR);
}
/**
* @return \Awobaz\Compoships\Database\Eloquent\Relations\BelongsTo
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class)->withTrashed();
}
/**
* @return \Awobaz\Compoships\Database\Eloquent\Relations\BelongsTo
*/
public function project(): BelongsTo
{
return $this->belongsTo(Project::class);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function is_unlike(): BelongsToMany
{
return $this->belongsToMany(User::class, UserActivityUnlikes::class, 'activity_id', 'user_id');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function tags(): BelongsToMany
{
return $this
->belongsToMany(SystemTag::class, ActivityTagPivot::class, 'activity_id', 'tag_id')
->wherePivotNull('deleted_at')->orderBy('id', 'asc')->withTimestamps();
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function viewUsers(): BelongsToMany
{
return $this->belongsToMany(User::class, UserActivityViewPivot::class, 'activity_id', 'user_id')
->wherePivotNull('deleted_at');
}
/**
* @return \Awobaz\Compoships\Database\Eloquent\Relations\HasMany
*/
public function viewUsersCount(): HasMany
{
return $this->hasMany(UserActivityViewPivot::class)->whereNull('deleted_at');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function collectionUsers(): BelongsToMany
{
return $this->belongsToMany(User::class, UserActivityCollectionPivot::class, 'activity_id', 'user_id')
->wherePivotNull('deleted_at');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function workUsers(): BelongsToMany
{
return $this->belongsToMany(User::class, ActivityUser::class, 'activity_id', 'user_id');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function submitUsers(): BelongsToMany
{
return $this->workUsers()->wherePivot('type', ActivityWorkTypeEnum::SUBMIT)->orderBy('id', 'asc');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function saveUsers(): BelongsToMany
{
return $this->workUsers()->wherePivot('type', ActivityWorkTypeEnum::SAVE);
}
/**
* @return \Awobaz\Compoships\Database\Eloquent\Relations\HasMany
*/
public function submit(): HasMany
{
return $this->hasMany(ActivityUser::class)->where('type', '=', "Submit")->with(['SelfPrice.AddressInfo', 'ShareUser.user:id,nick_name,real_name', 'unread', 'user.business:id,nick_name,real_name,avatar', 'user:id,nick_name,real_name,avatar,province,city,company,rate,chat_mode,business_id'])->orderBy('created_at', 'desc');
}
/**
* @return HasMany
*/
public function applyRecords(): HasMany
{
return $this->hasMany(ActivityApplyRecord::class)->latest();
}
/**
* @return \Illuminate\Database\Eloquent\Relations\MorphToMany
*/
public function links(): MorphToMany
{
return $this->morphedByMany(User::class, 'link', ActivityLinkPivot::class)->withTrashed();
}
/**
* @return \Awobaz\Compoships\Database\Eloquent\Relations\HasMany
*/
public function outSideManages(): HasMany
{
return $this->hasMany(UserManageActivity::class);
}
public function totalSong(): HasMany
{
return $this->hasMany(__CLASS__, 'project_id', 'project_id')->whereNotIn('activitys.status', [0, 2, 4])->where('activitys.audit_status', 1);
}
public function onlineSong(): HasMany
{
return $this->hasMany(__CLASS__, 'project_id', 'project_id')->where(['status' => 1, 'audit_status' => 1]);
}
public function comfirmTime(): HasOne
{
return $this->hasOne(ProjectConfirmationTime::class, 'project_id', 'project_id');
}
public function sexInfo(): HasOne
{
return $this->hasOne(SystemConfig::class, 'identifier', 'sex');
}
public function publicAudio(): HasOne
{
return $this->hasOne(ActivityUser::class, 'activity_id', 'id')->where(['type' => 'Submit', 'syn_status' => 1, 'is_hide' => 0]);
}
public function linkArranger(): MorphToMany
{
return $this->morphedByMany(User::class, 'link', ActivityLinkPivot::class)->wherePivot('type', 'arranger')->withTrashed();
}
/**
* @return \Awobaz\Compoships\Database\Eloquent\Relations\HasMany
*/
public function attend_user(): HasMany
{
return $this->hasMany(ActivityUser::class)->select('user_id', 'activity_id')->where('type', '=', "Submit")->with(['user:id,nick_name,real_name,intro,avatar,province,city,company,rate'])->orderBy('created_at', 'desc')->limit(6);
}
/**
* @return \Awobaz\Compoships\Database\Eloquent\Relations\HasMany
*/
public function attend_user_count(): HasMany
{
return $this->hasMany(ActivityUser::class)->select('user_id', 'activity_id')->where('type', '=', "Submit");
}
/**
* @return \Awobaz\Compoships\Database\Eloquent\Relations\HasMany
*/
public function attend_union_user_count(): HasMany
{
return $this->hasMany(ActivityUser::class)->select('user_id', 'activity_id')->where('type', '=', "Submit")->distinct();
}
public function is_master(): HasOne
{
return $this->hasOne(UserProjectPivot::class, 'project_id', 'user_id');
}
public function is_confirm_share(): HasOne
{
return $this->hasOne(ActivityShareUser::class, 'activity_id', 'user_id');
}
}