duqinya 5 年之前
父节点
当前提交
dc4f39bdee
共有 1 个文件被更改,包括 14 次插入20 次删除
  1. 14 20
      app/Console/Commands/ExcellentResidents.php

+ 14 - 20
app/Console/Commands/ExcellentResidents.php

@@ -75,27 +75,21 @@ class ExcellentResidents extends Command
         $this->line("开始统计星球居民相关内容");
         $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])
-            ->get(array(
-                    DB::raw('SUM(c.quantity_issued) as c_quantity_issued'),
-                    DB::raw('SUM(g.quantity_issued) as g_quantity_issued'),
-                    DB::raw('SUM(a.quantity_issued) as a_quantity_issued'),
-                    DB::raw('SUM(r.quantity_issued) as r_quantity_issued')
-                )
-            )->toArray();
         //昨日发放总豆
-        $all_quantity_issued = 0;
-        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_quantity_issued = CommentRecord::select('quantity_issued')
+            ->whereBetween('created_at', [$yesterday_start, $yesterday_end])
+            ->sum('quantity_issued');
+        $general_quantity_issued = GeneralRecord::select('quantity_issued')
+            ->whereBetween('created_at', [$yesterday_start, $yesterday_end])
+            ->sum('quantity_issued');
+        $registered_quantity_issued = RegisteredRecord::select('quantity_issued')
+            ->whereBetween('created_at', [$yesterday_start, $yesterday_end])
+            ->sum('quantity_issued');
+        $release_quantity_issued = ReleaseRecord::select('quantity_issued')
+            ->whereBetween('created_at', [$yesterday_start, $yesterday_end])
+            ->sum('quantity_issued');
+
+        $all_quantity_issued = $comment_quantity_issued + $general_quantity_issued + $registered_quantity_issued + $release_quantity_issued;
 
         //文章被评论最多用户
         $comment = $this->commentRecord