|
@@ -35,7 +35,7 @@ class MusicRepository
|
|
$where[] = ['id', '=', $request['id']];
|
|
$where[] = ['id', '=', $request['id']];
|
|
}
|
|
}
|
|
|
|
|
|
- return $this->postMusicCategory->where($where)->orderBy('id', 'desc')->paginate($perPage);
|
|
|
|
|
|
+ return $this->postMusicCategory->where($where)->orderBy('sort', 'asc')->paginate($perPage);
|
|
}
|
|
}
|
|
|
|
|
|
public function categoryCreate($request)
|
|
public function categoryCreate($request)
|
|
@@ -47,6 +47,7 @@ class MusicRepository
|
|
$data = [
|
|
$data = [
|
|
'name' => $request['name'],
|
|
'name' => $request['name'],
|
|
'is_open' => $request['is_open'] ?? 0,
|
|
'is_open' => $request['is_open'] ?? 0,
|
|
|
|
+ 'sort' => $request['sort'] ?? 999,
|
|
];
|
|
];
|
|
|
|
|
|
if (!$this->postMusicCategory->create($data)) {
|
|
if (!$this->postMusicCategory->create($data)) {
|
|
@@ -56,13 +57,10 @@ class MusicRepository
|
|
|
|
|
|
public function categoryEdit($request)
|
|
public function categoryEdit($request)
|
|
{
|
|
{
|
|
- if($this->postMusicCategory->where('name', $request['name'])->exists()){
|
|
|
|
- throw new HttpException(500, '该分类已经存在');
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
$post_music_category = $this->postMusicCategory->where('id', $request['id'])->first();
|
|
$post_music_category = $this->postMusicCategory->where('id', $request['id'])->first();
|
|
$post_music_category->name = $request['name'];
|
|
$post_music_category->name = $request['name'];
|
|
$post_music_category->is_open = $request['is_open'] ?? 0;
|
|
$post_music_category->is_open = $request['is_open'] ?? 0;
|
|
|
|
+ $post_music_category->sort = $request['sort'] ?? 999;
|
|
$post_music_category->updated_at = date('Y-m-d H:i:s');
|
|
$post_music_category->updated_at = date('Y-m-d H:i:s');
|
|
|
|
|
|
$res = $post_music_category->save();
|
|
$res = $post_music_category->save();
|
|
@@ -117,9 +115,9 @@ class MusicRepository
|
|
$postMusicList = $this->postMusicCategoryRel
|
|
$postMusicList = $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_category_rel.id','post_music.name','post_music.url','post_music.music_duration','post_music.created_at','post_music_category.name as category_name','post_music_category.id as category_id')
|
|
|
|
|
|
+ ->select('post_music_category_rel.id','post_music_category_rel.sort','post_music.name','post_music.url','post_music.music_duration','post_music.created_at','post_music_category.name as category_name','post_music_category.id as category_id')
|
|
->where($where)
|
|
->where($where)
|
|
- ->orderBy('id', 'desc')
|
|
|
|
|
|
+ ->orderBy('post_music_category_rel.sort', 'asc')
|
|
->paginate($perPage);
|
|
->paginate($perPage);
|
|
|
|
|
|
return $postMusicList;
|
|
return $postMusicList;
|
|
@@ -143,6 +141,7 @@ class MusicRepository
|
|
$create_category_rel = [
|
|
$create_category_rel = [
|
|
'mid' => $mid,
|
|
'mid' => $mid,
|
|
'music_category_id' => $request['category_id'],
|
|
'music_category_id' => $request['category_id'],
|
|
|
|
+ 'sort' => $request['sort'] ?? 999,
|
|
'created_at' => $date,
|
|
'created_at' => $date,
|
|
'updated_at' => $date
|
|
'updated_at' => $date
|
|
];
|
|
];
|
|
@@ -169,11 +168,11 @@ class MusicRepository
|
|
{
|
|
{
|
|
$post_music_rel = $this->postMusicCategoryRel->select('mid')->where('id', $request['id'])->first();
|
|
$post_music_rel = $this->postMusicCategoryRel->select('mid')->where('id', $request['id'])->first();
|
|
$post_music = $this->postMusic->where('id',$post_music_rel->mid)->first();
|
|
$post_music = $this->postMusic->where('id',$post_music_rel->mid)->first();
|
|
- if($post_music == null) {
|
|
|
|
- $post_music = new PostMusic();
|
|
|
|
- $post_music->name = $request['name'];
|
|
|
|
|
|
+ if (!$post_music) {
|
|
|
|
+ throw new HttpException(500, '没有找到对应的音乐');
|
|
}
|
|
}
|
|
$date = date('Y-m-d H:i:s');
|
|
$date = date('Y-m-d H:i:s');
|
|
|
|
+ $post_music->name = $request['name'];
|
|
$post_music->url = $request['url'];
|
|
$post_music->url = $request['url'];
|
|
$post_music->music_duration = $request['music_duration'];
|
|
$post_music->music_duration = $request['music_duration'];
|
|
$post_music->updated_at = $date;
|
|
$post_music->updated_at = $date;
|
|
@@ -184,6 +183,7 @@ class MusicRepository
|
|
$create_category_rel = [
|
|
$create_category_rel = [
|
|
'mid' => $post_music->id,
|
|
'mid' => $post_music->id,
|
|
'music_category_id' => $request['category_id'],
|
|
'music_category_id' => $request['category_id'],
|
|
|
|
+ 'sort' => $request['sort'] ?? 999,
|
|
'created_at' => $date,
|
|
'created_at' => $date,
|
|
'updated_at' => $date,
|
|
'updated_at' => $date,
|
|
];
|
|
];
|