*
Showing
2 changed files
with
7 additions
and
6 deletions
| ... | @@ -25,7 +25,7 @@ class Song extends BaseModel | ... | @@ -25,7 +25,7 @@ class Song extends BaseModel |
| 25 | /** | 25 | /** |
| 26 | * @return \Illuminate\Database\Eloquent\Relations\HasOne | 26 | * @return \Illuminate\Database\Eloquent\Relations\HasOne |
| 27 | */ | 27 | */ |
| 28 | public function cover() | 28 | public function coverResource() |
| 29 | { | 29 | { |
| 30 | return $this->hasOne(SongFile::class, 'song_id')->where('type', 4); | 30 | return $this->hasOne(SongFile::class, 'song_id')->where('type', 4); |
| 31 | } | 31 | } | ... | ... |
| ... | @@ -31,20 +31,21 @@ class MusicianSongService extends Service | ... | @@ -31,20 +31,21 @@ class MusicianSongService extends Service |
| 31 | $songip_table = SongsIp::table(); | 31 | $songip_table = SongsIp::table(); |
| 32 | 32 | ||
| 33 | $res = Song::query()->join($songip_table, "{$song_table}.id", '=', "{$songip_table}.song_id") | 33 | $res = Song::query()->join($songip_table, "{$song_table}.id", '=', "{$songip_table}.song_id") |
| 34 | ->with(['contractDetail', 'cover'])->whereIn("{$songip_table}.song_id", $song_ids)->select(["{$song_table}.id", 'publish_song']) | 34 | ->with(['contractDetail', 'coverResource'])->whereIn("{$songip_table}.song_id", $song_ids)->select(["{$song_table}.id", 'publish_song']) |
| 35 | ->groupBy(["song_id"])->paginate($this->pageSize); | 35 | ->groupBy(["song_id"])->get(); |
| 36 | 36 | ||
| 37 | foreach ($res as &$item) { | 37 | foreach ($res as &$item) { |
| 38 | |||
| 38 | list($name, $singer) = explode('|', $item->publish_song); | 39 | list($name, $singer) = explode('|', $item->publish_song); |
| 39 | 40 | ||
| 40 | $item->setAttribute('name', $name); | 41 | $item->setAttribute('name', $name); |
| 41 | $item->setAttribute('singer', $singer); | 42 | $item->setAttribute('singer', $singer); |
| 42 | $item->setAttribute('cover', empty($item->cover->url) ? '' : $item->cover->url); | 43 | $item->setAttribute('cover', empty($item->coverResource) ? '' : $item->coverResource->url); |
| 43 | 44 | ||
| 44 | $tmp = $item->toArray(); | 45 | $tmp = $item->toArray(); |
| 45 | if (empty($tmp['contract_detail'])) { | 46 | if (empty($tmp['contract_detail'])) { |
| 46 | $item->setAttribute('role', []); | 47 | $item->setAttribute('role', []); |
| 47 | unset($item->contractDetail); | 48 | unset($item->contractDetail, $item->publish_song, $item->coverResource); |
| 48 | continue; | 49 | continue; |
| 49 | } | 50 | } |
| 50 | 51 | ||
| ... | @@ -61,7 +62,7 @@ class MusicianSongService extends Service | ... | @@ -61,7 +62,7 @@ class MusicianSongService extends Service |
| 61 | } | 62 | } |
| 62 | } | 63 | } |
| 63 | $item->setAttribute('role', array_unique($role)); | 64 | $item->setAttribute('role', array_unique($role)); |
| 64 | unset($item->contractDetail, $item->publish_song); | 65 | unset($item->contractDetail, $item->publish_song, $item->coverResource); |
| 65 | } | 66 | } |
| 66 | 67 | ||
| 67 | return Response::success($res); | 68 | return Response::success($res); | ... | ... |
-
Please register or sign in to post a comment