Browse Source

update: fix reset traffic

tokumeikoi 3 years ago
parent
commit
21a9074b3f
1 changed files with 15 additions and 6 deletions
  1. 15 6
      app/Console/Commands/ResetTraffic.php

+ 15 - 6
app/Console/Commands/ResetTraffic.php

@@ -44,18 +44,27 @@ class ResetTraffic extends Command
     public function handle()
     {
         ini_set('memory_limit', -1);
-        foreach (Plan::get() as $plan) {
-            switch ($plan->reset_traffic_method) {
+        $resetMethods = Plan::select(
+            DB::raw("GROUP_CONCAT(`id`) as plan_ids"),
+            DB::raw("reset_traffic_method as method")
+        )
+            ->groupBy('reset_traffic_method')
+            ->get()
+            ->toArray();
+        foreach ($resetMethods as $resetMethod) {
+            $planIds = explode(',', $resetMethod['plan_ids']);
+            switch ($resetMethod['method']) {
                 case null: {
                     $resetTrafficMethod = config('v2board.reset_traffic_method', 0);
+                    $builder = with(clone($this->builder))->whereIn('plan_id', $planIds);
                     switch ((int)$resetTrafficMethod) {
                         // month first day
                         case 0:
-                            $this->resetByMonthFirstDay($this->builder);
+                            $this->resetByMonthFirstDay($builder);
                             break;
                         // expire day
                         case 1:
-                            $this->resetByExpireDay($this->builder);
+                            $this->resetByExpireDay($builder);
                             break;
                         // no action
                         case 2:
@@ -64,12 +73,12 @@ class ResetTraffic extends Command
                     break;
                 }
                 case 0: {
-                    $builder = with(clone($this->builder))->where('plan_id', $plan->id);
+                    $builder = with(clone($this->builder))->whereIn('plan_id', $planIds);
                     $this->resetByMonthFirstDay($builder);
                     break;
                 }
                 case 1: {
-                    $builder = with(clone($this->builder))->where('plan_id', $plan->id);
+                    $builder = with(clone($this->builder))->whereIn('plan_id', $planIds);
                     $this->resetByExpireDay($builder);
                     break;
                 }