Files
portal-api/app/Console/Commands/VPSMail.php
T
2025-07-24 16:18:27 +07:00

57 lines
1.2 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Jobs\Mail\ExpiryMail;
use App\Models\Customer;
use App\Models\ModuleVmware;
use Illuminate\Console\Command;
use Illuminate\Support\Carbon;
class VPSMail extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'vps:mail';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$jobs = [];
$allUser = Customer::get();
foreach ($allUser as $item)
{
$vps = ModuleVmware::where('customer_id',$item->id)->first();
if ($vps)
{
$ServiceExpiry = Carbon::now()->diffInDays(Carbon::parse($vps->next_due_date),false);
if ($ServiceExpiry <= 5 && $ServiceExpiry > 0)
{
$jobs[] = new ExpiryMail($vps->id,5,4);
}
}
}
foreach ($jobs as $_job)
{
dispatch($_job)->delay(now()->addSeconds(10));
}
return Command::SUCCESS;
}
}