feat: ✨ set winning proofs optionnal

This commit is contained in:
Alexis Gousseau 2026-09-28 15:52:43 +02:00
parent 7f8284e300
commit 6a6781831b
No known key found for this signature in database
GPG key ID: 7F3C786EE12DBB72
5 changed files with 81 additions and 57 deletions

View file

@ -33,42 +33,50 @@ class SubmitWinningProofRequest extends CreateAccountRequest
$this->integer('country') : ($authUser ?
(new CrmRepository())->fetchCrmCustomer($authUser)->country->value : 0);
$countryRules = match ($countryCode) {
Country::belgium->value => [
'phone' => 'phone:BE',
],
Country::luxembourg->value => [
'phone' => 'phone:LU',
],
Country::germany->value => [
'phone' => 'phone:DE',
],
default => [
'phone' => 'phone:FR',
]
Country::belgium->value => ['phone' => 'phone:BE'],
Country::luxembourg->value => ['phone' => 'phone:LU'],
Country::germany->value => ['phone' => 'phone:DE'],
default => ['phone' => 'phone:FR'],
};
return \array_merge(Arr::only(
parent::rules(),
return \array_merge(
Arr::only(
parent::rules(),
[
'lastname',
'firstname',
'address',
'address2',
'postal_code',
'city',
'country',
]
),
[
'lastname',
'firstname',
'address',
'address2',
'postal_code',
'city',
'country'
]
), [
'phone' => [
'required',
'max:255',
$countryRules['phone'],
'phone' => [
'required',
'max:255',
$countryRules['phone'],
],
],
// * Min 10 KB, Max 2MB
'sticker' => 'required|mimes:jpeg,jpg,png,pdf|min:10|max:2048',
'ticket' => 'required|mimes:jpeg,jpg,png,pdf|min:10|max:2048',
'barcode' => 'required|mimes:jpeg,jpg,png,pdf|min:10|max:2048',
]);
$this->proofRules()
);
}
/**
* Rules of winning proof.
*
* @return array<string, string>
*/
private function proofRules(): array
{
// * Min 10 KB, Max 2MB
$fileRules = 'required|mimes:jpeg,jpg,png,pdf|min:10|max:2048';
return collect(['sticker', 'ticket', 'barcode'])
->filter(fn (string $proof) => config("proofs.$proof"))
->mapWithKeys(fn (string $proof) => [$proof => $fileRules])
->all();
}
/**

View file

@ -28,10 +28,10 @@ class WinningProofAdminMail extends Mailable implements ShouldQueue
* @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
* @param string|null $sticker Fichier image du sticker utilisé.
* @param string|null $ticket Fichier image du ticket de caisse prouvant
* l'achat du produit stické.
* @param string $barcode Fichier image du code-barres du produit acheté.
* @param string|null $barcode Fichier image du code-barres du produit acheté.
*
* @return void
*/
@ -42,9 +42,9 @@ class WinningProofAdminMail extends Mailable implements ShouldQueue
protected Customer $customer,
protected ?string $unique_code,
protected ?string $ean_code,
protected string $sticker,
protected string $ticket,
protected string $barcode,
protected ?string $sticker,
protected ?string $ticket,
protected ?string $barcode,
) {
}
@ -71,7 +71,7 @@ class WinningProofAdminMail extends Mailable implements ShouldQueue
public function content(): \Illuminate\Mail\Mailables\Content
{
$participation = [];
if (!is_null($this->ean_code)) {
if (!is_null($this->unique_code)) {
$participation = [
trans('Code Unique : :code', ['code' => $this->unique_code]),
];
@ -106,10 +106,12 @@ class WinningProofAdminMail extends Mailable implements ShouldQueue
*/
public function attachments(): array
{
return [
Attachment::fromPath(FileStorageHelper::getFileFullPath($this->sticker)),
Attachment::fromPath(FileStorageHelper::getFileFullPath($this->ticket)),
Attachment::fromPath(FileStorageHelper::getFileFullPath($this->barcode)),
];
return collect([$this->sticker, $this->ticket, $this->barcode])
->filter()
->map(fn (string $file) => Attachment::fromPath(
FileStorageHelper::getFileFullPath($file)
))
->values()
->all();
}
}

View file

@ -17,9 +17,9 @@ use IPLib\Address\AddressInterface;
* Participation.
*
* @property \IPLib\Address\AddressInterface $ip IP
* @property string $sticker Path of the sticker file
* @property string $ticket Path of the ticket file
* @property string $barcode Path of the barcode file
* @property string|null $sticker Path of the sticker file
* @property string|null $ticket Path of the ticket file
* @property string|null $barcode Path of the barcode file
* @property string|null $discount_code Treatment code of the BR
* @property string $comment Administrators comments
* @property boolean $prize_sent Has the won prize been sent ?

View file

@ -90,19 +90,26 @@ class ParticipationPolicy
{
/** @var \App\Models\Settings */
$settings = app(Settings::class);
return $settings->winning_proof and Participation::query()
// Columns of the winning proofs enabled in the config.
$enabledProofs = array_keys(array_filter(config('proofs')));
// Winning proofs are disabled globally or no proof is enabled in the config.
if (! $settings->winning_proof || empty($enabledProofs)) {
return false;
}
return Participation::query()
->where('prize_sent', false)
->whereHas(
'customer',
fn (Builder $q) =>
$q->where('id', $authUser->id)
)->where('id', $model->id)->whereHas('instantWin')
->where(function (Builder $q) {
$q->whereNull(
['sticker', 'ticket', 'barcode'],
'or'
);
})->exists();
fn (Builder $q) => $q->where('id', $authUser->id)
)
->where('id', $model->id)
->whereHas('instantWin')
// At least one enabled proof has not been submitted yet.
->where(fn (Builder $q) => $q->whereNull($enabledProofs, 'or'))
->exists();
}
/**

7
config/proofs.php Normal file
View file

@ -0,0 +1,7 @@
<?php
return [
'sticker' => filter_var(env('PROOF_STICKER', true), FILTER_VALIDATE_BOOLEAN),
'ticket' => filter_var(env('PROOF_TICKET', true), FILTER_VALIDATE_BOOLEAN),
'barcode' => filter_var(env('PROOF_BARCODE', true), FILTER_VALIDATE_BOOLEAN),
];