2019-01-15 14:17:15 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
2025-11-12 16:35:16 +01:00
|
|
|
use App\Models\Panier;
|
|
|
|
|
use App\Models\Campagne;
|
|
|
|
|
use App\Models\Coupon;
|
|
|
|
|
use App\Models\Contact;
|
2025-08-05 14:47:02 +02:00
|
|
|
use App\Enums\CampaignTypes;
|
2019-02-27 10:32:34 +01:00
|
|
|
use App\Traits\CouponTrait;
|
2019-02-13 16:37:14 +01:00
|
|
|
use App\Traits\ThanksTrait;
|
2019-01-15 14:17:15 +01:00
|
|
|
|
|
|
|
|
class PanierController extends Controller
|
|
|
|
|
{
|
2019-02-13 16:37:14 +01:00
|
|
|
use ThanksTrait;
|
2019-02-27 10:32:34 +01:00
|
|
|
use CouponTrait;
|
2019-02-13 16:37:14 +01:00
|
|
|
|
2019-01-15 14:17:15 +01:00
|
|
|
public function showTemplate(Request $request)
|
|
|
|
|
{
|
2025-04-03 09:30:16 +02:00
|
|
|
// $panier = Panier::find($request->query('basketid'));
|
2019-01-29 12:26:00 +01:00
|
|
|
$panier = Panier::where(['panier_ref' => $request->basketid])->first();
|
2021-04-27 17:29:47 +02:00
|
|
|
if (!$panier) {
|
2019-02-28 17:05:24 +01:00
|
|
|
abort(404);
|
2019-01-29 12:26:00 +01:00
|
|
|
}
|
2019-01-15 14:17:15 +01:00
|
|
|
session()->put('panier', $panier);
|
2019-02-27 10:32:34 +01:00
|
|
|
$panierCouponsCount = $this->getCountCouponsPanierPublished($panier);
|
2025-04-03 09:30:16 +02:00
|
|
|
$contact = Contact::where(['contact_id' => $panier->panier_contactId])->first();
|
2021-04-27 17:29:47 +02:00
|
|
|
if (!$contact) {
|
2019-02-28 17:05:24 +01:00
|
|
|
abort(404);
|
2019-01-29 12:26:00 +01:00
|
|
|
}
|
|
|
|
|
session()->put('contact', $contact);
|
|
|
|
|
|
2019-02-28 17:05:24 +01:00
|
|
|
$campagne = Campagne::where(['camp_id' => $panier->panier_campId, 'camp_published' => 1])->first();
|
2021-04-27 17:29:47 +02:00
|
|
|
if (!$campagne) {
|
2019-02-28 17:05:24 +01:00
|
|
|
abort(404);
|
2019-01-29 12:26:00 +01:00
|
|
|
}
|
|
|
|
|
session()->put('campagne', $campagne);
|
|
|
|
|
|
2025-08-05 14:47:02 +02:00
|
|
|
if ($campagne->camp_type->equals(CampaignTypes::panier())) {
|
2019-02-27 10:32:34 +01:00
|
|
|
$coupons = $this->getCouponsPublished($campagne);
|
2019-02-13 16:37:14 +01:00
|
|
|
} else {
|
2019-02-27 10:32:34 +01:00
|
|
|
$panierContents = $this->getPanierContentPublished($panier);
|
2025-04-03 09:30:16 +02:00
|
|
|
$coupons = array();
|
2019-02-13 16:37:14 +01:00
|
|
|
foreach ($panierContents as $panierContent) {
|
2025-04-03 09:30:16 +02:00
|
|
|
$cp = Coupon::where(['coupon_id' => $panierContent->panier_content_couponId])->first();
|
2019-02-13 16:37:14 +01:00
|
|
|
$qty = $panierContent->panier_content_quantity;
|
2021-04-27 17:29:47 +02:00
|
|
|
for ($i = 0; $i < $qty; $i++) {
|
2019-03-12 12:30:11 +01:00
|
|
|
$coupons[] = $cp;
|
2019-02-13 16:37:14 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
session()->put('coupons', $coupons);
|
2019-05-06 10:33:32 +02:00
|
|
|
return view('landings::' . $panier->panier_campId . '.index')
|
2021-04-27 17:29:47 +02:00
|
|
|
->with(['ref' => $panier->panier_campId, 'coupons' => $coupons, 'contact' => $contact, 'nb' => $panierCouponsCount]);
|
2019-01-29 12:26:00 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-13 16:37:14 +01:00
|
|
|
public function printPanierSelect(Request $request)
|
2019-01-29 12:26:00 +01:00
|
|
|
{
|
2021-04-27 17:29:47 +02:00
|
|
|
if (isset($request->coupons)) {
|
2019-02-13 16:37:14 +01:00
|
|
|
session()->put('coupons', $request->coupons);
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-31 14:37:33 +02:00
|
|
|
$coupons = session('coupons', []);
|
|
|
|
|
|
2021-04-27 17:29:47 +02:00
|
|
|
if ($request->session()->has('campagne')) {
|
|
|
|
|
$campagne = $request->session()->get('campagne');
|
|
|
|
|
}
|
2019-02-13 16:37:14 +01:00
|
|
|
|
|
|
|
|
$ref = $campagne->camp_id;
|
|
|
|
|
|
2019-05-06 10:33:32 +02:00
|
|
|
return view('landings::' . $ref . '.imprimer')
|
2021-04-27 17:29:47 +02:00
|
|
|
->with(['ref' => $ref, 'coupons' => $coupons, 'contact' => $request->session()->get('contact')]);
|
2019-01-15 14:17:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function showBasket(Request $request)
|
|
|
|
|
{
|
2019-01-29 12:26:00 +01:00
|
|
|
// ---- Contrôle des paramètres
|
2021-04-27 17:29:47 +02:00
|
|
|
if (isset($request->basketid) && $request->basketid != "") {
|
|
|
|
|
$basketid = $request->basketid;
|
|
|
|
|
} else {
|
2025-08-05 14:47:02 +02:00
|
|
|
return response()->json([
|
2021-04-27 17:29:47 +02:00
|
|
|
'Statut' => 'KO',
|
|
|
|
|
'Code' => 106,
|
|
|
|
|
'Message' => 'Le panier n\'existe pas'
|
|
|
|
|
]);
|
|
|
|
|
}
|
2019-01-29 12:26:00 +01:00
|
|
|
|
2021-04-27 17:29:47 +02:00
|
|
|
$panier = Panier::where('panier_ref', $basketid)->first();
|
|
|
|
|
if (!$panier) {
|
2025-08-05 14:47:02 +02:00
|
|
|
return response()->json([
|
2021-04-27 17:29:47 +02:00
|
|
|
'Statut' => 'KO',
|
|
|
|
|
'Code' => 106,
|
|
|
|
|
'Message' => 'Le panier n\'existe pas'
|
|
|
|
|
]);
|
|
|
|
|
}
|
2019-01-29 12:26:00 +01:00
|
|
|
|
2021-04-27 17:29:47 +02:00
|
|
|
if ($panier->panier_pending == 1) {
|
|
|
|
|
$encours = "oui";
|
|
|
|
|
} else {
|
|
|
|
|
$encours = "non";
|
|
|
|
|
}
|
2019-01-29 12:26:00 +01:00
|
|
|
|
|
|
|
|
$contact = $panier->contact()->where(['contact_id' => $panier->panier_contactId])->first();
|
2021-04-27 17:29:47 +02:00
|
|
|
if (!$contact) {
|
2025-08-05 14:47:02 +02:00
|
|
|
return response()->json([
|
2021-04-27 17:29:47 +02:00
|
|
|
'Statut' => 'KO',
|
|
|
|
|
'Code' => 104,
|
|
|
|
|
'Message' => 'Le contact n\'existe pas'
|
|
|
|
|
]);
|
|
|
|
|
}
|
2019-01-29 12:26:00 +01:00
|
|
|
|
|
|
|
|
$campagne = $panier->campagne()->where(['camp_id' => $panier->panier_campId])->first();
|
2021-04-27 17:29:47 +02:00
|
|
|
if (!$campagne) {
|
2025-08-05 14:47:02 +02:00
|
|
|
return response()->json([
|
2021-04-27 17:29:47 +02:00
|
|
|
'Statut' => 'KO',
|
|
|
|
|
'Code' => 103,
|
|
|
|
|
'Message' => 'La campagne n\'existe pas'
|
|
|
|
|
]);
|
|
|
|
|
}
|
2019-01-29 12:26:00 +01:00
|
|
|
|
2021-04-27 17:29:47 +02:00
|
|
|
$site = $campagne->site()->first();
|
|
|
|
|
if ($site === null) {
|
2025-08-05 14:47:02 +02:00
|
|
|
return response()->json([
|
2021-04-27 17:29:47 +02:00
|
|
|
'Statut' => 'KO',
|
|
|
|
|
'Code' => 102,
|
|
|
|
|
'Message' => 'Le site n\'existe pas'
|
|
|
|
|
]);
|
|
|
|
|
}
|
2019-01-29 12:26:00 +01:00
|
|
|
|
|
|
|
|
$allPanierContent = $panier->panierContents()->get();
|
2021-04-27 17:29:47 +02:00
|
|
|
if ($allPanierContent->count() == 0) {
|
2025-08-05 14:47:02 +02:00
|
|
|
return response()->json([
|
2021-04-27 17:29:47 +02:00
|
|
|
'Statut' => 'KO',
|
|
|
|
|
'Code' => 108,
|
|
|
|
|
'Message' => 'Le panier n\'a pas de coupons liés'
|
|
|
|
|
]);
|
|
|
|
|
}
|
2019-01-29 12:26:00 +01:00
|
|
|
|
2025-04-03 09:30:16 +02:00
|
|
|
$response = new \stdClass();
|
|
|
|
|
$response->Site = $site->site_nom . " (" . $site->site_id . ")";
|
|
|
|
|
$response->Campagne = $campagne->camp_name . " (" . $campagne->camp_id . ")";
|
|
|
|
|
$response->Panier = $panier->panier_ref;
|
2019-01-29 12:26:00 +01:00
|
|
|
$response->DateCreation = date("d/m/Y", strtotime($panier->panier_createdate));
|
2025-04-03 09:30:16 +02:00
|
|
|
$response->EnCours = $encours;
|
|
|
|
|
$response->Nom = $contact->contact_nom;
|
|
|
|
|
$response->Prenom = $contact->contact_prenom;
|
|
|
|
|
$response->Email = $contact->contact_email;
|
|
|
|
|
$response->CodePostal = $contact->contact_cp;
|
|
|
|
|
$response->Commune = $contact->contact_ville;
|
|
|
|
|
$panCont = [];
|
2021-04-27 17:29:47 +02:00
|
|
|
foreach ($allPanierContent as $panierContent) {
|
|
|
|
|
$coupon = Coupon::where(['coupon_id' => $panierContent->panier_content_couponId])->first();
|
|
|
|
|
if ($coupon) {
|
|
|
|
|
array_push($panCont, $coupon->coupon_code . " - " . $coupon->coupon_name . " (x" . $panierContent->panier_content_quantity . ")");
|
2019-01-29 12:26:00 +01:00
|
|
|
}
|
2021-04-27 17:29:47 +02:00
|
|
|
}
|
2019-01-29 12:26:00 +01:00
|
|
|
|
2021-04-27 17:29:47 +02:00
|
|
|
$response->panierContent = $panCont;
|
2019-01-29 12:26:00 +01:00
|
|
|
|
2025-08-05 14:47:02 +02:00
|
|
|
return response()->json([
|
2019-01-29 12:26:00 +01:00
|
|
|
'Statut' => 'OK',
|
|
|
|
|
'Informations Panier' => $response
|
|
|
|
|
]);
|
2019-01-15 14:17:15 +01:00
|
|
|
}
|
|
|
|
|
}
|