MusicianSongService.php
1.88 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
<?php
namespace App\Services\V2;
use App\Helper\CosHelper;
use App\Helper\Response;
use App\Models\Legal\Contract;
use App\Models\Legal\Song;
use App\Models\Legal\SongsIp;
use App\Models\Legal\SongsIpExts;
use App\Models\Legal\SongStakeholder;
use App\Services\Service;
use Illuminate\Database\Eloquent\Builder;
/**
 * Class MusicianSongService
 * @package App\Services
 */
class MusicianSongService extends Service
{
    /**
     * 授权发行歌曲
     * @return \Illuminate\Http\JsonResponse
     */
    public function releaseSong()
    {
        $song_ids  =  array_filter(array_unique(SongStakeholder::query()->identify()->pluck('song_id')->toArray()));
        if (empty($song_ids)) return Response::success();
        $res =  Song::query()->join('songs_ip', "songs.id", '=', "songs_ip.song_id")
                    ->join('songs_ip_exts as ext', 'songs_ip.id', '=', 'ext.song_ip_id')
                    ->whereIn("songs.id", $song_ids)->whereNull("songs_ip.deleted_at")
                    ->where('auth_channel', 1)->select(["songs.id", "songs_ip.id as sp_id", 'track_name',
                        'singer_name', 'album_name', 'tme_id', 'track_cover', 'tme_company_id', 'public_time', 'track_version', 'favCnt', 'playCnt', 'downloadCnt',
                        'favCnt_week', 'playCnt_week', 'downloadCnt_week', 'favCnt_years', 'playCnt_years', 'downloadCnt_years',
                    ])
                    ->when(filled($this->request->name), function (Builder $builder) {
                        $builder->where(function (Builder $builder){
                            $builder->where('album_name', 'like', "{$this->request->name}")
                                ->orWhere('track_name', 'like', "{$this->request->name}");
                        });
                    })
                    ->sorted($this->request->sort)->paginate($this->pageSize);
        return Response::success($res);
    }
}