mirror of
				https://github.com/v2board/v2board.git
				synced 2025-10-31 09:21:46 +08:00 
			
		
		
		
	opt: mail & reset traffic
This commit is contained in:
		| @@ -7,6 +7,7 @@ use App\Models\User; | |||||||
|  |  | ||||||
| class ResetTraffic extends Command | class ResetTraffic extends Command | ||||||
| { | { | ||||||
|  |     protected $user; | ||||||
|     /** |     /** | ||||||
|      * The name and signature of the console command. |      * The name and signature of the console command. | ||||||
|      * |      * | ||||||
| @@ -29,6 +30,8 @@ class ResetTraffic extends Command | |||||||
|     public function __construct() |     public function __construct() | ||||||
|     { |     { | ||||||
|         parent::__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() |     public function handle() | ||||||
|     { |     { | ||||||
|         $user = User::where('expired_at', '!=', NULL) |  | ||||||
|             ->where('expired_at', '>', time()); |  | ||||||
|         $resetTrafficMethod = config('v2board.reset_traffic_method', 0); |         $resetTrafficMethod = config('v2board.reset_traffic_method', 0); | ||||||
|         switch ((int)$resetTrafficMethod) { |         switch ((int)$resetTrafficMethod) { | ||||||
|             // 1 a month |             // 1 a month | ||||||
|             case 0: |             case 0: | ||||||
|                 $this->resetByMonthFirstDay($user); |                 $this->resetByMonthFirstDay(); | ||||||
|                 break; |                 break; | ||||||
|             // expire day |             // expire day | ||||||
|             case 1: |             case 1: | ||||||
|                 $this->resetByExpireDay($user); |                 $this->resetByExpireDay(); | ||||||
|                 break; |                 break; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private function resetByMonthFirstDay($user):void |     private function resetByMonthFirstDay($user):void | ||||||
|     { |     { | ||||||
|  |         $user = $this->user; | ||||||
|         if ((string)date('d') === '01') { |         if ((string)date('d') === '01') { | ||||||
|             $user->update([ |             $user->update([ | ||||||
|                 'u' => 0, |                 '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')); |         $lastDay = date('d', strtotime('last day of +0 months')); | ||||||
|         $users = []; |         $users = []; | ||||||
|         foreach ($user->get() as $item) { |         foreach ($user->get() as $item) { | ||||||
|   | |||||||
| @@ -57,7 +57,7 @@ return [ | |||||||
|  |  | ||||||
|     'from' => [ |     'from' => [ | ||||||
|         'address' => env('MAIL_FROM_ADDRESS', config('v2board.mail_from_address')), |         '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')), | ||||||
|     ], |     ], | ||||||
|  |  | ||||||
|     /* |     /* | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user