From 21a9074b3ff67c8005878c4317462c9268d7e697 Mon Sep 17 00:00:00 2001 From: tokumeikoi Date: Wed, 9 Feb 2022 02:58:49 +0800 Subject: [PATCH] update: fix reset traffic --- app/Console/Commands/ResetTraffic.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/app/Console/Commands/ResetTraffic.php b/app/Console/Commands/ResetTraffic.php index b93d9168..cf248f74 100644 --- a/app/Console/Commands/ResetTraffic.php +++ b/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; }