|
|
@@ -11,6 +11,7 @@
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
|
+use App\Models\MusicCollectModel;
|
|
|
use App\Models\MusicModel;
|
|
|
|
|
|
/**
|
|
|
@@ -182,4 +183,44 @@ class MusicService extends BaseService
|
|
|
return parent::edit($data); // TODO: Change the autogenerated stub
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取详情
|
|
|
+ * @param $id
|
|
|
+ */
|
|
|
+ public function getDetail($id, $userId=0){
|
|
|
+ $info = $this->model::from('musics as a')
|
|
|
+ ->leftJoin('music_sheets as c', 'a.sheet_id', '=', 'c.id')
|
|
|
+ ->where(['a.mark'=> 1,'a.status'=> 1,'a.id'=> $id])
|
|
|
+ ->select(['a.id','a.title','a.thumb','a.author','a.sheet_id','a.play_num','a.file_url','c.name as sheet_name','a.description','a.create_time'])
|
|
|
+ ->first();
|
|
|
+ $info = $info? $info->toArray() : [];
|
|
|
+ if($info){
|
|
|
+ $info['thumb'] = $info['thumb']? get_image_url($info['thumb']) : '';
|
|
|
+ $info['file_url'] = $info['file_url']? get_file_url($info['file_url']) : '';
|
|
|
+ $info['create_time'] = $info['create_time']? datetime($info['create_time'],'Y-m-d H:i:s') : '';
|
|
|
+
|
|
|
+ // 是否已收藏
|
|
|
+ $info['is_collect'] = 0;
|
|
|
+ if($userId){
|
|
|
+ if(MusicCollectModel::where(['user_id'=> $userId,'source_id'=> $id,'mark'=> 1,'status'=> 1])->value('id')){
|
|
|
+ $info['is_collect'] = 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $info;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 访问量
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function updateVisit($userId=0){
|
|
|
+ $id = request()->get('id');
|
|
|
+ $cacheKey = "caches:music:visit:{$userId}_{$id}";
|
|
|
+ $check = RedisService::get($cacheKey);
|
|
|
+ if($id && !$check){
|
|
|
+ RedisService::set($cacheKey, $id, 3600);
|
|
|
+ return $this->model::where(['id'=> $id])->increment('play_num', 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|