mirror of
https://github.com/Bigherollc/wticreatorstudio.git
synced 2026-09-22 18:13:07 -04:00
94 lines
2.5 KiB
PHP
94 lines
2.5 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 App\Traits\SendMail;
|
|
use Carbon\Carbon;
|
|
|
|
|
|
class SubscriptionRenewalReminder extends Command
|
|
{
|
|
use SendMail;
|
|
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'command:subscription-renewal-reminder';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Subscription Renewal Reminder.';
|
|
|
|
/**
|
|
* Create a new command instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function handle()
|
|
{
|
|
CustomerSubscription::with(['user','planPrice'])->where('status','active')->where('paid_invoice','>',1)->where('payment_method','stripe')->orderBy('id')->chunk(10, function ($subscriptions) {
|
|
|
|
foreach ($subscriptions as $key => $subscription) {
|
|
|
|
if($subscription->payment_mode == 'Monthly'){
|
|
$expiredDate = Carbon::parse($subscription->expired_at);
|
|
$willRenew = ($subscription->paid_invoice - 1) == $subscription->planPrice->custom_interval;
|
|
} else {
|
|
$expiredDate = Carbon::parse($subscription->created_at)->addYear();
|
|
$willRenew = true;
|
|
}
|
|
|
|
$diffInDays = $expiredDate->diffInDays(Carbon::now());
|
|
|
|
if($willRenew && ($diffInDays == 3 || $diffInDays == 7)){
|
|
$this->sendSubscriptionRenewalReminder('Upcoming Renewal',$subscription->user->email,$expiredDate->toFormattedDateString());
|
|
Log::info('Successfully Sent Subscription Renewal Reminder');
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 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],
|
|
];
|
|
}
|
|
}
|