Commit aef9a9d5 aef9a9d52fb400dca5b42cacc120c24bc94eef12 by lemon

Merge branch 'release' of gitlab.hikoon.com:zhaocong/musician-api.hikoon.com into release

2 parents 8cd36f22 024634ce
......@@ -20,16 +20,16 @@ class SongController extends Controller
public function list(Request $request)
{
if (!$request->has('type') || !$request->has('value')) {
/*if (!$request->has('type') || !$request->has('value')) {
return Response::successWithCode(ErrorCode::MISSING_PARAMS, ErrorCode::$messages[ErrorCode::MISSING_PARAMS]);
}
if (!$request->filled('type') || !$request->filled('value')) {
return Response::successWithCode(ErrorCode::EMPTY_PARAMS, ErrorCode::$messages[ErrorCode::EMPTY_PARAMS]);
}
if (!in_array($request->get('type'), static::$input_types)) {
return Response::successWithCode(ErrorCode::ILLEGAL_PARAMS, ErrorCode::$messages[ErrorCode::ILLEGAL_PARAMS]);
}*/
if (empty($request->get('song_id')) && empty($request->get('song_name')) &&empty($request->get('singer'))) {
return Response::successWithCode(ErrorCode::EMPTY_PARAMS, ErrorCode::$messages[ErrorCode::EMPTY_PARAMS]);
}
$songs = Song::with('subject', 'tags', 'files')
......@@ -39,26 +39,23 @@ class SongController extends Controller
'performer_right' => 1,
'tape_right' => 1,
])
->when($request->filled('value'), function ($query) use ($request) {
switch ($request->get('type')) {
case 1:
$query->where('custom_id', $request->get('value'));
break;
case 2:
$query->where('name', 'like', "%{$request->get('value')}%");
break;
case 3:
$query->where('singer', 'like', "%{$request->get('value')}%");
break;
}
});
->when($request->filled('song_id'), function ($query) use ($request) {
$query->where('custom_id', 'like', "%{$request->get('song_id')}%");
})
->when($request->filled('song_name'), function ($query) use ($request) {
$query->where('name', 'like', "%{$request->get('song_name')}%");
})
->when($request->filled('singer'), function ($query) use ($request) {
$query->where('singer', 'like', "%{$request->get('singer')}%");
})
->where('has_all_files', 1);
$total = $songs->count();
$songs = $songs->orderByDesc('id')
->forPage($request->get('page', 1), static::$songs_limit)
$songs = $songs->forPage($request->get('page', 1), $request->get('limit', static::$songs_limit))
->get(['custom_id as song_id', 'name as song_name', 'lyricist', 'composer', 'singer', 'lyrics_right',
'tune_right', 'performer_right', 'tape_right', 'status', 'subject_no', 'tag_id'])
'tune_right', 'performer_right', 'tape_right', 'status', 'subject_no', 'tag_id', 'lyrics_right_date',
'tune_right_date', 'performer_right_date', 'tape_right_date'])
->toArray();
if (count($songs)) {
......@@ -75,6 +72,11 @@ class SongController extends Controller
$song['files'] = $this->coverFiles($song['files']);
}
$song['lyrics_right_date'] = $this->coverRightDate($song['lyrics_right_date']);
$song['tune_right_date'] = $this->coverRightDate($song['tune_right_date']);
$song['performer_right_date'] = $this->coverRightDate($song['performer_right_date']);
$song['tape_right_date'] = $this->coverRightDate($song['tape_right_date']);
$song['type'] = 1;
unset($song['subject_no'], $song['tag_id']);
......@@ -101,7 +103,7 @@ class SongController extends Controller
public function coverFiles($song_files): array
{
$files_need = ['mp3_url', 'accompany_mp3_url', 'cover_url', 'wav_url', 'accompany_wav_url'];
$files_need = ['mp3_url', 'accompany_mp3_url', 'lyric_url', 'cover_url', 'wav_url', 'accompany_wav_url'];
$files_arr = [];
foreach ($song_files as $file) {
switch ($file['type']) {
......@@ -111,6 +113,9 @@ class SongController extends Controller
case 2:
$files_arr['accompany_mp3_url'] = $file['url'];
break;
case 3:
$files_arr['lyric_url'] = $file['url'];
break;
case 4:
$files_arr['cover_url'] = $file['url'];
break;
......@@ -131,6 +136,23 @@ class SongController extends Controller
return $files_arr;
}
public function coverRightDate($right_date)
{
$date = ['start' => '无', 'end' => '无'];
try {
if ($right_date) {
$tmp = explode(' - ', $right_date);
$date = [
'start' => $tmp[0],
'end' => $tmp[1],
];
}
} catch (\Exception $exception) {
return $date;
}
return $date;
}
}
......
......@@ -14,7 +14,7 @@ class Song extends BaseModel
{
use HasFactory,SoftDeletes;
protected static $file_only = [1,2,4,11,12];
public static $file_only = [1,2,4,11,12];
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
......