Files
wticreatorstudio/Modules/Subscription/Console/CustomerSubscriptionCommand.php
T
2024-02-12 22:54:20 -05:00

85 lines
1.8 KiB
PHP

<?php
namespace Modules\Subscription\Console;
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Modules\Subscription\Entities\CustomerSubscription;
use Carbon\Carbon;
class CustomerSubscriptionCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'customerSubscription:cron';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Check customer subscriptions';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$customerSubscriptions = CustomerSubscription::with(['user'])->where('status','active')->get();
foreach ($customerSubscriptions as $subscription) {
$expiredDate = Carbon::parse($subscription->expired_at);
$nowDate = Carbon::now();
if ($nowDate->gt($expiredDate)) {
$subscription->update([
'status' => 'expired'
]);
}
}
return true;
}
/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return [
['example', InputArgument::REQUIRED, 'An example argument.'],
];
}
/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return [
['example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null],
];
}
}