apiCrm = new \LDCCRM\ApiV1(config('crm.endpoint'), config('crm.token')); } 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'); } $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:2048', 'ticket' => 'required|mimes:jpeg,png,jpg,pdf|max:2048', 'barcode' => 'required|mimes:jpeg,png,jpg,pdf|max:2048', ]); $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; // Mise à jour de l'utilisateur en local $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(); // Mise à jour utilisateur dans la CRM $update = $this->apiCrm->updateCustomer($user->crm_id, $firstname, $lastname, null, null, $phone, $address, $address2, $town, $postalCode, ucfirst($country)); if ($update->status !== 'OK') { Log::warning('Erreur lors de la mise a jour du user (crm_id : ' . $user->crm_id . ') - code : ' . $update->code . ' - message : ' . $update->message); Mail::to(config('mail.MAIL_ADMIN'))->send(new NotifAdmin('CRM : Erreur lors de la mise a jour du user (crm_id : ' . $user->crm_id . ') - code : ' . $update->code . ' - message : ' . $update->message)); } $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(); /** @var \App\Models\Settings $settings */ $settings = app(Settings::class); $mails = json_decode($settings->notification_emails); foreach ($mails as $mail) { Mail::to($mail->email)->send(new WinningProof($stickerPath, $ticketPath, $barcodePath, $participation, $user, $settings)); } return view('front.basic.replay'); } }