Przeglądaj źródła

Merge remote-tracking branch 'origin/develop' into develop

wzq 5 lat temu
rodzic
commit
ed1bea4f9e

+ 5 - 5
app/Http/Controllers/ConfigController.php

@@ -88,11 +88,11 @@ class ConfigController extends Controller
                 'is_close'=>'关闭',
                 'is_close'=>'关闭',
             ],
             ],
             'banner_type'=>[
             'banner_type'=>[
-                0=>'纯展示',
-                1=>'内容',
-                2=>'用户',
-                3=>'活动',
-                4=>'话题',
+                '1' =>'内容',
+                '0' =>'纯展示',
+                '2' =>'用户',
+                '3' =>'活动',
+                '4' =>'话题',
             ],
             ],
             'floor_type'=>[
             'floor_type'=>[
                 0=>'banner',
                 0=>'banner',

+ 3 - 1
app/Http/Controllers/MusicController.php

@@ -44,7 +44,8 @@ class MusicController extends Controller
                 'id',
                 'id',
                 'name',
                 'name',
                 'music_count',
                 'music_count',
-                'is_open'
+                'is_open',
+                'sort'
             ]
             ]
         ];
         ];
         return $data;
         return $data;
@@ -125,6 +126,7 @@ class MusicController extends Controller
                 'name',
                 'name',
                 'category_name',
                 'category_name',
                 'music_duration',
                 'music_duration',
+                'sort',
                 'created_at'
                 'created_at'
             ]
             ]
         ];
         ];

+ 10 - 10
app/Repositories/MusicRepository.php

@@ -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,
                     ];
                     ];

+ 1 - 0
app/Transformers/MusicCategoryTransformer.php

@@ -18,6 +18,7 @@ class MusicCategoryTransformer extends TransformerAbstract {
             'name' => $categoryList['name'],
             'name' => $categoryList['name'],
             'music_count' => $categoryList['music_count'],
             'music_count' => $categoryList['music_count'],
             'is_open' => $categoryList['is_open'],
             'is_open' => $categoryList['is_open'],
+            'sort' => $categoryList['sort'],
         ];
         ];
     }
     }
 }
 }

+ 1 - 0
app/Transformers/MusicTranformer.php

@@ -22,6 +22,7 @@ class MusicTranformer extends TransformerAbstract {
             'created_at' => date($musicList['created_at']),
             'created_at' => date($musicList['created_at']),
             'category_id' => $musicList['category_id'],
             'category_id' => $musicList['category_id'],
             'category_name' => $musicList['category_name'],
             'category_name' => $musicList['category_name'],
+            'sort' => $musicList['sort'],
         ];
         ];
     }
     }
 }
 }

+ 32 - 0
database/migrations/2019_07_30_165136_add_sort_to_post_music_category_table.php

@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddSortToPostMusicCategoryTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('post_music_category', function (Blueprint $table) {
+            $table->integer('sort')->default(999)->comment('排序');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('post_music_category', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 32 - 0
database/migrations/2019_07_30_165234_add_sort_to_post_music_category_rel_table.php

@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddSortToPostMusicCategoryRelTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('post_music_category_rel', function (Blueprint $table) {
+            $table->integer('sort')->default(999)->comment('排序');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('post_music_category_rel', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 1 - 1
routes/web.php

@@ -12,7 +12,7 @@
 */
 */
 
 
 $router->get('/', function () use ($router) {
 $router->get('/', function () use ($router) {
-    return $router->app->version();
+    return '欢迎来到由你';
 });
 });
 
 
 $router->get('/test', function () use ($router) {
 $router->get('/test', function () use ($router) {