Commit 7d117511 7d117511057af6fd2266d5b1f8d06f95bc38d8ef by lemon

(*

1 parent 7dca7a31
......@@ -20,4 +20,12 @@ class Song extends BaseModel
{
return $this->belongsToMany(ContractDetail::class, 'contract_song', 'song_id', 'contract_detail_id');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
public function cover()
{
return $this->hasOne(SongFile::class, 'song_id')->where('type', 4);
}
}
......
<?php
namespace App\Models\Legal;
use App\Models\BaseModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
/**
* Class SongFile
* @package App\Models\Legal
*/
class SongFile extends BaseModel
{
use HasFactory;
}
......@@ -32,7 +32,7 @@ class MusicianSongService extends Service
$res = Song::query()->join($songip_table, "{$song_table}.id", '=', "{$songip_table}.song_id")
->with('contractDetail')->whereIn("{$songip_table}.song_id", $song_ids)->select(["{$song_table}.id", 'publish_song'])
->with(['contractDetail', 'cover'])->whereIn("{$songip_table}.song_id", $song_ids)->select(["{$song_table}.id", 'publish_song'])
->groupBy(["song_id"])->paginate($this->pageSize);
foreach ($res as &$item) {
......@@ -40,7 +40,7 @@ class MusicianSongService extends Service
$item->setAttribute('name', $name);
$item->setAttribute('singer', $singer);
$item->setAttribute('cover', '');
$item->setAttribute('cover', $item->cover->url ?: '');
$tmp = $item->toArray();
if (empty($tmp['contract_detail'])) {
......