Browse Source

Merge branch 'master' into release

wzq 5 years ago
parent
commit
14e559ccc6

+ 7 - 1
app/Http/Controllers/V1/CategoryController.php

@@ -25,7 +25,7 @@ class CategoryController extends Controller {
     public function index(Request $request) {
         $data = $categoryList = $this->categoryRepository->lists($request->all());
         return jsonSuccess(['topic_category' => $data]);
-}
+    }
     //获取多个话题
     public function getTopics(Request $request){
         $data = $request->only('ids');
@@ -38,4 +38,10 @@ class CategoryController extends Controller {
         $categoryList = $this->categoryRepository->getTopics($data['ids']);
         return jsonSuccess($categoryList);
     }
+
+    //分类列表(推荐内容首页用)
+    public function suggest() {
+        $data = $categoryList = $this->categoryRepository->suggest();
+        return jsonSuccess($data);
+    }
 }

+ 20 - 0
app/Models/CategorySuggest.php

@@ -0,0 +1,20 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/9/4
+ * Time: 14:48
+ */
+namespace App\Models;
+use Illuminate\Database\Eloquent\Model;
+
+class CategorySuggest extends Model
+{
+    protected $table = 'category_suggest';
+    protected $guarded = [];
+
+    public function category()
+    {
+        return $this->hasOne('App\Models\Category', 'id', 'category_id');
+    }
+}

+ 18 - 0
app/Repositories/BeanRepository.php

@@ -209,9 +209,27 @@ class BeanRepository
         }
         $star_home['user']['username'] = $userInfo['username'];
         $star_home['user']['avatar'] = $userInfo['avatar'];
+        //battle信息
+        $activityInfo = $this->getActivity();
+        $star_home['battle']['start'] = $activityInfo['start'];
+        $star_home['battle']['end'] = $activityInfo['end'];
+        $star_home['battle']['news'] = Redis::get('battle_latest_info_'.$activityInfo['id'])??'战场四平八稳,劳驾老板亲自去战场督战';
         return $star_home;
 
     }
+    function getActivity(){
+        $activity = config('customer.battle_activity_info');
+        $activityInfo = ['id'=>1];
+        if($activity){
+            try{
+                $activityInfo = \GuzzleHttp\json_decode($activity,true);
+            }catch (\Exception $e){
+                Log::debug('解析活动信息配置失败:'.$e->getMessage());
+                return $activityInfo;
+            }
+        }
+        return $activityInfo;
+    }
 
     //获取某用户豆数
     function get_user_bean($uid)

+ 30 - 1
app/Repositories/CategoryRepository.php

@@ -9,13 +9,15 @@
 namespace App\Repositories;
 
 use App\Models\Category;
+use App\Models\CategorySuggest;
 use App\Models\CategoryTopic;
 
 class CategoryRepository {
 
-    public function __construct(Category $category,CategoryTopic $categoryTopic) {
+    public function __construct(Category $category,CategoryTopic $categoryTopic, CategorySuggest $categorySuggest) {
         $this->category = $category;
         $this->categoryTopic = $categoryTopic;
+        $this->categorySuggest = $categorySuggest;
     }
     //列表
     public function lists($request)
@@ -53,4 +55,31 @@ class CategoryRepository {
             ->groupBy('topic.id')
             ->get();
     }
+
+    //分类列表(推荐内容首页用)
+    public function suggest()
+    {
+        $list = [
+            [
+                'id' => 0,
+                'name' => '推荐',
+                'img' => config('customer.category_hot_img')
+            ]
+        ];
+        $name = ['推荐'];
+
+        $res =  $this->categorySuggest->get();
+        foreach($res as $item){
+            $list[] = [
+                'id' => $item->category_id,
+                'name' => $item->category->name,
+                'img' => $item->category->img,
+            ];
+            $name[] = $item->category->name;
+        }
+        return [
+            'category_list' => $list,
+            'category_list_name' => $name,
+        ];
+    }
 }

+ 25 - 5
app/Repositories/PostRepositories.php

@@ -10,6 +10,7 @@ namespace App\Repositories;
 
 
 use App\Models\Behavior;
+use App\Models\CategoryTopic;
 use App\Models\MemberFollowTopic;
 use App\Models\Post;
 use App\Models\PostCollect;
@@ -50,6 +51,7 @@ class PostRepositories
                                 DetectionService $detectionService,
                                 AliYunVodService $aliYunVodService,
                                 MemberFollowTopic $memberFollowTopic,
+                                CategoryTopic $categoryTopic,
                                 Topic $topic)
     {
         $this->post = $post;
@@ -62,6 +64,7 @@ class PostRepositories
         $this->detectionService = $detectionService;
         $this->topic = $topic;
         $this->memberFollowTopic = $memberFollowTopic;
+        $this->categoryTopic = $categoryTopic;
         $this->aliYunVodService = $aliYunVodService;
     }
 
@@ -507,11 +510,28 @@ class PostRepositories
             $blacklist = [];
         }
 
-        return $this->post->where(function ($query) use ($blacklist) {
-            if ($blacklist) {
-                $query->whereNotIn('uid', $blacklist);
-            }
-        })
+        $topicIds = [];
+        if(isset($request['category_id']) && $request['category_id']){
+            $topicIds = $this->categoryTopic->where('category_id', $request['category_id'])->pluck('topic_id')->toArray();
+        }
+
+        return $this->post
+            ->where(function ($query) use ($blacklist) {
+                if ($blacklist) {
+                    $query->whereNotIn('uid', $blacklist);
+                }
+            })
+            ->where(function ($query) use ($topicIds) {
+                if ($topicIds) {
+                    foreach ($topicIds as $key => $id) {
+                        if ($key == 0) {
+                            $query = $query->whereRaw('FIND_IN_SET(' . $id . ', topic_ids)');
+                        } else {
+                            $query = $query->orWhereRaw('FIND_IN_SET(' . $id . ', topic_ids)');
+                        }
+                    }
+                }
+            })
             ->where('is_hide', 0)
             ->orderBy('is_suggest', 'desc')
             ->orderBy('weight', 'desc')

+ 1 - 0
config/customer.tpl

@@ -9,4 +9,5 @@ return [
     'post_delete_image' => '{post_delete_image}',
     'category_hot_img' => '{category_hot_img}',
     'category_my_img' => '{category_my_img}',
+    'battle_activity_info' => '{battle_activity_info}',
 ];

+ 3 - 0
routes/api.php

@@ -65,6 +65,9 @@ $api->version('v1', [
     //获取话题
     $api->get('topic/group', 'PostController@getTopic');
 
+    //分类列表(推荐内容首页用)
+    $api->get('post/category', 'CategoryController@suggest');
+
     //图片验证
     $api->get('post/checkImage', 'PostController@checkImage');