Quellcode durchsuchen

feat: 优化剧集管理

xiansin vor 2 Jahren
Ursprung
Commit
7a50b0ff86

+ 7 - 0
mini/api/episode.js

xqd xqd
@@ -18,6 +18,12 @@ export function rank() {
   )
 }
 
+export function todayRecommend() {
+  return request.get(
+    'episode/today/recommend'
+  )
+}
+
 export function detail(id) {
   return request.get(
     `episode/${id}/detail`
@@ -60,6 +66,7 @@ export default {
   recommend,
   news,
   rank,
+  todayRecommend,
   detail,
   trace,
   search,

+ 8 - 0
mini/pages/index/components/EpisodeBox.vue

xqd xqd
@@ -68,6 +68,13 @@ export default {
         this.episodes = res.data
       })
     },
+    getTodayRecommend() {
+      this.loading = true
+      this.$api.episode.todayRecommend().then(res => {
+        this.loading = false
+        this.episodes = res.data
+      })
+    },
     getNews() {
       this.loading = true
       this.$api.episode.news().then(res => {
@@ -84,6 +91,7 @@ export default {
     },
     handleRefresh() {
       this.type === 'recommend' && this.getRecommend()
+      this.type === 'todayRecommend' && this.getTodayRecommend()
       this.type === 'news' && this.getNews()
       this.type === 'rank' && this.getRank()
     }

+ 6 - 8
mini/pages/index/index.vue

xqd
@@ -29,14 +29,12 @@
     <!--栏目分类-->
     <nav-bar />
     <!--分类-->
-    <template v-for="(item,index) in homeColumn">
-      <episode-box
-        v-if="item.type !== homeColumnType[2]"
-        :key="index"
-        :title="item.name"
-        :type="item.type"
-      />
-    </template>
+    <episode-box
+      v-for="(item,index) in homeColumn"
+      :key="index"
+      :title="item.name"
+      :type="item.type"
+    />
     <!--tab bar-->
     <tab-bar />
     <!--最近播放-->

+ 3 - 0
server/.env.example

xqd
@@ -75,3 +75,6 @@ ALI_OSS_ACCESS_ID=
 ALI_OSS_ACCESS_KEY=
 ALI_OSS_BUCKET=
 ALI_OSS_ENDPOINT=
+
+# 首页推荐栏目展示短剧个数
+HOME_RECOMMEND_NUMBER=6

+ 2 - 2
server/app/Admin/Controllers/Episode/EpisodeController.php

xqd
@@ -37,14 +37,14 @@ class EpisodeController extends AdminController
             $grid->column('is_vip_watch')->using(config('global.bool_status'))->label(['gray', 'primary'])->sortable();
             $grid->column('','短剧上传')->display(function (){
                 $url = admin_url('/episodes/batch/'.$this->id.'/upload');
-                return '<a href="'.$url.'"><i class="fa fa-upload"></i> 上传剧</a>';
+                return '<a href="'.$url.'"><i class="fa fa-upload"></i> 上传剧</a>';
             });
             $grid->column('created_at');
 
             $grid->actions(function (Grid\Displayers\Actions $actions) {
                 $id = $actions->getKey();
                 // append一个操作
-                $actions->append('<a href="/admin/episodes/'.$id.'/lists"><i class="fa fa-upload"></i> 剧管理</a>');
+                $actions->append('<a href="/admin/episodes/'.$id.'/lists"><i class="fa fa-upload"></i> 剧管理</a>');
             });
 
             $grid->filter(function (Grid\Filter $filter) {

+ 3 - 3
server/app/Admin/Controllers/Episode/EpisodesListController.php

xqd xqd
@@ -28,10 +28,10 @@ class EpisodesListController extends AdminController
             ->translation($this->translation())
             ->breadcrumb(
                 ['text' => $this->episode->name],
-                ['text' => '剧上传'],
+                ['text' => '剧上传'],
             )
             ->title($this->title())
-            ->description('剧上传');
+            ->description('剧上传');
     }
 
     public function index(Content $content,$episodeId = 0)
@@ -77,7 +77,7 @@ class EpisodesListController extends AdminController
             $grid->column('sort')->display(function (){
                 return '第'.$this->sort.'集';
             })->editable();
-            $grid->column('episode.name','剧名称');
+            $grid->column('episode.name','剧名称');
             $grid->column('is_free')
                 ->using(config('global.episode_free'))
                 ->label(['success', 'primary'])->sortable();

+ 63 - 31
server/app/Http/Controllers/V1/EpisodeController.php

xqd xqd xqd xqd xqd
@@ -14,6 +14,13 @@ use Illuminate\Support\Collection;
 
 class EpisodeController extends Controller
 {
+
+    private $number;
+
+    public function __construct()
+    {
+        $this->number = env('HOME_RECOMMEND_NUMBER', 6);
+    }
     /**
      * 推荐
      */
@@ -24,20 +31,6 @@ class EpisodeController extends Controller
             ->inRandomOrder()
             //->where('created_at','>=', Carbon::now()->subDays(7)->toDateTime())
             ->first();
-
-        $limit = 3 - ($history?$history->count():0);
-        // 推荐
-        $episodes = Episode::withCount(['lists'])
-            ->where('is_opend', 1)
-            ->where('platform', \user()->info->platform)
-            ->when($history,function ($query) use($history){
-                /* @var Builder  $query*/
-                return $query->where('category_id', $history->episode->category_id)
-                    ->where('id','<>', $history->episode->id);
-            })
-            ->limit($limit)
-            ->get();
-
         $lists = [];
 
         $ids = [];
@@ -50,33 +43,49 @@ class EpisodeController extends Controller
             $lists[] = $history->episode;
         }
 
-        /* @var Episode $episode*/
-        foreach ($episodes as $episode){
-            $ids[] = $episode->id;
-            $episode->status_text = $episode->status;
-            $episode->total = $episode->lists_count;
-            $episode->guess = true;
-            $lists[] = $episode;
-        }
-        // 推荐的不够两个 需要补充
-        $limit = $limit -($episodes ? $episodes->count() : 0);
-        $supplement = Episode::withCount(['lists'])
+        $limit =  $this->number - count($lists);
+        // 推荐
+        $episodes = Episode::withCount(['lists'])
             ->where('is_opend', 1)
             ->where('platform', \user()->info->platform)
-            ->when($ids, function ($query) use($ids){
+            ->when($history,function ($query) use($history){
                 /* @var Builder  $query*/
-                return $query->whereNotIn('id',$ids);
+                return $query->where('category_id', $history->episode->category_id)
+                    ->where('id','<>', $history->episode->id);
             })
             ->limit($limit)
             ->get();
 
         /* @var Episode $episode*/
-        foreach ($supplement as $episode){
+        foreach ($episodes as $episode){
+            $ids[] = $episode->id;
             $episode->status_text = $episode->status;
             $episode->total = $episode->lists_count;
             $episode->guess = true;
             $lists[] = $episode;
         }
+        // 推荐的不够两个 需要补充
+        $limit =  $this->number - count($lists);
+        if($limit){
+            $supplement = Episode::withCount(['lists'])
+                ->where('is_opend', 1)
+                ->where('platform', \user()->info->platform)
+                ->when($ids, function ($query) use($ids){
+                    /* @var Builder  $query*/
+                    return $query->whereNotIn('id',$ids);
+                })
+                ->limit($limit)
+                ->get();
+
+            /* @var Episode $episode*/
+            foreach ($supplement as $episode){
+                $episode->status_text = $episode->status;
+                $episode->total = $episode->lists_count;
+                $episode->guess = true;
+                $lists[] = $episode;
+            }
+        }
+
 
         return $this->success($lists);
     }
@@ -87,14 +96,37 @@ class EpisodeController extends Controller
      */
     public function news()
     {
-        $limit = request()->input('limit',3);
+        $limit = request()->input('limit', $this->number);
         $page = request()->input('page',1);
         $offset = ($page - 1) * $limit;
         $episodes = Episode::withCount(['lists'])
             ->where('is_opend', 1)
             ->where('platform', \user()->info->platform)
             ->inRandomOrder()
-            ->orderByDesc('id')
+            ->orderByDesc('created_at')
+            ->limit($limit)
+            ->offset($offset)
+            ->get();
+
+
+        $lists = Episode::complete($episodes);
+
+        return $this->success($lists);
+    }
+
+    /**
+     * 今日推荐
+     */
+    public function todayRecommend()
+    {
+        $limit = request()->input('limit', $this->number);
+        $page = request()->input('page',1);
+        $offset = ($page - 1) * $limit;
+        $episodes = Episode::withCount(['lists'])
+            ->where('is_opend', 1)
+            ->where('platform', \user()->info->platform)
+            ->inRandomOrder()
+            ->orderByDesc('sort')
             ->limit($limit)
             ->offset($offset)
             ->get();
@@ -111,7 +143,7 @@ class EpisodeController extends Controller
      */
     public function rank()
     {
-        $limit = request()->input('limit',3);
+        $limit = request()->input('limit',  $this->number);
         $page = request()->input('page',1);
         $offset = ($page - 1) * $limit;
         $episodes = Episode::withCount(['userEpisodesRecords','lists'])

+ 1 - 0
server/routes/api.php

xqd
@@ -153,6 +153,7 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\V1'], function ($api)
         $api->group(['prefix' => 'episode'],function ($api){
             /* @var Dingo\Api\Routing\Router $api*/
             $api->get('recommend', 'EpisodeController@recommend'); // 推荐
+            $api->get('today/recommend', 'EpisodeController@todayRecommend'); // 今日推荐
             $api->get('news', 'EpisodeController@news'); // 最新
             $api->get('rank', 'EpisodeController@rank'); // 排行
             $api->get('trace', 'EpisodeController@trace'); // 追剧