Viewing file: ExpireCheck.php (3.77 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
namespace App\Console\Commands;
use App\Events\SendMail; use App\Models\CustomerPlan; use Carbon\Carbon; use Illuminate\Console\Command; use Illuminate\Support\Facades\Log;
class ExpireCheck extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'expiry:check';
/** * The console command description. * * @var string */ protected $description = 'check expiry date';
/** * Create a new command instance. * * @return void */ public function __construct() { parent::__construct(); }
/** * Execute the console command. * * @return int */ public function handle() { $emailTemplate = get_email_template('plan_expired'); if (!$emailTemplate) { return Command::FAILURE; } $customerPlans = CustomerPlan::where('status','approved')->where('is_current','yes')->whereNotNull('expired_date')->where('expiry_notified','no')->where('expired_date','<=',Carbon::now()->addDay(5))->limit(100)->get(); foreach ($customerPlans as $customerPlan){ if (isset($customerPlan->expired_date) && $customerPlan->expired_date) { $date = Carbon::now(); $renewDate = new \DateTime($customerPlan->expired_date); $diffDate = $renewDate->diff($date); $days = $diffDate->format('%a'); if (isset($customerPlan->recurring_type) && $customerPlan->recurring_type == 'monthly' || $customerPlan->recurring_type == 'yearly') { if ($days <= 5) { try { $regTemp = str_replace('{customer_name}', $customerPlan->customer->first_name . ' ' . $customerPlan->customer->last_name, $emailTemplate->body); $route = route('paymentgateway::email.payment.process', ['id' => $customerPlan->plan_id]); $regTemp = str_replace('{click_here}', "<a href=" . $route . ">" . trans('pay now') . "</a>", $regTemp); $regTemp = str_replace('{plan_expired_date}', formatDate($customerPlan->expired_date), $regTemp); SendMail::dispatch($customerPlan->customer->email, $emailTemplate->subject, $regTemp); $customerPlan->update(['expiry_notified' => 'yes']); } catch (\Exception $ex) { Log::info($ex); return Command::FAILURE; } } }else{ if ($days < 2) { try {
$regTemp = str_replace('{customer_name}', $customerPlan->customer->first_name . ' ' . $customerPlan->customer->last_name, $emailTemplate->body);
$route = route('paymentgateway::email.payment.process', ['id' => $customerPlan->plan_id]); $regTemp = str_replace('{click_here}', "<a href=" . $route . ">" . trans('pay now') . "</a>", $regTemp); $regTemp = str_replace('{plan_expired_date}', formatDate($customerPlan->expired_date), $regTemp); // dd($customerPlan->customer->email, $emailTemplate->subject, $regTemp); SendMail::dispatch($customerPlan->customer->email, $emailTemplate->subject, $regTemp); $customerPlan->update(['expiry_notified' => 'yes']); } catch (\Exception $ex) { Log::info($ex); return Command::FAILURE; } } } }
} return Command::SUCCESS; } }
|