Merge branch 'release' of gitlab.hikoon.com:zhaocong/musician-api.hikoon.com into release
Showing
2 changed files
with
45 additions
and
23 deletions
... | @@ -20,16 +20,16 @@ class SongController extends Controller | ... | @@ -20,16 +20,16 @@ class SongController extends Controller |
20 | 20 | ||
21 | public function list(Request $request) | 21 | public function list(Request $request) |
22 | { | 22 | { |
23 | if (!$request->has('type') || !$request->has('value')) { | 23 | /*if (!$request->has('type') || !$request->has('value')) { |
24 | return Response::successWithCode(ErrorCode::MISSING_PARAMS, ErrorCode::$messages[ErrorCode::MISSING_PARAMS]); | 24 | return Response::successWithCode(ErrorCode::MISSING_PARAMS, ErrorCode::$messages[ErrorCode::MISSING_PARAMS]); |
25 | } | 25 | } |
26 | 26 | ||
27 | if (!$request->filled('type') || !$request->filled('value')) { | ||
28 | return Response::successWithCode(ErrorCode::EMPTY_PARAMS, ErrorCode::$messages[ErrorCode::EMPTY_PARAMS]); | ||
29 | } | ||
30 | |||
31 | if (!in_array($request->get('type'), static::$input_types)) { | 27 | if (!in_array($request->get('type'), static::$input_types)) { |
32 | return Response::successWithCode(ErrorCode::ILLEGAL_PARAMS, ErrorCode::$messages[ErrorCode::ILLEGAL_PARAMS]); | 28 | return Response::successWithCode(ErrorCode::ILLEGAL_PARAMS, ErrorCode::$messages[ErrorCode::ILLEGAL_PARAMS]); |
29 | }*/ | ||
30 | |||
31 | if (empty($request->get('song_id')) && empty($request->get('song_name')) &&empty($request->get('singer'))) { | ||
32 | return Response::successWithCode(ErrorCode::EMPTY_PARAMS, ErrorCode::$messages[ErrorCode::EMPTY_PARAMS]); | ||
33 | } | 33 | } |
34 | 34 | ||
35 | $songs = Song::with('subject', 'tags', 'files') | 35 | $songs = Song::with('subject', 'tags', 'files') |
... | @@ -39,26 +39,23 @@ class SongController extends Controller | ... | @@ -39,26 +39,23 @@ class SongController extends Controller |
39 | 'performer_right' => 1, | 39 | 'performer_right' => 1, |
40 | 'tape_right' => 1, | 40 | 'tape_right' => 1, |
41 | ]) | 41 | ]) |
42 | ->when($request->filled('value'), function ($query) use ($request) { | 42 | ->when($request->filled('song_id'), function ($query) use ($request) { |
43 | switch ($request->get('type')) { | 43 | $query->where('custom_id', 'like', "%{$request->get('song_id')}%"); |
44 | case 1: | 44 | }) |
45 | $query->where('custom_id', $request->get('value')); | 45 | ->when($request->filled('song_name'), function ($query) use ($request) { |
46 | break; | 46 | $query->where('name', 'like', "%{$request->get('song_name')}%"); |
47 | case 2: | 47 | }) |
48 | $query->where('name', 'like', "%{$request->get('value')}%"); | 48 | ->when($request->filled('singer'), function ($query) use ($request) { |
49 | break; | 49 | $query->where('singer', 'like', "%{$request->get('singer')}%"); |
50 | case 3: | 50 | }) |
51 | $query->where('singer', 'like', "%{$request->get('value')}%"); | 51 | ->where('has_all_files', 1); |
52 | break; | ||
53 | } | ||
54 | }); | ||
55 | 52 | ||
56 | $total = $songs->count(); | 53 | $total = $songs->count(); |
57 | 54 | ||
58 | $songs = $songs->orderByDesc('id') | 55 | $songs = $songs->forPage($request->get('page', 1), $request->get('limit', static::$songs_limit)) |
59 | ->forPage($request->get('page', 1), static::$songs_limit) | ||
60 | ->get(['custom_id as song_id', 'name as song_name', 'lyricist', 'composer', 'singer', 'lyrics_right', | 56 | ->get(['custom_id as song_id', 'name as song_name', 'lyricist', 'composer', 'singer', 'lyrics_right', |
61 | 'tune_right', 'performer_right', 'tape_right', 'status', 'subject_no', 'tag_id']) | 57 | 'tune_right', 'performer_right', 'tape_right', 'status', 'subject_no', 'tag_id', 'lyrics_right_date', |
58 | 'tune_right_date', 'performer_right_date', 'tape_right_date']) | ||
62 | ->toArray(); | 59 | ->toArray(); |
63 | 60 | ||
64 | if (count($songs)) { | 61 | if (count($songs)) { |
... | @@ -75,6 +72,11 @@ class SongController extends Controller | ... | @@ -75,6 +72,11 @@ class SongController extends Controller |
75 | $song['files'] = $this->coverFiles($song['files']); | 72 | $song['files'] = $this->coverFiles($song['files']); |
76 | } | 73 | } |
77 | 74 | ||
75 | $song['lyrics_right_date'] = $this->coverRightDate($song['lyrics_right_date']); | ||
76 | $song['tune_right_date'] = $this->coverRightDate($song['tune_right_date']); | ||
77 | $song['performer_right_date'] = $this->coverRightDate($song['performer_right_date']); | ||
78 | $song['tape_right_date'] = $this->coverRightDate($song['tape_right_date']); | ||
79 | |||
78 | $song['type'] = 1; | 80 | $song['type'] = 1; |
79 | 81 | ||
80 | unset($song['subject_no'], $song['tag_id']); | 82 | unset($song['subject_no'], $song['tag_id']); |
... | @@ -101,7 +103,7 @@ class SongController extends Controller | ... | @@ -101,7 +103,7 @@ class SongController extends Controller |
101 | 103 | ||
102 | public function coverFiles($song_files): array | 104 | public function coverFiles($song_files): array |
103 | { | 105 | { |
104 | $files_need = ['mp3_url', 'accompany_mp3_url', 'cover_url', 'wav_url', 'accompany_wav_url']; | 106 | $files_need = ['mp3_url', 'accompany_mp3_url', 'lyric_url', 'cover_url', 'wav_url', 'accompany_wav_url']; |
105 | $files_arr = []; | 107 | $files_arr = []; |
106 | foreach ($song_files as $file) { | 108 | foreach ($song_files as $file) { |
107 | switch ($file['type']) { | 109 | switch ($file['type']) { |
... | @@ -111,6 +113,9 @@ class SongController extends Controller | ... | @@ -111,6 +113,9 @@ class SongController extends Controller |
111 | case 2: | 113 | case 2: |
112 | $files_arr['accompany_mp3_url'] = $file['url']; | 114 | $files_arr['accompany_mp3_url'] = $file['url']; |
113 | break; | 115 | break; |
116 | case 3: | ||
117 | $files_arr['lyric_url'] = $file['url']; | ||
118 | break; | ||
114 | case 4: | 119 | case 4: |
115 | $files_arr['cover_url'] = $file['url']; | 120 | $files_arr['cover_url'] = $file['url']; |
116 | break; | 121 | break; |
... | @@ -131,6 +136,23 @@ class SongController extends Controller | ... | @@ -131,6 +136,23 @@ class SongController extends Controller |
131 | 136 | ||
132 | return $files_arr; | 137 | return $files_arr; |
133 | } | 138 | } |
139 | |||
140 | public function coverRightDate($right_date) | ||
141 | { | ||
142 | $date = ['start' => '无', 'end' => '无']; | ||
143 | try { | ||
144 | if ($right_date) { | ||
145 | $tmp = explode(' - ', $right_date); | ||
146 | $date = [ | ||
147 | 'start' => $tmp[0], | ||
148 | 'end' => $tmp[1], | ||
149 | ]; | ||
150 | } | ||
151 | } catch (\Exception $exception) { | ||
152 | return $date; | ||
153 | } | ||
154 | return $date; | ||
155 | } | ||
134 | } | 156 | } |
135 | 157 | ||
136 | 158 | ... | ... |
... | @@ -14,7 +14,7 @@ class Song extends BaseModel | ... | @@ -14,7 +14,7 @@ class Song extends BaseModel |
14 | { | 14 | { |
15 | use HasFactory,SoftDeletes; | 15 | use HasFactory,SoftDeletes; |
16 | 16 | ||
17 | protected static $file_only = [1,2,4,11,12]; | 17 | public static $file_only = [1,2,4,11,12]; |
18 | 18 | ||
19 | /** | 19 | /** |
20 | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany | 20 | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany | ... | ... |
-
Please register or sign in to post a comment