Commit 6fe52fec 6fe52fecbb552f4631b225b0b321b8d1e56922f2 by lemon

授权歌曲信息

1 parent e77ede5c
<?php
namespace App\Http\Controllers\Musician\V2;
use App\Http\Controllers\Controller;
use App\Services\V2\MusicianSongService;
/**
* Class MusicianSongController
* @package App\Http\Controllers\Musician
*/
class MusicianSongController extends Controller
{
/**
* @var MusicianSongService
*/
protected $musicianSongService;
/**
* MusicianSongController constructor.
* @param MusicianSongService $musicianSongService
*/
public function __construct(MusicianSongService $musicianSongService)
{
$this->musicianSongService = $musicianSongService;
}
/**
* @return \Illuminate\Http\JsonResponse
*/
public function list()
{
return $this->musicianSongService->releaseSong();
}
}
......@@ -58,6 +58,8 @@ class BaseModel extends Model
return $builder;
}
/**
* @param Builder $builder
* @return Builder
......@@ -67,5 +69,21 @@ class BaseModel extends Model
return $builder->whereIn('stakeholder_id', request()->get('stakeholder_ids'));
}
/**
* 排序
* @param $sort
* @return mixed
*/
public function scopeSorted(Builder $query, $sort): Builder
{
$table = (new static)->getTable();
try {
$sort = json_decode($sort, true);
return $query->orderBy($sort['prop'] ?? "{$table}.updated_at", $sort['order'] ?? 'desc');
} catch (\Exception $e) {
return $query->orderBy("{$table}.updated_at", 'desc');
}
}
}
......
......@@ -44,18 +44,13 @@ class RouteServiceProvider extends ServiceProvider
->namespace($this->namespace . '\Musician')
->group(base_path('routes/api.php'));
//公用
Route::prefix('common')
->middleware('api')
->namespace($this->namespace . '\Common')
->group(base_path('routes/common.php'));
//后台
Route::prefix('admin')
->middleware('api')
->namespace($this->namespace . '\Admin')
->group(base_path('routes/admin.php'));
//web
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web.php'));
......
<?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', '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);
}
}
......@@ -52,3 +52,8 @@ Route::group([], function (){
});
//api-v2
Route::group(["prefix"=>"v2", "namespace"=>"V2"], function (){
Route::get('musician_song', 'MusicianSongController@list');
});
......
<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
Route::group([], function (){
//首页-最新发行作品
Route::get('release_song', 'ReleaseSongController@list');
});