Bladeren bron

Merge remote-tracking branch 'origin/develop' into develop

wzq 5 jaren geleden
bovenliggende
commit
e20a76d2c4
2 gewijzigde bestanden met toevoegingen van 50 en 54 verwijderingen
  1. 35 39
      app/Console/Commands/ExcellentResidents.php
  2. 15 15
      app/Console/Commands/RankingList.php

+ 35 - 39
app/Console/Commands/ExcellentResidents.php

@@ -5,6 +5,7 @@
  * Date: 2019/6/19
  * Time: 下午3:45
  */
+
 namespace App\Console\Commands;
 
 
@@ -53,6 +54,17 @@ class ExcellentResidents extends Command
         $this->releaseRecord = $releaseRecord;
     }
 
+    private function _condition($model, $virus_behavior_id)
+    {
+        $yesterday_start = Carbon::now()->addDays(-1)->startOfDay()->toDateTimeString();
+        $yesterday_end = Carbon::now()->addDays(-1)->endOfDay()->toDateTimeString();
+        return $model
+            ->where('virus_behavior_id', $virus_behavior_id)
+            ->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();
+    }
+
     /**
      * Execute the console command.
      *
@@ -64,14 +76,14 @@ class ExcellentResidents extends Command
         $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')
-            ->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])
+            ->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')
+            ->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'),
@@ -81,27 +93,27 @@ class ExcellentResidents extends Command
             )->toArray();
         //昨日发放总豆
         $all_quantity_issued = 0;
-        foreach ($sum_quantity_issued as $k=>$v){
+        foreach ($sum_quantity_issued as $k => $v) {
             $all_quantity_issued += $v['c_quantity_issued'] + $v['g_quantity_issued'] + $v['a_quantity_issued'] + $v['r_quantity_issued'];
         }
 
         //文章被评论最多用户
         $comment = $this->commentRecord
-            ->whereBetween('created_at', [$yesterday_start,$yesterday_end])
+            ->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();
-        foreach ($comment as $k=>$v){
+        foreach ($comment as $k => $v) {
             $comment[$k]['type'] = 'comment';//类型
         }
 
         //昨日拉新最多用户
         $registered = $this->registeredRecord
-            ->whereBetween('created_at', [$yesterday_start,$yesterday_end])
+            ->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();
-        foreach ($registered as $k=>$v){
+        foreach ($registered as $k => $v) {
             $registered[$k]['type'] = 'registered';
         }
 
@@ -110,13 +122,9 @@ class ExcellentResidents extends Command
             ->select('virus_behavior_id')
             ->where('behavior_identification', 'collect')
             ->first();
-        $collent = $this->generalRecord
-            ->where('virus_behavior_id', $virus_id->virus_behavior_id)
-            ->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 = $this->_condition($this->generalRecord, $virus_id->virus_behavior_id);
         $collent = $collent->toArray();
-        foreach ($collent as $k=>$v){
+        foreach ($collent as $k => $v) {
             $collent[$k]['type'] = 'collent';
         }
 
@@ -125,13 +133,9 @@ class ExcellentResidents extends Command
             ->select('virus_behavior_id')
             ->where('behavior_identification', 'like')
             ->first();
-        $like = $this->generalRecord
-            ->where('virus_behavior_id', $virus_id->virus_behavior_id)
-            ->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 = $this->_condition($this->generalRecord, $virus_id->virus_behavior_id);
         $like = $like->toArray();
-        foreach ($like as $k=>$v){
+        foreach ($like as $k => $v) {
             $like[$k]['type'] = 'like';
         }
 
@@ -140,13 +144,9 @@ class ExcellentResidents extends Command
             ->select('virus_behavior_id')
             ->where('behavior_identification', 'forward')
             ->first();
-        $forward = $this->generalRecord
-            ->where('virus_behavior_id', $virus_id->virus_behavior_id)
-            ->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 = $this->_condition($this->generalRecord, $virus_id->virus_behavior_id);
         $forward = $forward->toArray();
-        foreach ($forward as $k=>$v){
+        foreach ($forward as $k => $v) {
             $forward[$k]['type'] = 'forward';
         }
 
@@ -155,20 +155,16 @@ class ExcellentResidents extends Command
             ->select('virus_behavior_id')
             ->where('behavior_identification', 'read')
             ->first();
-        $read = $this->generalRecord
-            ->where('virus_behavior_id', $virus_id->virus_behavior_id)
-            ->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 = $this->_condition($this->generalRecord, $virus_id->virus_behavior_id);
         $read = $read->toArray();
-        foreach ($read as $k=>$v){
+        foreach ($read as $k => $v) {
             $read[$k]['type'] = 'read';
         }
         $all_merge = array_merge($comment, $registered, $collent, $like, $forward, $read);
         $all_excellent_residents = json_encode($all_merge);
 
-        Log::info('统计昨日优秀居民内容'.json_encode($all_excellent_residents));
-        Log::info('昨日发放总彩虹豆'.json_encode($all_quantity_issued));
+        Log::info('统计昨日优秀居民内容' . json_encode($all_excellent_residents));
+        Log::info('昨日发放总彩虹豆' . json_encode($all_quantity_issued));
 
         Redis::set('yesterday_excellent_residents', $all_excellent_residents);
         Redis::set('yesterday_quantity_issued', $all_quantity_issued);

+ 15 - 15
app/Console/Commands/RankingList.php

@@ -78,39 +78,39 @@ class RankingList extends Command
         $yesterday_end = Carbon::now()->addDays(-1)->endOfDay()->toDateTimeString();
         //昨日拉新最多前十人
         $registered_most = $this->registeredRecord
-            ->whereBetween('created_at', [$yesterday_start,$yesterday_end])
-            ->select(DB::raw('count(*) as count'),'superior_uid')
-            ->groupBy('superior_uid')->orderBy('count','desc')->limit(10)->get();
+            ->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();
 
         //昨日文章产生彩虹豆最多前十人
         $comment_author = $this->_condition($this->commentRecord);
         $comment_best_author = $comment_author->toArray();
-        foreach ($comment_best_author as $k=>$v){
+        foreach ($comment_best_author as $k => $v) {
             $comment_best_author[$k]['type'] = 'comment';
         }
         $general_author = $this->_condition($this->commentRecord);
         $general_best_author = $general_author->toArray();
-        foreach ($general_best_author as $k=>$v){
+        foreach ($general_best_author as $k => $v) {
             $general_best_author[$k]['type'] = 'general';
         }
         $release_author = $this->releaseRecord
-            ->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();
+            ->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();
-        foreach ($release_best_author as $k=>$v){
+        foreach ($release_best_author as $k => $v) {
             $release_best_author[$k]['type'] = 'release';
         }
-        $all_best_author = array_merge($comment_best_author,$general_best_author,$release_best_author);
+        $all_best_author = array_merge($comment_best_author, $general_best_author, $release_best_author);
 
-        $column = array_column($all_best_author,'generation_quantity');
-        array_multisort($column,SORT_DESC,$all_best_author);
+        $column = array_column($all_best_author, 'generation_quantity');
+        array_multisort($column, SORT_DESC, $all_best_author);
 
-        $all_best_author = array_slice($all_best_author,0,10);
+        $all_best_author = array_slice($all_best_author, 0, 10);
 
-        Log::debug('昨日拉新最多前十人'.json_encode($registered_most));
-        Log::debug('昨日文章产生彩虹豆最多前十人'.json_encode($all_best_author));
+        Log::debug('昨日拉新最多前十人' . json_encode($registered_most));
+        Log::debug('昨日文章产生彩虹豆最多前十人' . json_encode($all_best_author));
 
         Redis::set('yesterday_registered_most', json_encode($registered_most));
         Redis::set('yesterday_best_author', json_encode($all_best_author));