ldc-gen-game-web/app/Mail/Won/PrizeWonAdminMail.php
2023-12-12 16:05:41 +01:00

90 lines
3 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 $unique_code The unique code used to participate.
* @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|null $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 = [
trans('Participation :'),
"Code Unique : {$this->unique_code}",
];
if ($this->ean_code) {
$participation[] = "Code EAN : {$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()
);
}
}