wip(Notification system)
This commit is contained in:
33
app/Jobs/SendSubscriptionExpiredPhase1Notifications.php
Normal file
33
app/Jobs/SendSubscriptionExpiredPhase1Notifications.php
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs;
|
||||||
|
|
||||||
|
use App\Models\Member;
|
||||||
|
use App\Notifications\SubscriptionExpiredPhase1;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Foundation\Queue\Queueable;
|
||||||
|
|
||||||
|
class SendSubscriptionExpiredPhase1Notifications implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Queueable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new job instance.
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the job.
|
||||||
|
*/
|
||||||
|
public function handle(): void
|
||||||
|
{
|
||||||
|
Member::isExpired()
|
||||||
|
->chunk(100, function ($members) {
|
||||||
|
foreach ($members as $member) {
|
||||||
|
$member->notify(new SubscriptionExpiredPhase1());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -155,4 +155,11 @@ class Member extends Model
|
|||||||
return $membership->services()->where('identifier', $serviceIdentifier)->exists();
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
58
app/Notifications/SubscriptionExpiredPhase1.php
Normal file
58
app/Notifications/SubscriptionExpiredPhase1.php
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Notifications;
|
||||||
|
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Notifications\Messages\MailMessage;
|
||||||
|
use Illuminate\Notifications\Notification;
|
||||||
|
|
||||||
|
class SubscriptionExpiredPhase1 extends Notification implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Queueable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new notification instance.
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the notification's delivery channels.
|
||||||
|
*
|
||||||
|
* @return array<int, string>
|
||||||
|
*/
|
||||||
|
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<string, mixed>
|
||||||
|
*/
|
||||||
|
public function toArray(object $notifiable): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user