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

115 lines
4.2 KiB
PHP

<?php
namespace App\Mail\Won;
use App\Lib\Helpers\FileStorageHelper;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Attachment;
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 WinningProofAdminMail 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.
* @param string $sticker Fichier image du sticker utilisé.
* @param string $ticket Fichier image du ticket de caisse prouvant
* l'achat du produit stické.
* @param string $barcode Fichier image du code-barres du produit acheté.
*
* @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,
protected string $sticker,
protected string $ticket,
protected string $barcode,
) {
}
/**
* Get the message envelope.
*
* @return \Illuminate\Mail\Mailables\Envelope
*/
public function envelope(): \Illuminate\Mail\Mailables\Envelope
{
return new Envelope(
subject: trans('Preuve de gains de :lastname :firstname', [
'lastname' => $this->customer->lastname,
'firstname' => $this->customer->firstname
]),
);
}
/**
* Get the message content definition.
*
* @return \Illuminate\Mail\Mailables\Content
*/
public function content(): \Illuminate\Mail\Mailables\Content
{
$participation = [];
if (!is_null($this->ean_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(
'Vous trouverez en PJ les preuves de gain du joueur suivant :',
))->lines([
trans('Lot :'),
"{$this->prize_label}",
])->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()
);
}
/**
* Get the attachments for the message.
*
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
*/
public function attachments(): array
{
return [
Attachment::fromPath(FileStorageHelper::getFileFullPath($this->sticker)),
Attachment::fromPath(FileStorageHelper::getFileFullPath($this->ticket)),
Attachment::fromPath(FileStorageHelper::getFileFullPath($this->barcode)),
];
}
}