浏览代码

feat: 会员免费片单

xiansin 2 年之前
父节点
当前提交
b74e19bc99

+ 9 - 1
mini/api/episode.js

xqd
@@ -43,11 +43,19 @@ export function search(params) {
   )
 }
 
+export function vipFree(params) {
+  return request.get(
+    `episode/vip/free`,
+    { params }
+  )
+}
+
 export default {
   recommend,
   news,
   rank,
   detail,
   trace,
-  search
+  search,
+  vipFree
 }

+ 5 - 0
mini/components/Episode/index.vue

xqd xqd
@@ -66,6 +66,10 @@ export default {
     rank: {
       type: Number,
       default: 0
+    },
+    redirect: {
+      type: Boolean,
+      default: true
     }
   },
   data() {
@@ -74,6 +78,7 @@ export default {
   computed: {},
   methods: {
     handlePlay() {
+      if (!this.redirect) return
       this.$u.route({
         url: '/pages/episode/play',
         params: {

+ 26 - 11
mini/pages/member/free.vue

xqd xqd
@@ -4,6 +4,7 @@
       v-for="(episode,index) in episodes"
       :key="index"
       :episode="episode"
+      :redirect="false"
       :custom-style="{
         marginRight: ((index+1) % 3 !== 0 ? '20rpx' :''),
       }"
@@ -18,20 +19,34 @@ export default {
   components: { Episode },
   data() {
     return {
-      episodes: [
-        { name: '毒液', status: '已完结', total: 40 },
-        { name: '毒液', status: '已完结', total: 40 },
-        { name: '毒液', status: '已完结', total: 40 },
-        { name: '毒液', status: '已完结', total: 40 },
-        { name: '毒液', status: '已完结', total: 40 },
-        { name: '毒液', status: '已完结', total: 40 },
-        { name: '毒液', status: '已完结', total: 40 },
-        { name: '毒液', status: '已完结', total: 40 }
-      ]
+      limit: 30,
+      page: 1,
+      isMore: true,
+      episodes: []
     }
   },
   computed: {},
-  methods: {}
+  methods: {
+    getFree() {
+      this.loading = true
+      this.$api.episode.vipFree({ limit: this.limit, page: this.page }).then(res => {
+        this.loading = false
+        if (res.data.length) {
+          this.episodes = this.episodes.concat(res.data)
+        } else {
+          this.isMore = false
+        }
+      })
+    }
+  },
+  onLoad() {
+    this.getFree()
+  },
+  onReachBottom(e) {
+    if (!this.isMore) return
+    this.page += 1
+    this.getFree()
+  }
 }
 </script>
 

+ 26 - 14
server/app/Http/Controllers/V1/EpisodeController.php

xqd xqd xqd xqd
@@ -98,13 +98,8 @@ class EpisodeController extends Controller
             ->offset($offset)
             ->get();
 
-        $lists = [];
-        /* @var Episode $episode*/
-        foreach ($episodes as $episode){
-            $episode->status_text = $episode->status;
-            $episode->total = $episode->lists_count;
-            $lists[] = $episode;
-        }
+
+        $lists = Episode::complete($episodes);
 
         return $this->success($lists);
     }
@@ -139,6 +134,7 @@ class EpisodeController extends Controller
         return $this->success($lists);
     }
 
+    // 追剧
     public function trace()
     {
         $lists = EpisodesCategory::with(['episodes' =>function($query){
@@ -184,17 +180,32 @@ class EpisodeController extends Controller
             ->offset($offset)
             ->get();
 
-        $lists = [];
-        /* @var Episode $episode*/
-        foreach ($episodes as $episode){
-            $episode->status_text = $episode->status;
-            $episode->total = $episode->lists_count;
-            $lists[] = $episode;
-        }
+        $lists = Episode::complete($episodes);
+
+        return $this->success($lists);
+    }
+
+    public function vipFree()
+    {
+        $limit = request()->input('limit',3);
+        $page = request()->input('page',1);
+        $offset = ($page - 1) * $limit;
+        $episodes = Episode::withCount(['lists'])
+            ->where('is_opend', 1)
+            ->where('is_vip_watch', 1)
+            ->where('platform', \user()->info->platform)
+            ->inRandomOrder()
+            ->orderByDesc('id')
+            ->limit($limit)
+            ->offset($offset)
+            ->get();
+
+        $lists = Episode::complete($episodes);
 
         return $this->success($lists);
     }
 
+    // 详情
     public function detail($id)
     {
         $episodes = Episode::withCount(['userWatchRecord','userCollect','userFavorite','lists'])
@@ -206,6 +217,7 @@ class EpisodeController extends Controller
         return $this->success($episodes);
     }
 
+    // 分享
     public function shared($id)
     {
         $res = Episode::find($id);

+ 19 - 0
server/app/Http/Controllers/V1/User/SignController.php

xqd
@@ -0,0 +1,19 @@
+<?php
+namespace App\Http\Controllers\V1\User;
+
+use App\Http\Controllers\V1\Controller;
+use App\Models\UserCollect;
+use App\Models\UserConsumeRecord;
+use App\Models\UserEpisodesRecord;
+use App\Models\UserWatchRecord;
+use Carbon\Carbon;
+use Dingo\Api\Http\Request;
+use Illuminate\Database\Eloquent\Builder;
+
+class SignController extends Controller
+{
+    public function check()
+    {
+
+    }
+}

+ 12 - 0
server/app/Models/Episode.php

xqd
@@ -71,6 +71,18 @@ class Episode extends Model
         'share_count' => 'integer'
     ];
 
+    public static function complete($episodes)
+    {
+        /* @var Episode $episode*/
+        foreach ($episodes as $episode){
+            $episode->status_text = $episode->status;
+            $episode->total = $episode->lists_count;
+        }
+
+        return $episodes;
+
+    }
+
     public function category()
     {
         return $this->belongsTo(EpisodesCategory::class,'category_id','id');

+ 44 - 29
server/routes/api.php

xqd xqd
@@ -76,36 +76,50 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\V1'], function ($api)
             $api->post('update', 'UserController@update'); //更新用户信息
 
 
-            $api->group(['prefix' => 'watch','namespace' => 'User'], function ($api){
+            $api->group(['namespace' => 'User'], function ($api){
                 /* @var Dingo\Api\Routing\Router $api*/
-                $api->get('record', 'WatchRecordsController@lists');
-                $api->get('recent', 'WatchRecordsController@recent');
-                $api->post('episode', 'WatchRecordsController@watched');
-            });
-
-            $api->group(['prefix' => 'consume','namespace' => 'User'], function ($api){
-                /* @var Dingo\Api\Routing\Router $api*/
-                $api->get('record', 'ConsumeController@record');
-            });
-
-            $api->group(['prefix' => 'recharge','namespace' => 'User'], function ($api){
-                /* @var Dingo\Api\Routing\Router $api*/
-                $api->get('record', 'RechargeController@record');
-            });
-
-            $api->group(['prefix' => 'collect','namespace' => 'User'], function ($api){
-                /* @var Dingo\Api\Routing\Router $api*/
-                $api->get('record', 'CollectController@record');
-                $api->post('{id}/check', 'CollectController@check');
-                $api->post('{id}/add', 'CollectController@add');
-                $api->post('{id}/destroy', 'CollectController@destroy');
-            });
-
-            $api->group(['prefix' => 'favorite','namespace' => 'User'], function ($api){
-                /* @var Dingo\Api\Routing\Router $api*/
-                $api->post('{id}/check', 'FavoriteController@check');
-                $api->post('{id}/add', 'FavoriteController@add');
-                $api->post('{id}/destroy', 'FavoriteController@destroy');
+                // 观看记录相关
+                $api->group(['prefix' => 'watch'], function ($api){
+                    /* @var Dingo\Api\Routing\Router $api*/
+                    $api->get('record', 'WatchRecordsController@lists');
+                    $api->get('recent', 'WatchRecordsController@recent');
+                    $api->post('episode', 'WatchRecordsController@watched');
+                });
+
+                // 消费相关
+                $api->group(['prefix' => 'consume'], function ($api){
+                    /* @var Dingo\Api\Routing\Router $api*/
+                    $api->get('record', 'ConsumeController@record');
+                });
+
+                // 充值相关
+                $api->group(['prefix' => 'recharge'], function ($api){
+                    /* @var Dingo\Api\Routing\Router $api*/
+                    $api->get('record', 'RechargeController@record');
+                });
+
+                // 收藏相关
+                $api->group(['prefix' => 'collect'], function ($api){
+                    /* @var Dingo\Api\Routing\Router $api*/
+                    $api->get('record', 'CollectController@record');
+                    $api->post('{id}/check', 'CollectController@check');
+                    $api->post('{id}/add', 'CollectController@add');
+                    $api->post('{id}/destroy', 'CollectController@destroy');
+                });
+
+                // 喜欢相关
+                $api->group(['prefix' => 'favorite'], function ($api){
+                    /* @var Dingo\Api\Routing\Router $api*/
+                    $api->post('{id}/check', 'FavoriteController@check');
+                    $api->post('{id}/add', 'FavoriteController@add');
+                    $api->post('{id}/destroy', 'FavoriteController@destroy');
+                });
+
+                // 签到相关
+                $api->group(['prefix' => 'sign'], function ($api){
+                    /* @var Dingo\Api\Routing\Router $api*/
+                    $api->post('{id}/check', 'SignController@check');
+                });
             });
         });
 
@@ -127,6 +141,7 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\V1'], function ($api)
             $api->get('rank', 'EpisodeController@rank'); // 排行
             $api->get('trace', 'EpisodeController@trace'); // 追剧
             $api->get('search', 'EpisodeController@search'); // 搜索
+            $api->get('vip/free', 'EpisodeController@vipFree'); // banner
             $api->get('{id}/detail', 'EpisodeController@detail'); // 详情
         });