Forráskód Böngészése

返回数据取消判断

duqinya 5 éve
szülő
commit
caa9b71089

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

@@ -5,6 +5,7 @@
  * Date: 2019/6/20
  * Time: 下午2:27
  */
+
 namespace App\Console\Commands;
 
 
@@ -57,13 +58,12 @@ class RankingList extends Command
     {
         $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')
-            ->whereBetween('created_at', [$yesterday_start,$yesterday_end])
-            ->groupBy('generation_quantity','related_content_id','content_author_id')
-            ->orderBy('generation_quantity','desc')
+        return $model->select(DB::raw('count(*) as num'), 'generation_quantity', 'content_author_id', DB::raw('sum(generation_quantity) as count'))
+            ->whereBetween('created_at', [$yesterday_start, $yesterday_end])
+            ->groupBy('generation_quantity', 'content_author_id')
+            ->orderBy('count', 'desc')
             ->limit(10)
             ->get();
-
     }
 
     /**
@@ -88,19 +88,23 @@ class RankingList extends Command
         $comment_best_author = $comment_author->toArray();
         foreach ($comment_best_author as $k => $v) {
             $comment_best_author[$k]['type'] = 'comment';
+            $v['count'] = intval($v['count']);
         }
         $general_author = $this->_condition($this->generalRecord);
         $general_best_author = $general_author->toArray();
         foreach ($general_best_author as $k => $v) {
             $general_best_author[$k]['type'] = 'general';
+            $v['count'] = intval($v['count']);
         }
         $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();
+            ->select(DB::raw('count(*) as num'), 'generation_quantity', 'uid as content_author_id', DB::raw('sum(generation_quantity) as count'))
+            ->groupBy('generation_quantity', 'content_author_id')->orderBy('count', 'desc')->limit(10)->get();
+
         $release_best_author = $release_author->toArray();
         foreach ($release_best_author as $k => $v) {
             $release_best_author[$k]['type'] = 'release';
+            $v['count'] = intval($v['count']);
         }
         $all_best_author = array_merge($comment_best_author, $general_best_author, $release_best_author);
 

+ 1 - 5
app/Http/Controllers/V1/BeanDetailController.php

@@ -29,12 +29,8 @@ class BeanDetailController extends Controller
             return $this->jsonError($validator->errors()->first());
         }
         $top_most = $this->beanRepository->rankingList($data);
-        if ($top_most){
-            return success(['list'=>$top_most]);
-        }else{
-            return success(['list' => []]);
-        }
 
+            return success(['list'=>$top_most]);
     }
 
     //分享/邀请首页