Commit 7d117511 7d117511057af6fd2266d5b1f8d06f95bc38d8ef by lemon

(*

1 parent 7dca7a31
...@@ -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 }
......
1 <?php
2
3 namespace App\Models\Legal;
4
5 use App\Models\BaseModel;
6 use Illuminate\Database\Eloquent\Factories\HasFactory;
7
8 /**
9 * Class SongFile
10 * @package App\Models\Legal
11 */
12 class SongFile extends BaseModel
13 {
14 use HasFactory;
15
16 }
...@@ -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'])) {
......