(*
Showing
3 changed files
with
26 additions
and
2 deletions
| ... | @@ -20,4 +20,12 @@ class Song extends BaseModel | ... | @@ -20,4 +20,12 @@ class Song extends BaseModel |
| 20 | { | 20 | { |
| 21 | return $this->belongsToMany(ContractDetail::class, 'contract_song', 'song_id', 'contract_detail_id'); | 21 | return $this->belongsToMany(ContractDetail::class, 'contract_song', 'song_id', 'contract_detail_id'); |
| 22 | } | 22 | } |
| 23 | |||
| 24 | /** | ||
| 25 | * @return \Illuminate\Database\Eloquent\Relations\HasOne | ||
| 26 | */ | ||
| 27 | public function cover() | ||
| 28 | { | ||
| 29 | return $this->hasOne(SongFile::class, 'song_id')->where('type', 4); | ||
| 30 | } | ||
| 23 | } | 31 | } | ... | ... |
app/Models/Legal/SongFile.php
0 → 100644
| ... | @@ -32,7 +32,7 @@ class MusicianSongService extends Service | ... | @@ -32,7 +32,7 @@ class MusicianSongService extends Service |
| 32 | 32 | ||
| 33 | 33 | ||
| 34 | $res = Song::query()->join($songip_table, "{$song_table}.id", '=', "{$songip_table}.song_id") | 34 | $res = Song::query()->join($songip_table, "{$song_table}.id", '=', "{$songip_table}.song_id") |
| 35 | ->with('contractDetail')->whereIn("{$songip_table}.song_id", $song_ids)->select(["{$song_table}.id", 'publish_song']) | 35 | ->with(['contractDetail', 'cover'])->whereIn("{$songip_table}.song_id", $song_ids)->select(["{$song_table}.id", 'publish_song']) |
| 36 | ->groupBy(["song_id"])->paginate($this->pageSize); | 36 | ->groupBy(["song_id"])->paginate($this->pageSize); |
| 37 | 37 | ||
| 38 | foreach ($res as &$item) { | 38 | foreach ($res as &$item) { |
| ... | @@ -40,7 +40,7 @@ class MusicianSongService extends Service | ... | @@ -40,7 +40,7 @@ class MusicianSongService extends Service |
| 40 | 40 | ||
| 41 | $item->setAttribute('name', $name); | 41 | $item->setAttribute('name', $name); |
| 42 | $item->setAttribute('singer', $singer); | 42 | $item->setAttribute('singer', $singer); |
| 43 | $item->setAttribute('cover', ''); | 43 | $item->setAttribute('cover', $item->cover->url ?: ''); |
| 44 | 44 | ||
| 45 | $tmp = $item->toArray(); | 45 | $tmp = $item->toArray(); |
| 46 | if (empty($tmp['contract_detail'])) { | 46 | if (empty($tmp['contract_detail'])) { | ... | ... |
-
Please register or sign in to post a comment