diff --git a/app/Jobs/SendSubscriptionExpiredPhase1Notifications.php b/app/Jobs/SendSubscriptionExpiredPhase1Notifications.php new file mode 100644 index 0000000..c9291c8 --- /dev/null +++ b/app/Jobs/SendSubscriptionExpiredPhase1Notifications.php @@ -0,0 +1,33 @@ +chunk(100, function ($members) { + foreach ($members as $member) { + $member->notify(new SubscriptionExpiredPhase1()); + } + }); + } +} diff --git a/app/Models/Member.php b/app/Models/Member.php index 6c294cd..efc7d4b 100644 --- a/app/Models/Member.php +++ b/app/Models/Member.php @@ -155,4 +155,11 @@ class Member extends Model return $membership->services()->where('identifier', $serviceIdentifier)->exists(); } + public function isExpired(): bool + { + // Member ayant leur dernière adhésion non renouvellée de puis plus d'un mois + $lastMembership = $this->lastMembership(); + return $lastMembership->status === 'expired' || $lastMembership->created_at->addMonths(1) < now(); + } + } diff --git a/app/Notifications/SubscriptionExpiredPhase1.php b/app/Notifications/SubscriptionExpiredPhase1.php new file mode 100644 index 0000000..f27d366 --- /dev/null +++ b/app/Notifications/SubscriptionExpiredPhase1.php @@ -0,0 +1,58 @@ + + */ + public function via(object $notifiable): array + { + return ['mail']; + } + + /** + * Get the mail representation of the notification. + */ + public function toMail(object $notifiable): MailMessage + { + //@todo: créer template générique + espace dans le BO pour alimenter les texte + return (new MailMessage) + ->subject('Votre adhésion est expirée') + ->greeting('Bonjour ' . $notifiable->name) + ->line('Votre adhésion est arrivée à expiration.') + ->line('Pour continuer à profiter nos services, merci de le renouveler.') + ->action('Renouveler mon adhésion', url('/devenir-membre')) + ->line('Merci pour votre confiance.'); + } + + /** + * Get the array representation of the notification. + * + * @return array + */ + public function toArray(object $notifiable): array + { + return [ + // + ]; + } +}