|
@@ -7,8 +7,8 @@
|
|
*/
|
|
*/
|
|
namespace App\Repositories;
|
|
namespace App\Repositories;
|
|
|
|
|
|
-use App\Models\PostMusic;
|
|
|
|
use App\Models\PostMusicCategoryRel;
|
|
use App\Models\PostMusicCategoryRel;
|
|
|
|
+use Illuminate\Support\Facades\Cache;
|
|
|
|
|
|
class MusicRepository
|
|
class MusicRepository
|
|
{
|
|
{
|
|
@@ -21,16 +21,25 @@ class MusicRepository
|
|
public function lists($request)
|
|
public function lists($request)
|
|
{
|
|
{
|
|
$perPage = isset($request['per_page']) ? $request['per_page'] : 20;
|
|
$perPage = isset($request['per_page']) ? $request['per_page'] : 20;
|
|
|
|
+ $music_key = config('constants.MUSIC_LIST');
|
|
|
|
+ if (Cache::has($music_key)) {
|
|
|
|
+ return Cache::store('redis')->get($music_key);
|
|
|
|
+ }
|
|
|
|
|
|
- $this->postMusicCategoryRel = $this->postMusicCategoryRel
|
|
|
|
|
|
+ $category_name = '热门';
|
|
|
|
+ $postMusicCategoryRel = $this->postMusicCategoryRel
|
|
->join('post_music_category', 'post_music_category.id', '=', 'post_music_category_rel.music_category_id')
|
|
->join('post_music_category', 'post_music_category.id', '=', 'post_music_category_rel.music_category_id')
|
|
->join('post_music', 'post_music.id', '=', 'post_music_category_rel.mid')
|
|
->join('post_music', 'post_music.id', '=', 'post_music_category_rel.mid')
|
|
->select('post_music.*')
|
|
->select('post_music.*')
|
|
- ->where('post_music_category.id', 11)
|
|
|
|
|
|
+ ->where('post_music_category.name', 'like', "%{$category_name}%")
|
|
->orderBy('id', 'desc')
|
|
->orderBy('id', 'desc')
|
|
->paginate($perPage);
|
|
->paginate($perPage);
|
|
|
|
|
|
- return $this->postMusicCategoryRel;
|
|
|
|
|
|
+ if (!Cache::has($music_key)) {
|
|
|
|
+ Cache::store('redis')->put($music_key, $postMusicCategoryRel, 604800);//一周过期
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return $postMusicCategoryRel;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|