Browse Source

opt: mail & reset traffic

Tokumeikoi 4 years ago
parent
commit
7c54939970
2 changed files with 9 additions and 6 deletions
  1. 8 5
      app/Console/Commands/ResetTraffic.php
  2. 1 1
      config/mail.php

+ 8 - 5
app/Console/Commands/ResetTraffic.php

@@ -7,6 +7,7 @@ use App\Models\User;
 
 class ResetTraffic extends Command
 {
+    protected $user;
     /**
      * The name and signature of the console command.
      *
@@ -29,6 +30,8 @@ class ResetTraffic extends Command
     public function __construct()
     {
         parent::__construct();
+        $this->user = User::where('expired_at', '!=', NULL)
+            ->where('expired_at', '>', time());
     }
 
     /**
@@ -38,23 +41,22 @@ class ResetTraffic extends Command
      */
     public function handle()
     {
-        $user = User::where('expired_at', '!=', NULL)
-            ->where('expired_at', '>', time());
         $resetTrafficMethod = config('v2board.reset_traffic_method', 0);
         switch ((int)$resetTrafficMethod) {
             // 1 a month
             case 0:
-                $this->resetByMonthFirstDay($user);
+                $this->resetByMonthFirstDay();
                 break;
             // expire day
             case 1:
-                $this->resetByExpireDay($user);
+                $this->resetByExpireDay();
                 break;
         }
     }
 
     private function resetByMonthFirstDay($user):void
     {
+        $user = $this->user;
         if ((string)date('d') === '01') {
             $user->update([
                 'u' => 0,
@@ -63,8 +65,9 @@ class ResetTraffic extends Command
         }
     }
 
-    private function resetByExpireDay($user):void
+    private function resetByExpireDay():void
     {
+        $user = $this->user;
         $lastDay = date('d', strtotime('last day of +0 months'));
         $users = [];
         foreach ($user->get() as $item) {

+ 1 - 1
config/mail.php

@@ -57,7 +57,7 @@ return [
 
     'from' => [
         'address' => env('MAIL_FROM_ADDRESS', config('v2board.mail_from_address')),
-        'name' => env('MAIL_FROM_NAME', config('v2board.mail_from_name')),
+        'name' => env('MAIL_FROM_NAME', config('v2board.mail_from_address')),
     ],
 
     /*