Commit 6fe52fec 6fe52fecbb552f4631b225b0b321b8d1e56922f2 by lemon

授权歌曲信息

1 parent e77ede5c
1 <?php
2
3 namespace App\Http\Controllers\Musician\V2;
4
5 use App\Http\Controllers\Controller;
6 use App\Services\V2\MusicianSongService;
7
8 /**
9 * Class MusicianSongController
10 * @package App\Http\Controllers\Musician
11 */
12 class MusicianSongController extends Controller
13 {
14 /**
15 * @var MusicianSongService
16 */
17 protected $musicianSongService;
18
19 /**
20 * MusicianSongController constructor.
21 * @param MusicianSongService $musicianSongService
22 */
23 public function __construct(MusicianSongService $musicianSongService)
24 {
25 $this->musicianSongService = $musicianSongService;
26 }
27
28 /**
29 * @return \Illuminate\Http\JsonResponse
30 */
31 public function list()
32 {
33 return $this->musicianSongService->releaseSong();
34 }
35 }
...@@ -58,6 +58,8 @@ class BaseModel extends Model ...@@ -58,6 +58,8 @@ class BaseModel extends Model
58 return $builder; 58 return $builder;
59 } 59 }
60 60
61
62
61 /** 63 /**
62 * @param Builder $builder 64 * @param Builder $builder
63 * @return Builder 65 * @return Builder
...@@ -67,5 +69,21 @@ class BaseModel extends Model ...@@ -67,5 +69,21 @@ class BaseModel extends Model
67 return $builder->whereIn('stakeholder_id', request()->get('stakeholder_ids')); 69 return $builder->whereIn('stakeholder_id', request()->get('stakeholder_ids'));
68 } 70 }
69 71
72 /**
73 * 排序
74 * @param $sort
75 * @return mixed
76 */
77 public function scopeSorted(Builder $query, $sort): Builder
78 {
79 $table = (new static)->getTable();
80
81 try {
82 $sort = json_decode($sort, true);
83 return $query->orderBy($sort['prop'] ?? "{$table}.updated_at", $sort['order'] ?? 'desc');
84 } catch (\Exception $e) {
85 return $query->orderBy("{$table}.updated_at", 'desc');
86 }
87 }
70 88
71 } 89 }
......
...@@ -44,18 +44,13 @@ class RouteServiceProvider extends ServiceProvider ...@@ -44,18 +44,13 @@ class RouteServiceProvider extends ServiceProvider
44 ->namespace($this->namespace . '\Musician') 44 ->namespace($this->namespace . '\Musician')
45 ->group(base_path('routes/api.php')); 45 ->group(base_path('routes/api.php'));
46 46
47 //公用 47 //后台
48 Route::prefix('common')
49 ->middleware('api')
50 ->namespace($this->namespace . '\Common')
51 ->group(base_path('routes/common.php'));
52
53 Route::prefix('admin') 48 Route::prefix('admin')
54 ->middleware('api') 49 ->middleware('api')
55 ->namespace($this->namespace . '\Admin') 50 ->namespace($this->namespace . '\Admin')
56 ->group(base_path('routes/admin.php')); 51 ->group(base_path('routes/admin.php'));
57 52
58 53 //web
59 Route::middleware('web') 54 Route::middleware('web')
60 ->namespace($this->namespace) 55 ->namespace($this->namespace)
61 ->group(base_path('routes/web.php')); 56 ->group(base_path('routes/web.php'));
......
1 <?php
2
3 namespace App\Services\V2;
4
5
6 use App\Helper\CosHelper;
7 use App\Helper\Response;
8 use App\Models\Legal\Contract;
9 use App\Models\Legal\Song;
10 use App\Models\Legal\SongsIp;
11 use App\Models\Legal\SongsIpExts;
12 use App\Models\Legal\SongStakeholder;
13 use App\Services\Service;
14 use Illuminate\Database\Eloquent\Builder;
15
16 /**
17 * Class MusicianSongService
18 * @package App\Services
19 */
20 class MusicianSongService extends Service
21 {
22 /**
23 * 授权发行歌曲
24 * @return \Illuminate\Http\JsonResponse
25 */
26 public function releaseSong()
27 {
28 $song_ids = array_filter(array_unique(SongStakeholder::query()->identify()->pluck('song_id')->toArray()));
29
30 if (empty($song_ids)) return Response::success();
31
32 $res = Song::query()->join('songs_ip', "songs.id", '=', "songs_ip.song_id")
33 ->join('songs_ip_exts as ext', 'songs_ip.id', '=', 'ext.song_ip_id')
34 ->whereIn("songs.id", $song_ids)->whereNull("songs_ip.deleted_at")
35 ->where('auth_channel', 1)->select(["songs.id", "songs_ip.id as sp_id", 'track_name',
36 'singer_name', 'album_name', 'public_time', 'track_version', 'favCnt', 'playCnt', 'downloadCnt',
37 'favCnt_week', 'playCnt_week', 'downloadCnt_week', 'favCnt_years', 'playCnt_years', 'downloadCnt_years',
38 ])
39 ->when(filled($this->request->name), function (Builder $builder) {
40 $builder->where(function (Builder $builder){
41 $builder->where('album_name', 'like', "{$this->request->name}")
42 ->orWhere('track_name', 'like', "{$this->request->name}");
43 });
44 })
45 ->sorted($this->request->sort)->paginate($this->pageSize);
46
47 return Response::success($res);
48 }
49 }
...@@ -52,3 +52,8 @@ Route::group([], function (){ ...@@ -52,3 +52,8 @@ Route::group([], function (){
52 52
53 53
54 }); 54 });
55
56 //api-v2
57 Route::group(["prefix"=>"v2", "namespace"=>"V2"], function (){
58 Route::get('musician_song', 'MusicianSongController@list');
59 });
......
1 <?php
2
3 use Illuminate\Support\Facades\Route;
4
5 /*
6 |--------------------------------------------------------------------------
7 | API Routes
8 |--------------------------------------------------------------------------
9 |
10 | Here is where you can register API routes for your application. These
11 | routes are loaded by the RouteServiceProvider within a group which
12 | is assigned the "api" middleware group. Enjoy building your API!
13 |
14 */
15
16 Route::group([], function (){
17
18 //首页-最新发行作品
19 Route::get('release_song', 'ReleaseSongController@list');
20
21 });