Commit 1aedcc30 1aedcc30d17b8332a12e176e8d7cc793cf022ece by lemon

歌曲绑定发行

1 parent 7b931681
......@@ -54,4 +54,13 @@ class MusicianSongController extends Controller
return $this->musicianSongService->right($song_id);
}
/**
* 歌曲权益
* @return \Illuminate\Http\JsonResponse
*/
public function songRights()
{
return $this->musicianSongService->songRights();
}
}
......
......@@ -30,4 +30,12 @@ class Song extends BaseModel
return $this->hasOne(SongFile::class, 'song_id')->where('type', 4);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function contracts()
{
return $this->belongsToMany(Contract::class, 'contract_song', 'song_id', 'contract_id');
}
}
......
......@@ -21,6 +21,43 @@ use Carbon\Carbon;
class MusicianSongService extends Service
{
/**
* 分贝授权发行歌曲 - 绑定版权数据 - 对应的权益
* @return \Illuminate\Http\JsonResponse
*/
public function songRights()
{
$song_ids = array_filter(array_unique(SongStakeholder::query()->identify()->pluck('song_id')->toArray()));
if (empty($song_ids)) return Response::success();
$res = Song::query()->with(['contractDetail'])->whereIn('id', $song_ids)->select(['id', 'custom_id'])->get()->toArray();
$data = [];
foreach ($res as $item) {
if (in_array($item['custom_id'], $this->request->custom_ids) && !empty($item['contract_detail'])) {
$role = [];
if ($clause_res = array_column($item['contract_detail'], 'clause')) {
foreach ($clause_res as $clause_res_item) {
if($clause = json_decode($clause_res_item)) {
foreach ($clause as $clause_item) {
if (in_array($clause_item->stakeholder_id, $this->stakeholder_ids)) {
$role = array_merge($role, Contract::transformRole($clause_item->right_type));
}
}
}
}
}
$data[$item['custom_id']] = $role;
}
}
return Response::success($data);
}
/**
* 授权发行歌曲
* @return \Illuminate\Http\JsonResponse
*/
......
......@@ -20,6 +20,8 @@ Route::group([], function (){
Route::get('musician_song/{song_id}', 'MusicianSongController@detail');
Route::get('musician_song/{song_id}/right', 'MusicianSongController@right');
Route::post('musician_song/rights', 'MusicianSongController@songRights');
//经纪约列表
Route::get('musician_treaty', 'MusicianTreatyController@list');
//我的合约
......