duqinya 5 роки тому
батько
коміт
f86c05a33b
1 змінених файлів з 29 додано та 108 видалено
  1. 29 108
      app/Repositories/BeanRepository.php

+ 29 - 108
app/Repositories/BeanRepository.php

@@ -31,117 +31,37 @@ class BeanRepository
     //获取优秀居民信息
     function excellentResidents($request)
     {
-//        $get_excellent = Redis::get('yesterday_excellent_residents');
-//        $excellent_residents = json_decode($get_excellent);
-
-        //文章被评论最多用户
-        $comment = CommentRecord::
-//            where('created_at', '>=', $time)
-            select(DB::raw('count(*) as count'), 'content_author_id', 'related_content_id')
-            ->groupBy('related_content_id', 'content_author_id')->orderBy('count', 'desc')->limit(1)->get();
-        $comment = $comment->toArray();
-        foreach ($comment as $k=>$v){
-            $comment[$k]['type'] = 'comment';//类型
-        }
-
-        //昨日拉新最多用户
-        $registered = RegisteredRecord::
-//            ->where('created_at', '>=', $time)
-            select(DB::raw('count(*) as count'), 'superior_uid as content_author_id')//作为用户ID
-            ->groupBy('superior_uid')->orderBy('count', 'desc')->limit(1)->get();
-        $registered = $registered->toArray();
-        foreach ($registered as $k=>$v){
-            $registered[$k]['type'] = 'registered';
-        }
-
-        //文章被收藏最多用户
-        $virus_id = Behavior::
-            select('virus_behavior_id')
-            ->where('behavior_identification', 'collect')
-            ->first();
-        $collent = GeneralRecord::
-            where('virus_behavior_id', $virus_id->virus_behavior_id)
-//            ->where('created_at', '>=', $time)
-            ->select(DB::raw('count(*) as count'), 'content_author_id', 'related_content_id')
-            ->groupBy('related_content_id', 'content_author_id')->orderBy('count', 'desc')->limit(1)->get();
-        $collent = $collent->toArray();
-        foreach ($collent as $k=>$v){
-            $collent[$k]['type'] = 'collect';
-        }
-
-        //文章被喜欢最多用户
-        $virus_id = Behavior::
-            select('virus_behavior_id')
-            ->where('behavior_identification', 'like')
-            ->first();
-        $like = GeneralRecord::
-            where('virus_behavior_id', $virus_id->virus_behavior_id)
-//            ->where('created_at', '>=', $time)
-            ->select(DB::raw('count(*) as count'), 'content_author_id', 'related_content_id')
-            ->groupBy('related_content_id', 'content_author_id')->orderBy('count', 'desc')->limit(1)->get();
-        $like = $like->toArray();
-        foreach ($like as $k=>$v){
-            $like[$k]['type'] = 'like';
-        }
-
-        //文章被转发最多用户
-        $virus_id = Behavior::
-            select('virus_behavior_id')
-            ->where('behavior_identification', 'forward')
-            ->first();
-        $forward = GeneralRecord::
-            where('virus_behavior_id', $virus_id->virus_behavior_id)
-//            ->where('created_at', '>=', $time)
-            ->select(DB::raw('count(*) as count'), 'content_author_id', 'related_content_id')
-            ->groupBy('related_content_id', 'content_author_id')->orderBy('count', 'desc')->limit(1)->get();
-        $forward = $forward->toArray();
-        foreach ($forward as $k=>$v){
-            $forward[$k]['type'] = 'forward';
-        }
-
-        //文章被阅读最多用户
-        $virus_id = Behavior::
-            select('virus_behavior_id')
-            ->where('behavior_identification', 'read')
-            ->first();
-        $read = GeneralRecord::
-            where('virus_behavior_id', $virus_id->virus_behavior_id)
-//            ->where('created_at', '>=', $time)
-            ->select(DB::raw('count(*) as count'), 'content_author_id', 'related_content_id')
-            ->groupBy('related_content_id', 'content_author_id')->orderBy('count', 'desc')->limit(1)->get();
-        $read = $read->toArray();
-        foreach ($read as $k=>$v){
-            $read[$k]['type'] = 'read';
-        }
-        $excellent_residents = array_merge($comment, $registered, $collent, $like, $forward, $read);
-//        $excellent_residents = json_encode($all_merge);
-
-        //获取评论内容
-        $post_ids = array_column($excellent_residents,'related_content_id');
-        $comment_content = Post::select('id', 'title', 'content')->whereIn('id', $post_ids)->get();
-
-        foreach ($comment_content->toArray() as $value) {
-            foreach ($excellent_residents as $k=>$v) {
-                if (isset($v['related_content_id']) && $v['related_content_id'] == $value['id']) {
-                    if (!empty($value['title'])) {
-                        $excellent_residents[$k]['post_title'] = $value['title'];
-                    }
-                    if (empty($value['title']) && !empty($value['content'])){
-                        $content = strip_tags($value['content']);
-                        $excellent_residents[$k]['post_title'] = mb_substr($content, 0, 20);
+        $get_excellent = Redis::get('yesterday_excellent_residents');
+        $excellent_residents = json_decode($get_excellent,true);
+
+        if ($excellent_residents){
+            //获取评论内容
+            $post_ids = array_column($excellent_residents,'related_content_id');
+            $comment_content = Post::select('id', 'title', 'content')->whereIn('id', $post_ids)->get();
+
+            foreach ($comment_content->toArray() as $value) {
+                foreach ($excellent_residents as $k=>$v) {
+                    if (isset($v['related_content_id']) && $v['related_content_id'] == $value['id']) {
+                        if (!empty($value['title'])) {
+                            $excellent_residents[$k]['post_title'] = $value['title'];
+                        }
+                        if (empty($value['title']) && !empty($value['content'])){
+                            $content = strip_tags($value['content']);
+                            $excellent_residents[$k]['post_title'] = mb_substr($content, 0, 20);
+                        }
                     }
                 }
             }
-        }
-        $content_author_id = array_column($excellent_residents,'content_author_id');
-        $uids = implode(',', array_unique($content_author_id));
-        $author_data = $this->getFollowMembersStatus($uids);
-        if ($author_data){
-            foreach ($excellent_residents as $k=>$v){
-                if(!isset($author_data[$v['content_author_id']])) continue;
-                        $excellent_residents[$k]['follow_status'] = $author_data[$v['content_author_id']]['follow_status'];
-                        $excellent_residents[$k]['username'] = $author_data[$v['content_author_id']]['username'];
-                        $excellent_residents[$k]['avatar'] = $author_data[$v['content_author_id']]['avatar'];
+            $content_author_id = array_column($excellent_residents,'content_author_id');
+            $uids = implode(',', array_unique($content_author_id));
+            $author_data = $this->getFollowMembersStatus($uids);
+            if ($author_data){
+                foreach ($excellent_residents as $k=>$v){
+                    if(!isset($author_data[$v['content_author_id']])) continue;
+                    $excellent_residents[$k]['follow_status'] = $author_data[$v['content_author_id']]['follow_status'];
+                    $excellent_residents[$k]['username'] = $author_data[$v['content_author_id']]['username'];
+                    $excellent_residents[$k]['avatar'] = $author_data[$v['content_author_id']]['avatar'];
+                }
             }
         }
 
@@ -228,6 +148,7 @@ class BeanRepository
 
     }
 
+    //星球首页
     public function starHome($request)
     {
         $star_home = [];