opt: mail & reset traffic

This commit is contained in:
Tokumeikoi 2020-08-19 12:52:49 +08:00
parent f3e9d43c44
commit 7c54939970
2 changed files with 9 additions and 6 deletions

View File

@ -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) {

View File

@ -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')),
],
/*