fix: reset traffic

This commit is contained in:
Tokumeikoi 2020-09-14 17:43:47 +08:00
parent 0cfa6a0676
commit bb1a59291f

View File

@ -7,7 +7,7 @@ use App\Models\User;
class ResetTraffic extends Command class ResetTraffic extends Command
{ {
protected $user; protected $builder;
/** /**
* The name and signature of the console command. * The name and signature of the console command.
* *
@ -30,7 +30,7 @@ class ResetTraffic extends Command
public function __construct() public function __construct()
{ {
parent::__construct(); parent::__construct();
$this->user = User::where('expired_at', '!=', NULL) $this->builder = User::where('expired_at', '!=', NULL)
->where('expired_at', '>', time()); ->where('expired_at', '>', time());
} }
@ -56,9 +56,9 @@ class ResetTraffic extends Command
private function resetByMonthFirstDay():void private function resetByMonthFirstDay():void
{ {
$user = $this->user; $builder = $this->builder;
if ((string)date('d') === '01') { if ((string)date('d') === '01') {
$user->update([ $builder->update([
'u' => 0, 'u' => 0,
'd' => 0 'd' => 0
]); ]);
@ -67,10 +67,10 @@ class ResetTraffic extends Command
private function resetByExpireDay():void private function resetByExpireDay():void
{ {
$user = $this->user; $builder = $this->builder;
$lastDay = date('d', strtotime('last day of +0 months')); $lastDay = date('d', strtotime('last day of +0 months'));
$users = []; $users = [];
foreach ($user->get() as $item) { foreach ($builder->get() as $item) {
$expireDay = date('d', $item->expired_at); $expireDay = date('d', $item->expired_at);
$today = date('d'); $today = date('d');
if ($expireDay === $today) { if ($expireDay === $today) {