..
Showing
2 changed files
with
38 additions
and
19 deletions
... | @@ -20,7 +20,7 @@ class SongController extends Controller | ... | @@ -20,7 +20,7 @@ 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 | ||
... | @@ -30,7 +30,7 @@ class SongController extends Controller | ... | @@ -30,7 +30,7 @@ class SongController extends Controller |
30 | 30 | ||
31 | if (!in_array($request->get('type'), static::$input_types)) { | 31 | if (!in_array($request->get('type'), static::$input_types)) { |
32 | return Response::successWithCode(ErrorCode::ILLEGAL_PARAMS, ErrorCode::$messages[ErrorCode::ILLEGAL_PARAMS]); | 32 | return Response::successWithCode(ErrorCode::ILLEGAL_PARAMS, ErrorCode::$messages[ErrorCode::ILLEGAL_PARAMS]); |
33 | } | 33 | }*/ |
34 | 34 | ||
35 | $songs = Song::with('subject', 'tags', 'files') | 35 | $songs = Song::with('subject', 'tags', 'files') |
36 | ->where([ | 36 | ->where([ |
... | @@ -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']); |
... | @@ -131,6 +133,23 @@ class SongController extends Controller | ... | @@ -131,6 +133,23 @@ class SongController extends Controller |
131 | 133 | ||
132 | return $files_arr; | 134 | return $files_arr; |
133 | } | 135 | } |
136 | |||
137 | public function coverRightDate($right_date) | ||
138 | { | ||
139 | $date = ['start' => '无', 'end' => '无']; | ||
140 | try { | ||
141 | if ($right_date) { | ||
142 | $tmp = explode(' - ', $right_date); | ||
143 | $date = [ | ||
144 | 'start' => $tmp[0], | ||
145 | 'end' => $tmp[1], | ||
146 | ]; | ||
147 | } | ||
148 | } catch (\Exception $exception) { | ||
149 | return $date; | ||
150 | } | ||
151 | return $date; | ||
152 | } | ||
134 | } | 153 | } |
135 | 154 | ||
136 | 155 | ... | ... |
... | @@ -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