ldc-gen-game-web/app/Mail/Won/PrizeWonAdminMail.php
2025-08-14 14:12:13 +00:00

92 lines
3.1 KiB
PHP

<?php
namespace App\Mail\Won;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Queue\SerializesModels;
use LDC\LDCCRM\Models\Customer;
class PrizeWonAdminMail extends Mailable implements ShouldQueue
{
use Queueable;
use SerializesModels;
/**
* Create a new message instance.
*
* @param string $game_name The game name.
* @param \Carbon\Carbon $participation_date The customer participation date.
* @param string $prize_label The won prize label.
* @param \LDC\LDCCRM\Models\Customer $customer The customer who won.
* @param string|null $unique_code The unique code used to participate if any.
* @param string|null $ean_code The product code used to participate if any.
*
* @return void
*/
public function __construct(
protected string $game_name,
protected Carbon $participation_date,
protected string $prize_label,
protected Customer $customer,
protected ?string $unique_code,
protected ?string $ean_code
) {
}
/**
* Get the message envelope.
*
* @return \Illuminate\Mail\Mailables\Envelope
*/
public function envelope(): \Illuminate\Mail\Mailables\Envelope
{
return new Envelope(
subject: trans('Votre gain du jeu :game_name', [
'game_name' => $this->game_name
]),
);
}
/**
* Get the message content definition.
*
* @return \Illuminate\Mail\Mailables\Content
*/
public function content(): \Illuminate\Mail\Mailables\Content
{
$participation = [];
if (!is_null($this->unique_code)) {
$participation = [
trans('Code Unique : :code', ['code' => $this->unique_code]),
];
}
if (!is_null($this->ean_code)) {
$participation[] = trans('Code EAN : :code', ['code' => $this->ean_code]);
}
return new Content(
htmlString: (new MailMessage())
->greeting(trans('Bonjour,'))
->line(trans(
'Le lot suivant a été gagné :prize_label le :date',
[
'prize_label' => $this->prize_label,
'date' => $this->participation_date->isoFormat('LLLL')
]
))->lines([
trans('Gagnant :'),
"{$this->customer->lastname} {$this->customer->firstname}",
"{$this->customer->address}",
"{$this->customer->address2}",
"{$this->customer->postcode} {$this->customer->city} - {$this->customer->country->label}",
"{$this->customer->email}",
"{$this->customer->phone}",
])->lines($participation)->render()
);
}
}