Files
portal-api/app/Console/Commands/HostingMail.php
T
2026-09-27 11:42:40 +07:00

58 lines
1.3 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Jobs\Mail\ExpiryMail;
use App\Models\Customer;
use App\Models\ModuleHosting;
use Illuminate\Console\Command;
use Illuminate\Support\Carbon;
class HostingMail extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'hosting: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)
{
$Hosting = ModuleHosting::with('Server')->where('customer_id',$item->id)->first();
if ($Hosting)
{
$ServiceExpiry = (int) Carbon::now()->diffInDays(Carbon::parse($Hosting->next_due_date), false);
if ($ServiceExpiry <= 5 && $ServiceExpiry >= 0)
{
$jobs[] = new ExpiryMail($item->id,5,3);
}
}
}
foreach ($jobs as $_job)
{
dispatch($_job)->delay(now()->addSeconds(10));
}
return Command::SUCCESS;
}
}