67 lines
1.5 KiB
PHP
67 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Jobs\VirtualMachine\Action\VMJobs;
|
|
use App\Models\Customer;
|
|
use App\Models\ModuleVmware;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Console\Command;
|
|
|
|
class ServiceVPS extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'vps:expiry';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Check Expiry for VPS Services';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return int
|
|
*/
|
|
public function handle()
|
|
{
|
|
$jobs = [];
|
|
$allUser = Customer::get();
|
|
|
|
foreach ($allUser as $item)
|
|
{
|
|
$allService = ModuleVmware::where('customer_id',$item->id)
|
|
->get();
|
|
if ($allService->count())
|
|
{
|
|
foreach ($allService as $service)
|
|
{
|
|
$ServiceExpiry = Carbon::now()->diffInDays(Carbon::parse($service->next_due_date),false);
|
|
|
|
if ($ServiceExpiry <= 0)
|
|
{
|
|
$jobs[] = new VMJobs($service->id,'PowerOff',false);
|
|
|
|
$service->status = 4;
|
|
|
|
$service->save();
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
foreach ($jobs as $_job)
|
|
{
|
|
dispatch($_job)->delay(now()->addSeconds(10));
|
|
}
|
|
return Command::SUCCESS;
|
|
}
|
|
}
|