mirror of
https://github.com/v2board/v2board.git
synced 2024-11-10 17:49:11 +08:00
opt: mail & reset traffic
This commit is contained in:
parent
f3e9d43c44
commit
7c54939970
@ -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) {
|
||||
|
@ -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')),
|
||||
],
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user