wesmiler 1 year ago
parent
commit
6e1e2babe4

+ 16 - 1
app/Http/Controllers/Api/v1/LiveController.php

@@ -31,7 +31,10 @@ class LiveController extends webApp
        }
     }
 
-
+    /**
+     * 在线用户数据
+     * @return array
+     */
     public function users()
     {
         $params =request()->post();
@@ -41,6 +44,18 @@ class LiveController extends webApp
     }
 
     /**
+     * 礼物列表
+     * @return array
+     */
+    public function giftList()
+    {
+        $params =request()->post();
+        $pageSize = request()->post('pageSize', 15);
+        $datas = LiveService::make()->getGiftList($params, $pageSize, $this->userId);
+        return message(1010, true, $datas);
+    }
+
+    /**
      * 播放与浏览
      * @return array
      */

+ 25 - 0
app/Models/LiveGiftModel.php

@@ -0,0 +1,25 @@
+<?php
+// +----------------------------------------------------------------------
+// | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
+// +----------------------------------------------------------------------
+// | 版权所有 2017~2021 LARAVEL研发中心
+// +----------------------------------------------------------------------
+// | 官方网站: http://www.laravel.cn
+// +----------------------------------------------------------------------
+// | Author: laravel开发员 <laravel.qq.com>
+// +----------------------------------------------------------------------
+
+namespace App\Models;
+
+/**
+ * 直播礼物-模型
+ * @author laravel开发员
+ * @since 2020/11/11
+ * @package App\Models
+ */
+class LiveGiftModel extends BaseModel
+{
+    // 设置数据表
+    protected $table = 'live_gift';
+
+}

+ 47 - 0
app/Services/LiveService.php

@@ -13,6 +13,7 @@ namespace App\Services;
 
 use AlibabaCloud\Tea\Exception\TeaUnableRetryError;
 use AlibabaCloud\SDK\Dysmsapi\V20170525\Dysmsapi;
+use App\Models\LiveGiftModel;
 use App\Models\LiveModel;
 use App\Models\MemberModel;
 use App\Models\VideoCollectModel;
@@ -293,6 +294,52 @@ class LiveService extends BaseService
     }
 
     /**
+     * 获取直播间礼物列表
+     * @param $params
+     * @param $pageSize
+     * @param int $userId
+     * @return array|mixed
+     */
+    public function getGiftList($params, $pageSize=30, $userId=0)
+    {
+        $liveId = isset($params['live_id'])? $params['live_id'] : 0;
+        $cachekey = "caches:live:gift_{$liveId}_{$userId}";
+        $datas = RedisService::get($cachekey);
+        if($datas || RedisService::exists($cachekey)){
+            return $datas? $datas : [
+                'pageSize'=> $pageSize,
+                'total'    => 0,
+                'list'     => []
+            ];
+        }
+
+        $list = LiveGiftModel::from('live_gift as a')
+            ->where(['a.status'=>1,'a.mark'=>1])
+            ->select(['a.id','a.name','a.code','a.money','a.icon','a.file_url','a.sort'])
+            ->orderBy('a.sort','desc')
+            ->orderBy('a.create_time','asc')
+            ->paginate($pageSize > 0 ? $pageSize : 9999999);
+        $list = $list ? $list->toArray() : [];
+        if ($list && $list['data']) {
+            foreach ($list['data'] as &$item) {
+                $item['icon'] = isset($member['icon']) && $member['icon']? get_image_url($member['icon']) : get_image_url('/images/gift/0.png');
+                $item['file_url'] = isset($member['file_url']) && $member['file_url']? get_image_url($member['file_url']) : '';
+            }
+            RedisService::set($cachekey, [
+                'pageSize' => $pageSize,
+                'total'    => isset($list['total']) ? $list['total'] : 0,
+                'list'     => isset($list['data']) ? $list['data'] : []
+            ], rand(5,10));
+        }
+
+        return [
+            'pageSize' => $pageSize,
+            'total'    => isset($list['total']) ? $list['total'] : 0,
+            'list'     => isset($list['data']) ? $list['data'] : []
+        ];
+    }
+
+    /**
      * 更新播放浏览历史
      * @param $userId 用户ID
      * @param $id 视频ID

BIN
public/uploads/images/gift/0.png


BIN
public/uploads/images/gift/1.gif


BIN
public/uploads/images/gift/1.png


BIN
public/uploads/images/gift/2.png


BIN
public/uploads/images/gift/3.png


BIN
public/uploads/images/gift/4.png


BIN
public/uploads/images/gift/5.png


+ 2 - 0
routes/api.php

@@ -52,6 +52,8 @@ Route::prefix('v1')->group(function(){
     Route::post('/live/users', [\App\Http\Controllers\Api\v1\LiveController::class, 'users']);
     Route::post('/live/create', [\App\Http\Controllers\Api\v1\LiveController::class, 'create']);
     Route::post('/live/info', [\App\Http\Controllers\Api\v1\LiveController::class, 'getInfo']);
+    Route::post('/live/giftList', [\App\Http\Controllers\Api\v1\LiveController::class, 'giftList']);
+    Route::post('/live/reward', [\App\Http\Controllers\Api\v1\LiveController::class, 'reward']);
     Route::post('/live/play', [\App\Http\Controllers\Api\v1\LiveController::class, 'updatePlay']);
     Route::post('/live/status', [\App\Http\Controllers\Api\v1\LiveController::class, 'status']);
     Route::post('/live/category/search', [\App\Http\Controllers\Api\v1\LiveCategoryController::class, 'search']);