91 lines
3.9 KiB
PHP
91 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Mail\WinningProof;
|
|
use App\Models\Participation;
|
|
use App\Models\Settings;
|
|
use App\User;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Mail;
|
|
|
|
class WinningProofController extends Controller
|
|
{
|
|
public function sendWinningProof(Request $request) {
|
|
// On récupère la participation gagnante en attente des infos
|
|
$participation = Participation::where([
|
|
['user_id', Auth::user()->id],
|
|
['instant_win_id', '<>', null],
|
|
['sticker', null],
|
|
['ticket', null],
|
|
['barcode', null]
|
|
])->first();
|
|
if (!$participation)
|
|
return redirect()->route('home');
|
|
|
|
$lastname = filter_var($request->lastname, FILTER_SANITIZE_STRING);
|
|
$firstname = filter_var($request->firstname, FILTER_SANITIZE_STRING);
|
|
$address = filter_var($request->address, FILTER_SANITIZE_STRING);
|
|
$address2 = $request->address2 !== null ? filter_var($request->address2, FILTER_SANITIZE_STRING) : null;
|
|
$town = filter_var($request->town, FILTER_SANITIZE_STRING);
|
|
$postalCode = filter_var($request->postal_code, FILTER_SANITIZE_STRING);
|
|
$country = filter_var($request->country, FILTER_SANITIZE_STRING);
|
|
$phone = filter_var($request->phone, FILTER_SANITIZE_STRING);
|
|
$sticker = $request->sticker;
|
|
$ticket = $request->ticket;
|
|
$barcode = $request->barcode;
|
|
|
|
$request->validate([
|
|
'lastname' => 'required|string|max:255',
|
|
'firstname' => 'required|string|max:255',
|
|
'address' => 'required|string|max:255',
|
|
'address2' => 'max:255',
|
|
'town' => 'required|string|max:255',
|
|
'postal_code' => 'required|max:255',
|
|
'country' => 'required|string|max:255',
|
|
'phone' => 'required|string|max:50',
|
|
'sticker' => 'required|mimes:jpeg,png,jpg,pdf|max:1536',
|
|
'ticket' => 'required|mimes:jpeg,png,jpg,pdf|max:1536',
|
|
'barcode' => 'required|mimes:jpeg,png,jpg,pdf|max:1536',
|
|
]);
|
|
|
|
// Mise à jour de l'utilisateur
|
|
$user = User::find(Auth::user()->id);
|
|
$user->lastname = $lastname;
|
|
$user->firstname = $firstname;
|
|
$user->address = $address;
|
|
$user->address2 = $address2;
|
|
$user->town = $town;
|
|
$user->postal_code = $postalCode;
|
|
$user->country = $country;
|
|
$user->phone = $phone;
|
|
$user->save();
|
|
|
|
$participationId = $participation->id;
|
|
$stickerFileName = $participationId . '-sticker.' . $sticker->extension();
|
|
$sticker->move(public_path('fichiers/preuve-de-gain/' . $participationId . '/'), $stickerFileName);
|
|
$stickerPath = public_path() . '/fichiers/preuve-de-gain/' . $participationId . '/' . $stickerFileName;
|
|
|
|
$ticketFileName = $participationId . '-ticket.' . $ticket->extension();
|
|
$ticket->move(public_path('fichiers/preuve-de-gain/' . $participationId . '/'), $ticketFileName);
|
|
$ticketPath = public_path() . '/fichiers/preuve-de-gain/' . $participationId . '/' . $ticketFileName;
|
|
|
|
$barcodeFileName = $participationId . '-code-barre.' . $barcode->extension();
|
|
$barcode->move(public_path('fichiers/preuve-de-gain/' . $participationId . '/'), $barcodeFileName);
|
|
$barcodePath = public_path() . '/fichiers/preuve-de-gain/' . $participationId . '/' . $barcodeFileName;
|
|
|
|
$participation->sticker = $stickerFileName;
|
|
$participation->ticket = $ticketFileName;
|
|
$participation->barcode = $barcodeFileName;
|
|
$participation->save();
|
|
|
|
$settings = Settings::find(1);
|
|
$mails = json_decode($settings->notification_emails);
|
|
foreach ($mails as $mail) {
|
|
Mail::to($mail)->send(new WinningProof($stickerPath, $ticketPath, $barcodePath, $participation, $user, $settings));
|
|
}
|
|
|
|
return view('front.basic.replay');
|
|
}
|
|
}
|