Pārlūkot izejas kodu

排行榜赚豆达人

duqinya 5 gadi atpakaļ
vecāks
revīzija
13607675d3

+ 12 - 11
app/Console/Commands/ExcellentResidents.php

@@ -61,16 +61,17 @@ class ExcellentResidents extends Command
     public function handle()
     {
         $this->line("开始统计星球居民相关内容");
-        $time = Carbon::now()->startOfDay()->toDateTimeString();
+        $yesterday_start = Carbon::now()->addDays(-1)->startOfDay()->toDateTimeString();
+        $yesterday_end = Carbon::now()->addDays(-1)->endOfDay()->toDateTimeString();
         $sum_quantity_issued = $this->behavior
             ->leftJoin('comment_account_record as c','behavior.virus_behavior_id','=','c.virus_behavior_id')
             ->leftJoin('general_ledger_record as g','behavior.virus_behavior_id','=','g.virus_behavior_id')
             ->leftJoin('registered_accounts_record as a','behavior.virus_behavior_id','=','a.virus_behavior_id')
             ->leftJoin('release_record as r','behavior.virus_behavior_id','=','r.virus_behavior_id')
-            ->where('c.created_at', '>=', $time)
-            ->orwhere('g.created_at', '>=', $time)
-            ->orwhere('a.created_at', '>=', $time)
-            ->orwhere('r.created_at', '>=', $time)
+            ->whereBetween('c.created_at', [$yesterday_start,$yesterday_end])
+            ->orwhereBetween('g.created_at', [$yesterday_start,$yesterday_end])
+            ->orwhereBetween('a.created_at', [$yesterday_start,$yesterday_end])
+            ->orwhereBetween('r.created_at', [$yesterday_start,$yesterday_end])
             ->get(array(
                     DB::raw('SUM(c.quantity_issued) as c_quantity_issued'),
                     DB::raw('SUM(g.quantity_issued) as g_quantity_issued'),
@@ -86,7 +87,7 @@ class ExcellentResidents extends Command
 
         //文章被评论最多用户
         $comment = $this->commentRecord
-            ->where('created_at', '>=', $time)
+            ->whereBetween('created_at', [$yesterday_start,$yesterday_end])
             ->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();
@@ -96,7 +97,7 @@ class ExcellentResidents extends Command
 
         //昨日拉新最多用户
         $registered = $this->registeredRecord
-            ->where('created_at', '>=', $time)
+            ->whereBetween('created_at', [$yesterday_start,$yesterday_end])
             ->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();
@@ -111,7 +112,7 @@ class ExcellentResidents extends Command
             ->first();
         $collent = $this->generalRecord
             ->where('virus_behavior_id', $virus_id->virus_behavior_id)
-            ->where('created_at', '>=', $time)
+            ->whereBetween('created_at', [$yesterday_start,$yesterday_end])
             ->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();
@@ -126,7 +127,7 @@ class ExcellentResidents extends Command
             ->first();
         $like = $this->generalRecord
             ->where('virus_behavior_id', $virus_id->virus_behavior_id)
-            ->where('created_at', '>=', $time)
+            ->whereBetween('created_at', [$yesterday_start,$yesterday_end])
             ->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();
@@ -141,7 +142,7 @@ class ExcellentResidents extends Command
             ->first();
         $forward = $this->generalRecord
             ->where('virus_behavior_id', $virus_id->virus_behavior_id)
-            ->where('created_at', '>=', $time)
+            ->whereBetween('created_at', [$yesterday_start,$yesterday_end])
             ->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();
@@ -156,7 +157,7 @@ class ExcellentResidents extends Command
             ->first();
         $read = $this->generalRecord
             ->where('virus_behavior_id', $virus_id->virus_behavior_id)
-            ->where('created_at', '>=', $time)
+            ->whereBetween('created_at', [$yesterday_start,$yesterday_end])
             ->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();

+ 7 - 5
app/Console/Commands/RankingList.php

@@ -55,8 +55,10 @@ class RankingList extends Command
 
     private function _condition($model)
     {
+        $yesterday_start = Carbon::now()->addDays(-1)->startOfDay()->toDateTimeString();
+        $yesterday_end = Carbon::now()->addDays(-1)->endOfDay()->toDateTimeString();
         return  $model->select(DB::raw('count(*) as count'),'generation_quantity','content_author_id','related_content_id')
-            ->where('created_at', '>=', Carbon::now()->startOfDay()->toDateTimeString())
+            ->whereBetween('created_at', [$yesterday_start,$yesterday_end])
             ->groupBy('generation_quantity','related_content_id','content_author_id')
             ->orderBy('generation_quantity','desc')
             ->limit(10)
@@ -72,11 +74,11 @@ class RankingList extends Command
     public function handle()
     {
         $this->line("开始统计排行榜相关内容");
-        $time = Carbon::now()->startOfDay()->toDateTimeString();
-
+        $yesterday_start = Carbon::now()->addDays(-1)->startOfDay()->toDateTimeString();
+        $yesterday_end = Carbon::now()->addDays(-1)->endOfDay()->toDateTimeString();
         //昨日拉新最多前十人
         $registered_most = $this->registeredRecord
-            ->where('created_at', '>=',$time)
+            ->whereBetween('created_at', [$yesterday_start,$yesterday_end])
             ->select(DB::raw('count(*) as count'),'superior_uid')
             ->groupBy('superior_uid')->orderBy('count','desc')->limit(10)->get();
         $registered_most = $registered_most->toArray();
@@ -93,7 +95,7 @@ class RankingList extends Command
             $general_best_author[$k]['type'] = 'general';
         }
         $release_author = $this->releaseRecord
-            ->where('created_at', '>=', $time)
+            ->whereBetween('created_at', [$yesterday_start,$yesterday_end])
             ->select(DB::raw('count(*) as count'),'generation_quantity','uid as content_author_id','related_content_id')
             ->groupBy('generation_quantity','content_author_id','related_content_id')->orderBy('generation_quantity','desc')->limit(10)->get();
         $release_best_author = $release_author->toArray();

+ 23 - 5
app/Repositories/BeanRepository.php

@@ -160,19 +160,37 @@ class BeanRepository
 
     public function rankingList($request)
     {
-        $time = Carbon::now()->startOfDay()->toDateTimeString();
+        $yesterday_start = Carbon::now()->addDays(-1)->startOfDay()->toDateTimeString();
+        $yesterday_end = Carbon::now()->addDays(-1)->endOfDay()->toDateTimeString();
         if ($request['type'] == 0){//排行榜赚豆达人
-            $all_bean = Redis::get('yesterday_all_bean');
-            $all_beans = json_decode($all_bean,true);
-
+            $all_beans = Redis::ZREVRANGEBYSCORE('user_rainbow_bean2019-06-21', 100000000, 0, array('WITHSCORES'=>true,'limit' => array(0, 20)));//.$yesterday
 
+                $new_arr = [];
+                $i = 0;
+                foreach ($all_beans as $key => $val) {
+                    $new_arr[$i]['uid'] = $key;
+                    $new_arr[$i]['bean'] = $val;
+                    $i++;
+                }
+            $uids = array_column($new_arr,'uid');
+            $user_data = $this->getFollowMembersStatus($uids);
+            if ($user_data){
+                foreach ($new_arr as $k=>$v){
+                    if(!isset($user_data[$v['uid']])) continue;
+                    $new_arr[$k]['follow_status'] = $user_data[$v['uid']]['follow_status'];
+                    $new_arr[$k]['username'] = $user_data[$v['uid']]['username'];
+                    $new_arr[$k]['avatar'] = $user_data[$v['uid']]['avatar'];
+                }
+            }
+            return $new_arr;
+//
         }elseif ($request['type'] == 1){//排行榜人脉达人
 //            $registered_most = Redis::get('yesterday_registered_most');
 //            $registered_mosts = json_decode($registered_most,true);
 
             //昨日拉新最多前十人
             $registered_most = RegisteredRecord::
-//                where('created_at', '>=',$time)
+//                whereBetween('created_at', [$yesterday_start,$yesterday_end])
                 select(DB::raw('count(*) as count'),'superior_uid')
                 ->groupBy('superior_uid')->orderBy('count','desc')->limit(10)->get();
             $registered_most = $registered_most->toArray();