Compare commits
151 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3c7af56770 | ||
|
|
74ce43b556 | ||
|
|
a7226f8319 | ||
|
|
f4ce662e8f | ||
|
|
c8953e4e4a | ||
|
|
6ade3c6578 | ||
|
|
6ec164d39a | ||
|
|
df7768f424 | ||
|
|
7ebefee1c4 | ||
|
|
1fd7b6f692 | ||
|
|
c62537a087 | ||
|
|
6203647673 | ||
|
|
8483c63838 | ||
|
|
a737011ae3 | ||
|
|
07b326e62a | ||
|
|
d36b936467 | ||
|
|
0db1b77bf6 | ||
|
|
a63aaf2f83 | ||
|
|
09a71342f0 | ||
|
|
9114af5e19 | ||
|
|
7c41c0eed6 | ||
|
|
43d796ece3 | ||
|
|
f2c4f1c165 | ||
|
|
d9930b07d1 | ||
|
|
56b4dd8da9 | ||
|
|
cf908781bd | ||
|
|
e7f89589a4 | ||
|
|
58df06a543 | ||
|
|
7c2c6c3e7d | ||
|
|
401e17d0fb | ||
|
|
880611e90a | ||
|
|
c5b8608842 | ||
|
|
e8a68e04d5 | ||
|
|
6875bca736 | ||
|
|
e5a50e41a4 | ||
|
|
019c03ccb5 | ||
|
|
92264fc329 | ||
|
|
81508c376f | ||
|
|
3c1245b66b | ||
|
|
695b2b766c | ||
|
|
f7c028fd1b | ||
|
|
8a230d897b | ||
|
|
8280ee5458 | ||
|
|
0d6fb4b999 | ||
|
|
9e2fe9cc73 | ||
|
|
d9dffadb1f | ||
|
|
0b0ce21efd | ||
|
|
f2423adbc0 | ||
|
|
f15a272093 | ||
|
|
7d4381de19 | ||
|
|
5e41e3668e | ||
|
|
b7f111123f | ||
|
|
58eca4167a | ||
|
|
40f90c6422 | ||
|
|
967edc9f07 | ||
|
|
a077d5e89a | ||
|
|
c0a33ef2ab | ||
|
|
f542100fca | ||
|
|
e9fa15d0f8 | ||
|
|
0bed498489 | ||
|
|
2485d0aa97 | ||
|
|
c08c0e8fcd | ||
|
|
634423322d | ||
|
|
cb343969c4 | ||
|
|
e5e6d2bee8 | ||
|
|
656b9e3b3a | ||
|
|
d4fcdc8df0 | ||
|
|
1aa7c5eb59 | ||
|
|
0c5eeff0d4 | ||
|
|
1fd8f3bd35 | ||
|
|
0da72e56bf | ||
|
|
c6186b725a | ||
|
|
f2f8c37069 | ||
|
|
4cca7dea5e | ||
|
|
7b18169f0d | ||
|
|
15118238ea | ||
|
|
8347a12f68 | ||
|
|
64118d03b0 | ||
|
|
b6dc00cba1 | ||
|
|
237ff2af03 | ||
|
|
dedb1cbd55 | ||
|
|
b3a7f6043f | ||
|
|
22bb989ed6 | ||
|
|
cfd7b828da | ||
|
|
94a4e04b50 | ||
|
|
db2da3543d | ||
|
|
62e0a471aa | ||
|
|
0f8c0e31ee | ||
|
|
e7211d40da | ||
|
|
9a5d8aa4f7 | ||
|
|
d90b83ec92 | ||
|
|
6efafddeb1 | ||
|
|
9d711289d3 | ||
|
|
619a859677 | ||
|
|
0d5fbfccb6 | ||
|
|
1430fc21ae | ||
|
|
a853cebf8a | ||
|
|
f323892705 | ||
|
|
b952401a41 | ||
|
|
639f24e1cc | ||
|
|
fd9849321e | ||
|
|
0e64a0715a | ||
|
|
a2d55c47db | ||
|
|
054c049681 | ||
|
|
b8568197be | ||
|
|
cec74c9933 | ||
|
|
b7f42fc518 | ||
|
|
0d648778ae | ||
|
|
f4333b0e59 | ||
|
|
da005cdf5c | ||
|
|
4ebbd47982 | ||
|
|
9838f48c36 | ||
|
|
e3a51051f0 | ||
|
|
30d79ccccd | ||
|
|
4b9f390069 | ||
|
|
fedb14c16d | ||
|
|
ff0ca3db34 | ||
|
|
9fac9bb8b4 | ||
|
|
5662dd8eec | ||
|
|
0145fb5fcb | ||
|
|
5a5650e557 | ||
|
|
6efc47a75d | ||
|
|
5cf4fad381 | ||
|
|
e0075ab68c | ||
|
|
715c83f9fc | ||
|
|
5f2158eba7 | ||
|
|
f2ade79840 | ||
|
|
809583b9f9 | ||
|
|
427517b656 | ||
|
|
203922849c | ||
|
|
d4dd48c37c | ||
|
|
00e6d07482 | ||
|
|
4d4dddbb1a | ||
|
|
3c75e8406c | ||
|
|
46283a72ad | ||
|
|
2c18c6d043 | ||
|
|
fd64145f09 | ||
|
|
f6d552a12a | ||
|
|
1ef1a8c9f0 | ||
|
|
e3936de524 | ||
|
|
0388f911e5 | ||
|
|
abb72d7790 | ||
|
|
c3899725ad | ||
|
|
b6e1c19431 | ||
|
|
5ba34972ac | ||
|
|
7017ffaf42 | ||
|
|
30df92ab01 | ||
|
|
2d089c9978 | ||
|
|
78cb582ed5 | ||
|
|
5a6b3b45ea | ||
|
|
c75c880526 |
320 changed files with 26947 additions and 45454 deletions
12
.dockerignore
Normal file
12
.dockerignore
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
.git
|
||||||
|
*.md
|
||||||
|
node_modules/
|
||||||
|
npm-debug.log
|
||||||
|
.npmrc
|
||||||
|
tests/
|
||||||
|
Dockerfile*
|
||||||
|
.dockerignore
|
||||||
|
.gitignore
|
||||||
|
LICENSE
|
||||||
|
.vscode
|
||||||
|
auth.json
|
||||||
12
.env.example
12
.env.example
|
|
@ -7,7 +7,7 @@ APP_URL=http://localhost
|
||||||
LOG_CHANNEL=stack
|
LOG_CHANNEL=stack
|
||||||
|
|
||||||
DB_CONNECTION=mysql
|
DB_CONNECTION=mysql
|
||||||
DB_HOST=127.0.0.1
|
DB_HOST=dev-mysql
|
||||||
DB_PORT=3306
|
DB_PORT=3306
|
||||||
DB_DATABASE=homestead
|
DB_DATABASE=homestead
|
||||||
DB_USERNAME=homestead
|
DB_USERNAME=homestead
|
||||||
|
|
@ -20,10 +20,16 @@ SESSION_DRIVER=file
|
||||||
SESSION_LIFETIME=120
|
SESSION_LIFETIME=120
|
||||||
|
|
||||||
MAIL_DRIVER=smtp
|
MAIL_DRIVER=smtp
|
||||||
MAIL_HOST=smtp.mailtrap.io
|
MAIL_HOST=dev-mailpit
|
||||||
MAIL_PORT=2525
|
MAIL_PORT=1025
|
||||||
MAIL_USERNAME=null
|
MAIL_USERNAME=null
|
||||||
MAIL_PASSWORD=null
|
MAIL_PASSWORD=null
|
||||||
MAIL_ENCRYPTION=null
|
MAIL_ENCRYPTION=null
|
||||||
|
MAIL_FROM_ADDRESS=
|
||||||
|
MAIL_FROM_NAME=
|
||||||
|
|
||||||
|
# CRM
|
||||||
CRM_ENDPOINT=
|
CRM_ENDPOINT=
|
||||||
|
|
||||||
|
# Sentry
|
||||||
|
SENTRY_LARAVEL_DSN=
|
||||||
|
|
|
||||||
39
.gitignore
vendored
39
.gitignore
vendored
|
|
@ -1,24 +1,37 @@
|
||||||
|
.env
|
||||||
|
.env.backup
|
||||||
|
.env.testing
|
||||||
|
.env.production
|
||||||
|
.phpunit.result.cache
|
||||||
|
.stylelintcache
|
||||||
|
/.fleet
|
||||||
|
/.idea
|
||||||
|
/.phpunit.cache
|
||||||
|
/.vscode
|
||||||
/node_modules
|
/node_modules
|
||||||
|
/bootstrap
|
||||||
|
/public/build
|
||||||
|
/public/cache
|
||||||
/public/hot
|
/public/hot
|
||||||
|
/public/sitemap.xml
|
||||||
/public/storage
|
/public/storage
|
||||||
/public/landings/*
|
|
||||||
!/public/landings/.gitkeep
|
|
||||||
/public/generation/*
|
|
||||||
!/public/generation/.gitkeep
|
|
||||||
/public/export/*
|
/public/export/*
|
||||||
!/public/export/.gitkeep
|
!/public/export/.gitkeep
|
||||||
/public/coupons/*
|
|
||||||
!/public/coupons/.gitkeep
|
|
||||||
/public/images/logos/*
|
|
||||||
!/public/images/logos/.gitkeep
|
|
||||||
/storage/*.key
|
/storage/*.key
|
||||||
/vendor
|
/vendor
|
||||||
/.idea
|
auth.json
|
||||||
/.vscode
|
docker-compose.override.yml
|
||||||
/.vagrant
|
|
||||||
Homestead.json
|
Homestead.json
|
||||||
Homestead.yaml
|
Homestead.yaml
|
||||||
npm-debug.log
|
npm-debug.log
|
||||||
yarn-error.log
|
yarn-error.log
|
||||||
.env
|
.npmrc
|
||||||
.phpunit.result.cache
|
/tests/coverage
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/.npm
|
||||||
|
.zshrc
|
||||||
|
/.composer
|
||||||
|
/public/images/
|
||||||
|
|
|
||||||
23
.gitlab-ci.yml
Normal file
23
.gitlab-ci.yml
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
include:
|
||||||
|
- project: "ldc-web/shared-ci"
|
||||||
|
ref: "main"
|
||||||
|
file: "lint/lint.yml"
|
||||||
|
- project: "ldc-web/shared-ci"
|
||||||
|
ref: "main"
|
||||||
|
file: "security/security.yml"
|
||||||
|
- project: "ldc-web/shared-ci"
|
||||||
|
ref: "main"
|
||||||
|
file: "build/build.yml"
|
||||||
|
- project: "ldc-web/shared-ci"
|
||||||
|
ref: "main"
|
||||||
|
file: "test/test.yml"
|
||||||
|
- project: "ldc-web/shared-ci"
|
||||||
|
ref: "main"
|
||||||
|
file: "deploy/deploy.yml"
|
||||||
|
|
||||||
|
stages:
|
||||||
|
- lint
|
||||||
|
- security
|
||||||
|
- build
|
||||||
|
- test
|
||||||
|
- deploy
|
||||||
24
.gitlab/issue_templates/sprint.md
Normal file
24
.gitlab/issue_templates/sprint.md
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
👤 **Formulation**
|
||||||
|
|
||||||
|
<!-- réferencer des labels avec tilde ~ -->
|
||||||
|
**En tant que** ~"persona:: Marie"
|
||||||
|
|
||||||
|
**Je veux** <!-- action / fonctionnalité souhaitée en utilisant les objets métier entre backticks (ex: `Brand`, `Campaign`) -->
|
||||||
|
|
||||||
|
**Afin de** <!-- bénéfice métier / valeur ajoutée -->
|
||||||
|
|
||||||
|
🎯 **Contexte métier & Objectif**
|
||||||
|
|
||||||
|
<!-- Préciser le contexte métier, les impacts et les règles de gestion principales -->
|
||||||
|
|
||||||
|
🧪 **Critères d'acceptation**
|
||||||
|
|
||||||
|
- [ ] **Scénario :** Cas nominal
|
||||||
|
* **Étant donné** <!-- contexte initial -->
|
||||||
|
* **Quand** <!-- action déclenchée -->
|
||||||
|
* **Alors** <!-- résultat attendu et vérifiable -->
|
||||||
|
|
||||||
|
- [ ] **Scénario :** Cas d'erreur / alternatif
|
||||||
|
* **Étant donné** <!-- contexte limite ou données erronées -->
|
||||||
|
* **Quand** <!-- action déclenchée -->
|
||||||
|
* **Alors** <!-- comportement attendu / blocage / message d'erreur -->
|
||||||
6
Dockerfile
Normal file
6
Dockerfile
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
ARG PHP_8_5_TAG=latest
|
||||||
|
FROM registry.s-web.fr/ldc-web/projets/ldc-web-images-docker/uwil-production-8.5:${PHP_8_5_TAG}
|
||||||
|
COPY --chown=www-data:www-data . /app/srcs
|
||||||
|
USER root
|
||||||
|
RUN chmod -R 755 /app/srcs/storage
|
||||||
|
USER www-data
|
||||||
14
README.md
Normal file
14
README.md
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
# MesBR
|
||||||
|
|
||||||
|
## Tests unitaires
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cp .env .env.testing
|
||||||
|
|
||||||
|
// Update db vars
|
||||||
|
|
||||||
|
php artisan test
|
||||||
|
```
|
||||||
|
|
||||||
|
## Gestion du Legacy
|
||||||
|
Au moment de la suppression du legacy, ne pas oublier de refaire les factory au propre pour les models
|
||||||
51
app/Console/Commands/ArchiveStatsCommand.php
Normal file
51
app/Console/Commands/ArchiveStatsCommand.php
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use App\Jobs\ArchiveStatsJob;
|
||||||
|
use App\Models\ArchiveSite;
|
||||||
|
use App\Models\ArchiveStat;
|
||||||
|
use App\Models\Statistique;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
|
class ArchiveStatsCommand extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected $signature = 'uwil:stats:archive';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected $description = 'Archives mesbr stats';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle(): void
|
||||||
|
{
|
||||||
|
$baseArchiveStatCount = ArchiveStat::count();
|
||||||
|
$baseStatCount = Statistique::count();
|
||||||
|
|
||||||
|
new ArchiveStatsJob()->handle();
|
||||||
|
|
||||||
|
$this->info(sprintf(
|
||||||
|
'%s archive(s) created',
|
||||||
|
ArchiveStat::count() - $baseArchiveStatCount
|
||||||
|
));
|
||||||
|
$this->info(sprintf(
|
||||||
|
'%s stat(s) deleted',
|
||||||
|
$baseStatCount - Statistique::count()
|
||||||
|
));
|
||||||
|
$this->info('Stats archived 👌');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,119 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Console\Commands;
|
|
||||||
|
|
||||||
use App\Campagne;
|
|
||||||
use App\Mail\AlertBr;
|
|
||||||
use App\Mail\AlertBrAdmin;
|
|
||||||
use App\Notification;
|
|
||||||
use App\Site;
|
|
||||||
use App\User;
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
use Illuminate\Support\Facades\Mail;
|
|
||||||
use App\Traits\CouponTrait;
|
|
||||||
|
|
||||||
class CheckAlert extends Command
|
|
||||||
{
|
|
||||||
use CouponTrait;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The name and signature of the console command.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $signature = 'check:alert';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The console command description.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $description = 'Command description';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new command instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the console command.
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
$this->info('Démarrage du traitement');
|
|
||||||
|
|
||||||
$sites = Site::all();
|
|
||||||
$couponSeuilGlobal = array();
|
|
||||||
$couponDiffusionGlobal = array();
|
|
||||||
$sendGlobal = false;
|
|
||||||
foreach ($sites as $site) { // ---- Pour chaque site
|
|
||||||
$campagnes = Campagne::where(['camp_siteId' => $site->site_id])->get();
|
|
||||||
foreach ($campagnes as $campagne) {
|
|
||||||
$sendMail = false;
|
|
||||||
$users = array();
|
|
||||||
$couponSeuil = array();
|
|
||||||
$couponDiffusion = array();
|
|
||||||
$coupons = $campagne->coupons()->get();
|
|
||||||
foreach ($coupons as $coupon) {
|
|
||||||
$couponAlert = false;
|
|
||||||
if ($coupon->coupon_published) {
|
|
||||||
$coupon->coupon_left = $this->getFullQuantity($coupon) - $this->getUsedQuantity($coupon);
|
|
||||||
if ($coupon->coupon_left < $coupon->coupon_seuil_alert) {
|
|
||||||
array_push($couponSeuil, $coupon);
|
|
||||||
array_push($couponSeuilGlobal, [$site->site_nom, $coupon]);
|
|
||||||
$sendGlobal = true;
|
|
||||||
$couponAlert = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- Check MaxDateDiffusion
|
|
||||||
if ($coupon->coupon_maxdatediffusion != null && strtotime($coupon->coupon_maxdatediffusion) < (time() + (30 * 24 * 60 * 60))) { //Fin de diffusion dans moins de 30jours
|
|
||||||
array_push($couponDiffusion, $coupon);
|
|
||||||
array_push($couponDiffusionGlobal, [$site->site_nom, $coupon]);
|
|
||||||
$sendGlobal = true;
|
|
||||||
$couponAlert = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($couponAlert) {
|
|
||||||
$notifications = Notification::where(['notif_campId' => $campagne->camp_id])->get();
|
|
||||||
foreach ($notifications as $notification) {
|
|
||||||
if (!array_key_exists($notification->notif_id, $users)) {
|
|
||||||
$userObject = [];
|
|
||||||
$userObject['email'] = $notification->notif_email;
|
|
||||||
$userObject['name'] = $notification->notif_name;
|
|
||||||
$users[$notification->notif_id] = (object)$userObject;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$sendMail = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($sendMail) {
|
|
||||||
Mail::to($users)->send(new AlertBr($couponSeuil, $couponDiffusion, $site->site_nom));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($sendGlobal) {
|
|
||||||
$this->line("Envoi mail superadmin");
|
|
||||||
$superadmins = array();
|
|
||||||
$admins = User::where(['roles' => 'superadmin'])->get();
|
|
||||||
foreach ($admins as $admin) {
|
|
||||||
$adminObject = [];
|
|
||||||
$adminObject['email'] = $admin->email;
|
|
||||||
$adminObject['name'] = $admin->name;
|
|
||||||
array_push($superadmins, (object)$adminObject);
|
|
||||||
}
|
|
||||||
Mail::to($superadmins)->send(new AlertBrAdmin($couponSeuilGlobal, $couponDiffusionGlobal));
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->line("");
|
|
||||||
$this->info('Fin du traitement');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
123
app/Console/Commands/CustomersClaims.php
Normal file
123
app/Console/Commands/CustomersClaims.php
Normal file
|
|
@ -0,0 +1,123 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use App\Models\Basket;
|
||||||
|
use App\Models\Campagne;
|
||||||
|
use App\Models\Contact;
|
||||||
|
use App\Models\Coupon;
|
||||||
|
use App\Models\Customers;
|
||||||
|
use App\Models\Site;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
|
||||||
|
class CustomersClaims extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected $signature = 'customers:claims {--siteId=?} {destCampaignId} {destCouponId}';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected $description = 'Command description';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new command instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$destCampaignId = $this->argument('destCampaignId');
|
||||||
|
$destCampaign = Campagne::findOrFail($destCampaignId);
|
||||||
|
|
||||||
|
$destCouponId = $this->argument('destCouponId');
|
||||||
|
$destCoupon = Coupon::findOrFail($destCouponId);
|
||||||
|
|
||||||
|
$siteIdArg = $this->option('siteId');
|
||||||
|
if (is_null($siteIdArg)) {
|
||||||
|
$this->table(
|
||||||
|
['ID', 'Site ID', 'Label'],
|
||||||
|
Site::all(['id', 'site_id', 'site_nom'])->toArray()
|
||||||
|
);
|
||||||
|
|
||||||
|
$site = $this->validateInput(fn() => $this->ask('Enter site model id'), 'required|numeric|min:1|max:50|exists:site,id');
|
||||||
|
|
||||||
|
$site = Site::find($site);
|
||||||
|
} else {
|
||||||
|
$site = Site::find($siteIdArg);
|
||||||
|
}
|
||||||
|
|
||||||
|
$email = $this->validateInput(fn() => $this->ask('Enter customer email'), 'required|email|min:1|max:255');
|
||||||
|
|
||||||
|
$crmHashcode = $this->validateInput(fn() => $this->ask('Enter customer hashcode'), 'required|string|min:1|max:36');
|
||||||
|
|
||||||
|
$crmCountry = $this->validateInput(fn() => $this->ask('Enter customer country ISO code'), 'required|numeric|in:56,250,442');
|
||||||
|
|
||||||
|
$date = $this->validateInput(fn() => $this->ask('Enter claim date'), 'required|date_format:d/m/Y');
|
||||||
|
|
||||||
|
$contacts = Contact::where('contact_email', $email)
|
||||||
|
->where('contact_siteId', '=', $site->site_id)
|
||||||
|
->get();
|
||||||
|
|
||||||
|
$toAdd = 0;
|
||||||
|
foreach ($contacts as $contact) {
|
||||||
|
$claimDate = \Illuminate\Support\Facades\Date::createFromFormat('d/m/Y', $date)->format('Y-m-d');
|
||||||
|
// On vient chercher les paniers dont la date de création est >= à la date de la récla
|
||||||
|
$paniers = $contact->paniers()->where('panier_createdate', '>=', $claimDate)->get();
|
||||||
|
foreach ($paniers as $panier) {
|
||||||
|
foreach ($panier->panierContents as $content) {
|
||||||
|
$toAdd += $content->panier_content_printed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$qty = $this->validateInput(fn() => $this->ask('Enter quantity to add', $toAdd), 'required|numeric|max:20');
|
||||||
|
|
||||||
|
$customer = Customers::firstOrNew([
|
||||||
|
'hashcode' => $crmHashcode,
|
||||||
|
'email' => $email,
|
||||||
|
'country' => $crmCountry,
|
||||||
|
]);
|
||||||
|
$customer->saveOrFail();
|
||||||
|
|
||||||
|
$basket = Basket::updateContent($destCampaign, [$destCoupon->coupon_id => $qty], $customer);
|
||||||
|
|
||||||
|
$this->info(url()->route("fo.basket.show", $basket));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function validateInput($method, $rules)
|
||||||
|
{
|
||||||
|
$value = $method(); // Ask user input
|
||||||
|
$validator = Validator::make(['input' => $value], ['input' => $rules]);
|
||||||
|
|
||||||
|
if ($validator->fails()) {
|
||||||
|
foreach ($validator->errors()->all() as $error) {
|
||||||
|
$this->warn($error);
|
||||||
|
}
|
||||||
|
return $this->validateInput($method, $rules); // Retry
|
||||||
|
}
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
58
app/Console/Commands/RegenBRBase.php
Normal file
58
app/Console/Commands/RegenBRBase.php
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use App\Models\Coupon;
|
||||||
|
use App\Traits\GenerateBR;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class RegenBRBase extends Command
|
||||||
|
{
|
||||||
|
use GenerateBR;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected $signature = 'coupons:regen-base';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected $description = 'Re-generate coupons base image';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new command instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$publishedCoupons = Coupon::where('coupon_published', 1)->get();
|
||||||
|
|
||||||
|
foreach ($publishedCoupons as $coupon)
|
||||||
|
{
|
||||||
|
$br_path = $this->generateBase(new Request(), $coupon);
|
||||||
|
$coupon->coupon_image = $br_path;
|
||||||
|
$coupon->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,10 +4,12 @@ namespace App\Console;
|
||||||
|
|
||||||
use Illuminate\Console\Scheduling\Schedule;
|
use Illuminate\Console\Scheduling\Schedule;
|
||||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||||
use App\Site;
|
use App\Models\Site;
|
||||||
use App\Campagne;
|
use App\Models\Campagne;
|
||||||
use App\User;
|
use App\Jobs\ArchiveStatsJob;
|
||||||
use App\Notification;
|
use App\Jobs\CleanOldDatasJob;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Models\Notification;
|
||||||
use App\Mail\AlertBr;
|
use App\Mail\AlertBr;
|
||||||
use App\Mail\AlertBrAdmin;
|
use App\Mail\AlertBrAdmin;
|
||||||
use Illuminate\Support\Facades\Mail;
|
use Illuminate\Support\Facades\Mail;
|
||||||
|
|
@ -23,48 +25,57 @@ class Kernel extends ConsoleKernel
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $commands = [
|
protected $commands = [
|
||||||
//
|
\App\Console\Commands\CustomersClaims::class,
|
||||||
|
\App\Console\Commands\ArchiveStatsCommand::class,
|
||||||
|
\App\Console\Commands\RegenBRBase::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define the application's command schedule.
|
* Define the application's command schedule.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function schedule(Schedule $schedule)
|
protected function schedule(Schedule $schedule)
|
||||||
{
|
{
|
||||||
//---- Commande d'alerte appelé tt les jours de la semaine a 7h00
|
// Archive stats every day at 2:00 AM (to prevent time difference between the server and the reality).
|
||||||
$schedule->call(function () {
|
$schedule->job(ArchiveStatsJob::class)->dailyAt('2:00');
|
||||||
$sites = Site::all();
|
|
||||||
$couponSeuilGlobal = array();
|
// Clean datas older than 3 years every day at midnight.
|
||||||
$couponDiffusionGlobal = array();
|
$schedule->job(CleanOldDatasJob::class)->daily();
|
||||||
$sendGlobal = false;
|
|
||||||
foreach ($sites as $site) { // ---- Pour chaque site
|
// ---- Commande d'alerte appelé tt les jours de la semaine a 7h00
|
||||||
|
$schedule->call(function (): void {
|
||||||
|
$sites = Site::all();
|
||||||
|
$couponSeuilGlobal = [];
|
||||||
|
$couponDiffusionGlobal = [];
|
||||||
|
$sendGlobal = false;
|
||||||
|
foreach ($sites as $site) {
|
||||||
|
// ---- Pour chaque site
|
||||||
$campagnes = Campagne::where(['camp_siteId' => $site->site_id])->get();
|
$campagnes = Campagne::where(['camp_siteId' => $site->site_id])->get();
|
||||||
foreach ($campagnes as $campagne) {
|
foreach ($campagnes as $campagne) {
|
||||||
$sendMail = false;
|
$sendMail = false;
|
||||||
$users = array();
|
$users = [];
|
||||||
$couponSeuil = array();
|
$couponSeuil = [];
|
||||||
$couponDiffusion = array();
|
$couponDiffusion = [];
|
||||||
$coupons = $campagne->coupons()->get();
|
$coupons = $campagne->coupons()->get();
|
||||||
foreach ($coupons as $coupon) {
|
foreach ($coupons as $coupon) {
|
||||||
$couponAlert = false;
|
$couponAlert = false;
|
||||||
if ($coupon->coupon_published) {
|
if ($coupon->coupon_published) {
|
||||||
$coupon->coupon_left = $this->getFullQuantity($coupon) - $this->getUsedQuantity($coupon);
|
$coupon->coupon_left = $this->getFullQuantity($coupon) - $this->getUsedQuantity($coupon);
|
||||||
if ($coupon->coupon_left < $coupon->coupon_seuil_alert) {
|
if ($coupon->coupon_left < $coupon->coupon_seuil_alert) {
|
||||||
array_push($couponSeuil, $coupon);
|
array_push($couponSeuil, $coupon);
|
||||||
array_push($couponSeuilGlobal, [$site->site_nom , $coupon]);
|
array_push($couponSeuilGlobal, [$site->site_nom, $coupon]);
|
||||||
$sendGlobal = true;
|
$sendGlobal = true;
|
||||||
$couponAlert = true;
|
$couponAlert = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Check MaxDateDiffusion
|
// --- Check MaxDateDiffusion
|
||||||
if ($coupon->coupon_maxdatediffusion != null && strtotime($coupon->coupon_maxdatediffusion) < (time() + (30 * 24 * 60 * 60))) {
|
if ($coupon->coupon_maxdatediffusion != null && strtotime($coupon->coupon_maxdatediffusion) < (time() + (30 * 24 * 60 * 60))) {
|
||||||
//Fin de diffusion dans moins de 30jours
|
// Fin de diffusion dans moins de 30jours
|
||||||
array_push($couponDiffusion, $coupon);
|
array_push($couponDiffusion, $coupon);
|
||||||
array_push($couponDiffusionGlobal, [$site->site_nom , $coupon]);
|
array_push($couponDiffusionGlobal, [$site->site_nom, $coupon]);
|
||||||
$sendGlobal = true;
|
$sendGlobal = true;
|
||||||
$couponAlert = true;
|
$couponAlert = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -72,45 +83,33 @@ class Kernel extends ConsoleKernel
|
||||||
$notifications = Notification::where(['notif_campId' => $campagne->camp_id])->get();
|
$notifications = Notification::where(['notif_campId' => $campagne->camp_id])->get();
|
||||||
foreach ($notifications as $notification) {
|
foreach ($notifications as $notification) {
|
||||||
if (!array_key_exists($notification->notif_id, $users)) {
|
if (!array_key_exists($notification->notif_id, $users)) {
|
||||||
$userObject = [];
|
$userObject = [];
|
||||||
$userObject['email'] = $notification->notif_email;
|
$userObject['email'] = $notification->notif_email;
|
||||||
$userObject['name'] = $notification->notif_name;
|
$userObject['name'] = $notification->notif_name;
|
||||||
$users[$notification->notif_id] = (object)$userObject;
|
$users[$notification->notif_id] = (object)$userObject;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$sendMail = true;
|
$sendMail = true;
|
||||||
}
|
}
|
||||||
}
|
} //end if
|
||||||
}
|
} //end foreach
|
||||||
|
|
||||||
if ($sendMail) {
|
if ($sendMail) {
|
||||||
Mail::to($users)->send(new AlertBr($couponSeuil, $couponDiffusion, $site->site_nom));
|
Mail::to($users)->send(new AlertBr($couponSeuil, $couponDiffusion, $site->site_nom));
|
||||||
}
|
}
|
||||||
}
|
} //end foreach
|
||||||
}
|
} //end foreach
|
||||||
if ($sendGlobal) {
|
if ($sendGlobal) {
|
||||||
$superadmins = array();
|
$superadmins = [];
|
||||||
$admins = User::where(['roles' => 'superadmin'])->get();
|
$admins = User::where(['roles' => 'superadmin'])->get();
|
||||||
foreach ($admins as $admin) {
|
foreach ($admins as $admin) {
|
||||||
$adminObject = [];
|
$adminObject = [];
|
||||||
$adminObject['email'] = $admin->email;
|
$adminObject['email'] = $admin->email;
|
||||||
$adminObject['name'] = $admin->name;
|
$adminObject['name'] = $admin->name;
|
||||||
array_push($superadmins, (object)$adminObject);
|
array_push($superadmins, (object)$adminObject);
|
||||||
}
|
}
|
||||||
Mail::to($superadmins)->send(new AlertBrAdmin($couponSeuilGlobal, $couponDiffusionGlobal));
|
Mail::to($superadmins)->send(new AlertBrAdmin($couponSeuilGlobal, $couponDiffusionGlobal));
|
||||||
}
|
}
|
||||||
})->weekdays()->at('7:00');
|
})->weekdays()->at('7:00');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Register the commands for the application.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
protected function commands()
|
|
||||||
{
|
|
||||||
$this->load(__DIR__ . '/Commands');
|
|
||||||
|
|
||||||
require base_path('routes/console.php');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
32
app/Enums/LogActions.php
Normal file
32
app/Enums/LogActions.php
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
use Kwaadpepper\Enum\BaseEnum;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method static self updatebasket()
|
||||||
|
* @method static self impression()
|
||||||
|
* @method static self updatecontact()
|
||||||
|
*/
|
||||||
|
|
||||||
|
class LogActions extends BaseEnum
|
||||||
|
{
|
||||||
|
protected static function values(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'updatebasket' => 1,
|
||||||
|
'impression' => 3,
|
||||||
|
'updatecontact' => 4,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static function labels(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'updatebasket' => 'Mise à jour du panier',
|
||||||
|
'impression' => 'Impression',
|
||||||
|
'updatecontact' => 'Mise à jour du contact',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,47 +4,57 @@ namespace App\Exceptions;
|
||||||
|
|
||||||
use App\Http\Resources\StatusResource;
|
use App\Http\Resources\StatusResource;
|
||||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||||
use Kwaadpepper\ExceptionHandler\Exceptions\ExceptionHandler;
|
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
class Handler extends ExceptionHandler
|
class Handler extends ExceptionHandler
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* A list of exception types with their corresponding custom log levels.
|
||||||
|
*
|
||||||
|
* @var array<class-string<\Throwable>, \Psr\Log\LogLevel::*>
|
||||||
|
*/
|
||||||
|
protected $levels = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A list of the exception types that are not reported.
|
* A list of the exception types that are not reported.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array<int, class-string<\Throwable>>
|
||||||
*/
|
*/
|
||||||
protected $dontReport = [
|
|
||||||
//
|
protected $dontReport = [];
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A list of the inputs that are never flashed for validation exceptions.
|
* A list of the inputs that are never flashed to the session on validation exceptions.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array<int, string>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected $dontFlash = [
|
protected $dontFlash = [
|
||||||
|
'current_password',
|
||||||
'password',
|
'password',
|
||||||
'password_confirmation',
|
'password_confirmation',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Report or log an exception.
|
* Register the exception handling callbacks for the application.
|
||||||
*
|
*
|
||||||
* @param \Throwable $exception
|
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function report(Throwable $exception)
|
public function register()
|
||||||
{
|
{
|
||||||
parent::report($exception);
|
$this->reportable(function (Throwable $e): void {
|
||||||
|
if (app()->bound('sentry')) {
|
||||||
|
resolve('sentry')->captureException($e);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render an exception into an HTTP response.
|
* Render an exception into an HTTP response.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
* @param \Throwable $exception
|
* @param \Throwable $exception
|
||||||
* @return \Symfony\Component\HttpFoundation\Response
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
*/
|
*/
|
||||||
public function render($request, Throwable $exception)
|
public function render($request, Throwable $exception)
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,13 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Coupon;
|
use App\Models\Campagne;
|
||||||
|
use App\Models\Coupon;
|
||||||
use App\Enums\CampaignTypes;
|
use App\Enums\CampaignTypes;
|
||||||
use App\PanierContent;
|
use App\Models\PanierContent;
|
||||||
use App\Statistique;
|
use App\Models\Statistique;
|
||||||
use App\Mur;
|
use App\Models\Mur;
|
||||||
use App\Log;
|
use App\Models\Log;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use App\Traits\GenerateBR;
|
use App\Traits\GenerateBR;
|
||||||
use App\Traits\CouponTrait;
|
use App\Traits\CouponTrait;
|
||||||
|
|
@ -17,11 +18,37 @@ class AjaxController extends Controller
|
||||||
use GenerateBR;
|
use GenerateBR;
|
||||||
use CouponTrait;
|
use CouponTrait;
|
||||||
|
|
||||||
|
// ---- Ajoute des coupons à une campagne
|
||||||
|
public function add_coupons_ajax(Request $request)
|
||||||
|
{
|
||||||
|
$camp_id = $request->input('campid');
|
||||||
|
$campagne = Campagne::where('camp_id', $camp_id)->first();
|
||||||
|
$ids = $request->input('ids');
|
||||||
|
|
||||||
|
$coupons = Coupon::find($ids);
|
||||||
|
$campagne->coupons()->attach($coupons);
|
||||||
|
|
||||||
|
return json_encode($coupons);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- Efface des coupons d'une campagne
|
||||||
|
public function remove_coupons_ajax(Request $request)
|
||||||
|
{
|
||||||
|
$camp_id = $request->input('campid');
|
||||||
|
$campagne = Campagne::where('camp_id', $camp_id)->first();
|
||||||
|
$coupon_id = $request->input('couponid');
|
||||||
|
$coupon = Coupon::find($coupon_id);
|
||||||
|
|
||||||
|
$campagne->coupons()->detach($coupon_id);
|
||||||
|
|
||||||
|
return json_encode($coupon);
|
||||||
|
}
|
||||||
|
|
||||||
// ---- Dépublie un coupon
|
// ---- Dépublie un coupon
|
||||||
public function unpublishCouponsAjax(Request $request)
|
public function unpublishCouponsAjax(Request $request)
|
||||||
{
|
{
|
||||||
$coupon_id = $request->input('couponid');
|
$coupon_id = $request->input('couponid');
|
||||||
$coupon = Coupon::find($coupon_id);
|
$coupon = Coupon::find($coupon_id);
|
||||||
$coupon->coupon_published = 0;
|
$coupon->coupon_published = 0;
|
||||||
$coupon->save();
|
$coupon->save();
|
||||||
|
|
||||||
|
|
@ -31,8 +58,8 @@ class AjaxController extends Controller
|
||||||
// ---- Publie un coupon
|
// ---- Publie un coupon
|
||||||
public function publishCouponsAjax(Request $request)
|
public function publishCouponsAjax(Request $request)
|
||||||
{
|
{
|
||||||
$coupon_id = $request->input('couponid');
|
$coupon_id = $request->input('couponid');
|
||||||
$coupon = Coupon::find($coupon_id);
|
$coupon = Coupon::find($coupon_id);
|
||||||
$coupon->coupon_published = 1;
|
$coupon->coupon_published = 1;
|
||||||
$coupon->save();
|
$coupon->save();
|
||||||
|
|
||||||
|
|
@ -67,53 +94,51 @@ class AjaxController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- INIT du log
|
// ---- INIT du log
|
||||||
$log = new Log();
|
$log = new Log();
|
||||||
$log->log_action = config('constants.impression');
|
$log->log_action = config('constants.impression');
|
||||||
$log->log_source = $source;
|
$log->log_source = $source;
|
||||||
$log->log_contactId = $contact->contact_id;
|
$log->log_contactId = $contact->contact_id;
|
||||||
$log->log_refsite = $campagne->camp_siteId;
|
$log->log_refsite = $campagne->camp_siteId;
|
||||||
$log->log_params = json_encode(['refcamp' => $campagne->camp_id]);
|
$log->log_params = json_encode(['refcamp' => $campagne->camp_id]);
|
||||||
|
|
||||||
$couponsPrinted = array();
|
$couponsPrinted = [];
|
||||||
|
|
||||||
$coupons = '<TABLE width="100%" align="center" cellpadding="0" cellspacing="0" border="0">';
|
$coupons = '<TABLE width="100%" align="center" cellpadding="0" cellspacing="0" border="0">';
|
||||||
$coupons .= '<TR><TD width="100%" align="center"><div>';
|
$coupons .= '<TR><TD width="100%" align="center"><div>';
|
||||||
|
|
||||||
if ($campagne->camp_type->equals(CampaignTypes::mur())) { //---- POUR LES MURS
|
if ($campagne->camp_type->equals(CampaignTypes::mur())) {
|
||||||
|
// ---- POUR LES MURS
|
||||||
if (!isset($couponsToPrint)) {
|
if (!isset($couponsToPrint)) {
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
$nbCoupon = 0;
|
$nbCoupon = 0;
|
||||||
|
|
||||||
foreach ($couponsToPrint as $key => $coupon_code) {
|
foreach ($couponsToPrint as $coupon_code) {
|
||||||
$cp = Coupon::where(['coupon_code' => $coupon_code])->first();
|
$cp = Coupon::where(['coupon_code' => $coupon_code])->first();
|
||||||
|
|
||||||
if ($this->isAvailable($cp, $campagne, $contact) && $this->isAvailableToPrint($cp, $campagne)) {
|
if ($this->isAvailable($cp, $campagne, $contact) && $this->isAvailableToPrint($cp, $campagne)) {
|
||||||
array_push($couponsPrinted, ['cp_code' => $cp->coupon_code, 'qty' => 1]);
|
array_push($couponsPrinted, ['cp_code' => $cp->coupon_code, 'qty' => 1]);
|
||||||
|
|
||||||
$imgCoupon = $this->printCp($cp, $contact);
|
$imgCoupon = $this->printCp($cp, $contact);
|
||||||
$coupons .= '<img src="' . $imgCoupon . '" border="0" style="display:block;width:165mm;"/>';
|
$coupons .= '<img src="' . $imgCoupon . '" border="0" style="display:block;width:165mm;"/>';
|
||||||
$nbCoupon++;
|
$nbCoupon++;
|
||||||
if ($nbCoupon % 3 == 0) {
|
if ($nbCoupon % 3 == 0) {
|
||||||
$coupons .= '</div><div>';
|
$coupons .= '</div><div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
//----- mémorise l'impression
|
// ----- mémorise l'impression
|
||||||
$mur = new Mur();
|
$mur = new Mur();
|
||||||
$mur->mur_campid = $campagne->camp_id;
|
$mur->mur_campid = $campagne->camp_id;
|
||||||
$mur->mur_contactId = $contact->contact_id;
|
$mur->mur_contactId = $contact->contact_id;
|
||||||
$mur->mur_couponId = $cp->coupon_id;
|
$mur->mur_couponId = $cp->coupon_id;
|
||||||
$mur->save();
|
$mur->save();
|
||||||
|
|
||||||
//Sauvegarde de stat
|
// Sauvegarde de stat
|
||||||
$stat = new Statistique();
|
$this->saveStat($campagne, $cp);
|
||||||
$stat->stat_campId = $campagne->camp_id;
|
}//end if
|
||||||
$stat->stat_couponId = $cp->coupon_id;
|
}//end foreach
|
||||||
$stat->stat_couponPrinted = 1;
|
} elseif ($campagne->camp_type->equals(CampaignTypes::panier())) {
|
||||||
$stat->save();
|
// ---- POUR LES PANIERS
|
||||||
}
|
|
||||||
}
|
|
||||||
} elseif ($campagne->camp_type->equals(CampaignTypes::panier())) { //---- POUR LES PANIERS
|
|
||||||
if (!isset($panier)) {
|
if (!isset($panier)) {
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
|
@ -126,7 +151,7 @@ class AjaxController extends Controller
|
||||||
|
|
||||||
foreach ($allPanierContent as $panierContent) {
|
foreach ($allPanierContent as $panierContent) {
|
||||||
$cp = Coupon::where(['coupon_id' => $panierContent->panier_content_couponId])->first();
|
$cp = Coupon::where(['coupon_id' => $panierContent->panier_content_couponId])->first();
|
||||||
if ($cp && $this->isAvailableToPrint($cp, $campagne)) {
|
if ($cp && $this->isAvailableToPrint($cp, $campagne)) {
|
||||||
$imgCoupon = $this->printCp($cp, $contact);
|
$imgCoupon = $this->printCp($cp, $contact);
|
||||||
// ---- Création du html du contenu à imprimer
|
// ---- Création du html du contenu à imprimer
|
||||||
if ($campagne->camp_limitedPrinting == 0) {
|
if ($campagne->camp_limitedPrinting == 0) {
|
||||||
|
|
@ -138,15 +163,11 @@ class AjaxController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$newQtyAvailable = 0;
|
$newQtyAvailable = 0;
|
||||||
$newQtyPrinted = $panierContent->panier_content_quantity + $panierContent->panier_content_printed;
|
$newQtyPrinted = $panierContent->panier_content_quantity + $panierContent->panier_content_printed;
|
||||||
array_push($couponsPrinted, ['cp_code' => $cp->coupon_code, 'qty' => $panierContent->panier_content_quantity]);
|
array_push($couponsPrinted, ['cp_code' => $cp->coupon_code, 'qty' => $panierContent->panier_content_quantity]);
|
||||||
|
|
||||||
//Sauvegarde de stat
|
// Sauvegarde de stat
|
||||||
$stat = new Statistique();
|
$this->saveStat($campagne, $cp);
|
||||||
$stat->stat_campId = $campagne->camp_id;
|
|
||||||
$stat->stat_couponId = $cp->coupon_id;
|
|
||||||
$stat->stat_couponPrinted = $panierContent->panier_content_quantity;
|
|
||||||
$stat->save();
|
|
||||||
} else {
|
} else {
|
||||||
if ($panierContent->panier_content_quantity > 0) {
|
if ($panierContent->panier_content_quantity > 0) {
|
||||||
$coupons .= '<img src="' . $imgCoupon . '" border="0" style="display:block;width:165mm;"/>';
|
$coupons .= '<img src="' . $imgCoupon . '" border="0" style="display:block;width:165mm;"/>';
|
||||||
|
|
@ -155,23 +176,19 @@ class AjaxController extends Controller
|
||||||
$coupons .= '</div><div>';
|
$coupons .= '</div><div>';
|
||||||
}
|
}
|
||||||
$newQtyAvailable = $panierContent->panier_content_quantity - 1;
|
$newQtyAvailable = $panierContent->panier_content_quantity - 1;
|
||||||
$newQtyPrinted = $panierContent->panier_content_printed + 1;
|
$newQtyPrinted = $panierContent->panier_content_printed + 1;
|
||||||
array_push($couponsPrinted, ['cp_code' => $cp->coupon_code, 'qty' => 1]);
|
array_push($couponsPrinted, ['cp_code' => $cp->coupon_code, 'qty' => 1]);
|
||||||
|
|
||||||
//Sauvegarde de stat
|
// Sauvegarde de stat
|
||||||
$stat = new Statistique();
|
$this->saveStat($campagne, $cp);
|
||||||
$stat->stat_campId = $campagne->camp_id;
|
|
||||||
$stat->stat_couponId = $cp->coupon_id;
|
|
||||||
$stat->stat_couponPrinted = 1;
|
|
||||||
$stat->save();
|
|
||||||
}
|
}
|
||||||
}
|
}//end if
|
||||||
// ---- Mémorise l'impression
|
// ---- Mémorise l'impression
|
||||||
$panierContent->panier_content_quantity = $newQtyAvailable;
|
$panierContent->panier_content_quantity = $newQtyAvailable;
|
||||||
$panierContent->panier_content_printed = $newQtyPrinted;
|
$panierContent->panier_content_printed = $newQtyPrinted;
|
||||||
$panierContent->save();
|
$panierContent->save();
|
||||||
}
|
}//end if
|
||||||
}
|
}//end foreach
|
||||||
// ---- Update du status du panier
|
// ---- Update du status du panier
|
||||||
$qty = $panier->panierContents()->sum('panier_content_quantity');
|
$qty = $panier->panierContents()->sum('panier_content_quantity');
|
||||||
if ($qty == 0) {
|
if ($qty == 0) {
|
||||||
|
|
@ -180,37 +197,35 @@ class AjaxController extends Controller
|
||||||
$panier->panier_pending = 1;
|
$panier->panier_pending = 1;
|
||||||
}
|
}
|
||||||
$panier->save();
|
$panier->save();
|
||||||
} elseif ($campagne->camp_type->equals(CampaignTypes::murss())) { //---- POUR LES MURS SANS SELECTION
|
} elseif ($campagne->camp_type->equals(CampaignTypes::murss())) {
|
||||||
|
// ---- POUR LES MURS SANS SELECTION
|
||||||
$nbCoupon = 0;
|
$nbCoupon = 0;
|
||||||
$cps = $campagne->coupons()->get();
|
$cps = $campagne->coupons()->get();
|
||||||
|
|
||||||
foreach ($cps as $cp) {
|
foreach ($cps as $cp) {
|
||||||
// ---- Contrôle si le BR a déjà fait l'objet d'une impression
|
// ---- Contrôle si le BR a déjà fait l'objet d'une impression
|
||||||
if ($this->isAvailable($cp, $campagne, $contact) && $this->isAvailableToPrint($cp, $campagne)) {
|
if ($this->isAvailable($cp, $campagne, $contact) && $this->isAvailableToPrint($cp, $campagne)) {
|
||||||
// ---- Génère l'image du BR à imprimer
|
// ---- Génère l'image du BR à imprimer
|
||||||
$imgCoupon = $this->printCp($cp, $contact);
|
$imgCoupon = $this->printCp($cp, $contact);
|
||||||
$coupons .= '<img src="' . $imgCoupon . '" border="0" style="display:block;width:165mm;"/>';
|
$coupons .= '<img src="' . $imgCoupon . '" border="0" style="display:block;width:165mm;"/>';
|
||||||
$nbCoupon++;
|
$nbCoupon++;
|
||||||
if ($nbCoupon % 3 == 0) {
|
if ($nbCoupon % 3 == 0) {
|
||||||
$coupons .= '</div><div>';
|
$coupons .= '</div><div>';
|
||||||
}
|
}
|
||||||
array_push($couponsPrinted, ['cp_code' => $cp->coupon_code, 'qty' => 1]);
|
array_push($couponsPrinted, ['cp_code' => $cp->coupon_code, 'qty' => 1]);
|
||||||
//----- mémorise l'impression
|
// ----- mémorise l'impression
|
||||||
$mur = new Mur();
|
$mur = new Mur();
|
||||||
$mur->mur_campid = $campagne->camp_id;
|
$mur->mur_campid = $campagne->camp_id;
|
||||||
$mur->mur_contactId = $contact->contact_id;
|
$mur->mur_contactId = $contact->contact_id;
|
||||||
$mur->mur_couponId = $cp->coupon_id;
|
$mur->mur_couponId = $cp->coupon_id;
|
||||||
$mur->save();
|
$mur->save();
|
||||||
|
|
||||||
//Sauvegarde de stat
|
// Sauvegarde de stat
|
||||||
$stat = new Statistique();
|
$this->saveStat($campagne, $cp);
|
||||||
$stat->stat_campId = $campagne->camp_id;
|
}//end if
|
||||||
$stat->stat_couponId = $cp->coupon_id;
|
}//end foreach
|
||||||
$stat->stat_couponPrinted = 1;
|
} elseif ($campagne->camp_type->equals(CampaignTypes::paniers())) {
|
||||||
$stat->save();
|
// ---- POUR LES PANIERS AVEC SELECTION
|
||||||
}
|
|
||||||
}
|
|
||||||
} elseif ($campagne->camp_type->equals(CampaignTypes::paniers())) { //---- POUR LES PANIERS AVEC SELECTION
|
|
||||||
if (!isset($couponsToPrint)) {
|
if (!isset($couponsToPrint)) {
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
|
@ -218,11 +233,11 @@ class AjaxController extends Controller
|
||||||
if (!isset($panier)) {
|
if (!isset($panier)) {
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
foreach ($couponsToPrint as $key => $coupon_code) {
|
foreach ($couponsToPrint as $coupon_code) {
|
||||||
$cp = Coupon::where(['coupon_code' => $coupon_code])->first();
|
$cp = Coupon::where(['coupon_code' => $coupon_code])->first();
|
||||||
|
|
||||||
if ($this->isAvailable($cp, $campagne, $contact) && $this->isAvailableToPrint($cp, $campagne)) {
|
if ($this->isAvailable($cp, $campagne, $contact) && $this->isAvailableToPrint($cp, $campagne)) {
|
||||||
$imgCoupon = $this->printCp($cp, $contact);
|
$imgCoupon = $this->printCp($cp, $contact);
|
||||||
$panierContent = PanierContent::where(['panier_content_couponId' => $cp->coupon_id, 'panier_content_panierId' => $panier->panier_id])->first();
|
$panierContent = PanierContent::where(['panier_content_couponId' => $cp->coupon_id, 'panier_content_panierId' => $panier->panier_id])->first();
|
||||||
if ($panierContent->panier_content_quantity > 0) {
|
if ($panierContent->panier_content_quantity > 0) {
|
||||||
$coupons .= '<img src="' . $imgCoupon . '" border="0" style="display:block;width:165mm;"/>';
|
$coupons .= '<img src="' . $imgCoupon . '" border="0" style="display:block;width:165mm;"/>';
|
||||||
|
|
@ -231,22 +246,19 @@ class AjaxController extends Controller
|
||||||
$coupons .= '</div><div>';
|
$coupons .= '</div><div>';
|
||||||
}
|
}
|
||||||
$newQtyAvailable = $panierContent->panier_content_quantity - 1;
|
$newQtyAvailable = $panierContent->panier_content_quantity - 1;
|
||||||
$newQtyPrinted = $panierContent->panier_content_printed + 1;
|
$newQtyPrinted = $panierContent->panier_content_printed + 1;
|
||||||
|
|
||||||
//Sauvegarde de stat
|
// Sauvegarde de stat
|
||||||
$stat = new Statistique();
|
$this->saveStat($campagne, $cp);
|
||||||
$stat->stat_campId = $campagne->camp_id;
|
|
||||||
$stat->stat_couponId = $cp->coupon_id;
|
// ---- Mémorise l'impression
|
||||||
$stat->stat_couponPrinted = 1;
|
$panierContent->panier_content_quantity = $newQtyAvailable;
|
||||||
$stat->save();
|
$panierContent->panier_content_printed = $newQtyPrinted;
|
||||||
|
$panierContent->save();
|
||||||
}
|
}
|
||||||
array_push($couponsPrinted, ['cp_code' => $cp->coupon_code, 'qty' => 1]);
|
array_push($couponsPrinted, ['cp_code' => $cp->coupon_code, 'qty' => 1]);
|
||||||
// ---- Mémorise l'impression
|
}//end if
|
||||||
$panierContent->panier_content_quantity = $newQtyAvailable;
|
}//end foreach
|
||||||
$panierContent->panier_content_printed = $newQtyPrinted;
|
|
||||||
$panierContent->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// ---- Update du status du panier
|
// ---- Update du status du panier
|
||||||
$qty = $panier->panierContents()->sum('panier_content_quantity');
|
$qty = $panier->panierContents()->sum('panier_content_quantity');
|
||||||
if ($qty == 0) {
|
if ($qty == 0) {
|
||||||
|
|
@ -255,12 +267,12 @@ class AjaxController extends Controller
|
||||||
$panier->panier_pending = 1;
|
$panier->panier_pending = 1;
|
||||||
}
|
}
|
||||||
$panier->save();
|
$panier->save();
|
||||||
}
|
}//end if
|
||||||
|
|
||||||
$coupons .= '</div></TD></TR>';
|
$coupons .= '</div></TD></TR>';
|
||||||
$coupons .= '</TABLE>';
|
$coupons .= '</TABLE>';
|
||||||
|
|
||||||
$log->log_statut = 'OK';
|
$log->log_statut = 'OK';
|
||||||
$log->log_message = json_encode(['Message' => 'Impressions réussies', 'Coupons' => $couponsPrinted], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
$log->log_message = json_encode(['Message' => 'Impressions réussies', 'Coupons' => $couponsPrinted], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||||
$log->save();
|
$log->save();
|
||||||
|
|
||||||
|
|
@ -278,16 +290,7 @@ class AjaxController extends Controller
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->session()->has('contact')) {
|
if ($campagne->camp_type->equals(CampaignTypes::panier()) || $campagne->camp_type->equals(CampaignTypes::paniers())) {
|
||||||
$contact = $request->session()->get('contact');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($campagne->camp_type->equals(CampaignTypes::mur()) || $campagne->camp_type->equals(CampaignTypes::murss())) {
|
|
||||||
if (!isset($contact)) {
|
|
||||||
die();
|
|
||||||
}
|
|
||||||
return redirect(url('/') . '/?refsite=' . $campagne->camp_siteId . '&refcamp=' . $campagne->camp_id . '&hash=' . $contact->contact_hash);
|
|
||||||
} elseif ($campagne->camp_type->equals(CampaignTypes::panier()) || $campagne->camp_type->equals(CampaignTypes::paniers())) {
|
|
||||||
if ($request->session()->has('panier')) {
|
if ($request->session()->has('panier')) {
|
||||||
$panier = $request->session()->get('panier');
|
$panier = $request->session()->get('panier');
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
114
app/Http/Controllers/Api/v0/ContactController.php
Normal file
114
app/Http/Controllers/Api/v0/ContactController.php
Normal file
|
|
@ -0,0 +1,114 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Api\v0;
|
||||||
|
|
||||||
|
use App\Models\Contact;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Models\Site;
|
||||||
|
use App\Traits\CouponTrait;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class ContactController extends Controller
|
||||||
|
{
|
||||||
|
use CouponTrait;
|
||||||
|
|
||||||
|
public function updateContact(Request $request)
|
||||||
|
{
|
||||||
|
// Validation des paramètres requis
|
||||||
|
$requiredFields = [
|
||||||
|
'refadherent' => 'string',
|
||||||
|
'nom' => 'string',
|
||||||
|
'refsite' => 'string',
|
||||||
|
'prenom' => 'string',
|
||||||
|
'email' => 'email',
|
||||||
|
'code_postal' => 'string',
|
||||||
|
'commune' => 'string',
|
||||||
|
];
|
||||||
|
|
||||||
|
$validated = [];
|
||||||
|
foreach ($requiredFields as $field => $type) {
|
||||||
|
$value = $request->input($field);
|
||||||
|
if (empty($value)) {
|
||||||
|
return response()->json([
|
||||||
|
'Statut' => 'KO',
|
||||||
|
'Code' => 101,
|
||||||
|
'Message' => 'Des paramètres de la requête sont mal renseignés ou non présents'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
$validated[$field] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validation spécifique pour l'email
|
||||||
|
if (!filter_var($validated['email'], FILTER_VALIDATE_EMAIL)) {
|
||||||
|
return response()->json([
|
||||||
|
'Statut' => 'KO',
|
||||||
|
'Code' => 101,
|
||||||
|
'Message' => 'L\'email fourni n\'est pas valide'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validation du pays (entier ou par défaut)
|
||||||
|
$pays = $request->input('pays');
|
||||||
|
if ($pays !== null && $pays !== '') {
|
||||||
|
if (!filter_var($pays, FILTER_VALIDATE_INT)) {
|
||||||
|
return response()->json([
|
||||||
|
'Statut' => 'KO',
|
||||||
|
'Code' => 101,
|
||||||
|
'Message' => 'Le pays doit être un entier'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
$validated['pays'] = $pays;
|
||||||
|
} else {
|
||||||
|
$validated['pays'] = 250;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recherche du contact existant
|
||||||
|
$contact = Contact::where([
|
||||||
|
'contact_siteId' => $validated['refsite'],
|
||||||
|
'contact_ref' => $validated['refadherent']
|
||||||
|
])->first();
|
||||||
|
|
||||||
|
// Si le contact n'existe pas, on vérifie le site
|
||||||
|
if (!$contact) {
|
||||||
|
$site = Site::where('site_id', $validated['refsite'])->first();
|
||||||
|
if (!$site) {
|
||||||
|
return response()->json([
|
||||||
|
'Statut' => 'KO',
|
||||||
|
'Code' => 102,
|
||||||
|
'Message' => 'Le site spécifié n\'existe pas'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
$contact = new Contact();
|
||||||
|
$contact->contact_ref = $validated['refadherent'];
|
||||||
|
$contact->contact_siteId = $validated['refsite'];
|
||||||
|
$contact->contact_hash = $request->input('hashcode') ?: strtoupper(md5(uniqid(time(), true)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mise à jour des champs
|
||||||
|
$contact->contact_prenom = $validated['prenom'];
|
||||||
|
$contact->contact_nom = $validated['nom'];
|
||||||
|
$contact->contact_email = $validated['email'];
|
||||||
|
$contact->contact_cp = $validated['code_postal'];
|
||||||
|
$contact->contact_ville = $validated['commune'];
|
||||||
|
$contact->contact_country = $validated['pays'];
|
||||||
|
$contact->contact_updatedate = now();
|
||||||
|
|
||||||
|
if ($request->filled('hashcode')) {
|
||||||
|
$contact->contact_hash = $request->hashcode;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sauvegarde et réponse
|
||||||
|
if ($contact->save()) {
|
||||||
|
return response()->json([
|
||||||
|
'Statut' => 'OK',
|
||||||
|
'contact' => $contact
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'Statut' => 'KO',
|
||||||
|
'Code' => 109,
|
||||||
|
'Message' => 'Une erreur est survenue'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
509
app/Http/Controllers/Api/v0/PanierController.php
Normal file
509
app/Http/Controllers/Api/v0/PanierController.php
Normal file
|
|
@ -0,0 +1,509 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Api\v0;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use App\Models\Panier;
|
||||||
|
use App\Models\Campagne;
|
||||||
|
use App\Models\Coupon;
|
||||||
|
use App\Models\Contact;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Models\Site;
|
||||||
|
use App\Models\Log;
|
||||||
|
use App\Models\PanierContent;
|
||||||
|
use App\Traits\CouponTrait;
|
||||||
|
use App\Traits\ThanksTrait;
|
||||||
|
|
||||||
|
class PanierController extends Controller
|
||||||
|
{
|
||||||
|
use ThanksTrait;
|
||||||
|
use CouponTrait;
|
||||||
|
|
||||||
|
public function updateBasket(Request $request)
|
||||||
|
{
|
||||||
|
if (isset($request->admin)) {
|
||||||
|
$source = 'ADMIN';
|
||||||
|
} else {
|
||||||
|
$source = 'API';
|
||||||
|
}
|
||||||
|
// ---- INIT du log
|
||||||
|
$log = new Log();
|
||||||
|
$log->log_action = config('constants.updatebasket');
|
||||||
|
$log->log_source = $source;
|
||||||
|
|
||||||
|
if (isset($request->basketid)) {
|
||||||
|
$basketid = $request->basketid;
|
||||||
|
if ($basketid != '') {
|
||||||
|
$panier = Panier::where('panier_ref', $basketid)->first();
|
||||||
|
if (!$panier) {
|
||||||
|
$log->log_params = json_encode(['basketid' => $basketid]);
|
||||||
|
$log->log_statut = 'NOK';
|
||||||
|
$log->log_message = "Le panier n'existe pas";
|
||||||
|
$log->save();
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'Statut' => 'KO',
|
||||||
|
'Code' => 106,
|
||||||
|
'Message' => 'Le panier n\'existe pas'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($request->panier) && $request->panier != "") {
|
||||||
|
$panier = $request->panier;
|
||||||
|
$panierTab = explode(",", $panier);
|
||||||
|
$coupons = [];
|
||||||
|
foreach ($panierTab as $panier) {
|
||||||
|
$pos = strpos($panier, ")");
|
||||||
|
if ($pos === false || substr_count($panier, ")") != 1) {
|
||||||
|
$log->log_params = json_encode(['basketid' => $basketid, 'panier' => $panier]);
|
||||||
|
$log->log_statut = 'NOK';
|
||||||
|
$log->log_message = "Des paramètres de la requête sont mal renseignés ou non présents";
|
||||||
|
$log->save();
|
||||||
|
return response()->json([
|
||||||
|
'Statut' => 'KO',
|
||||||
|
'Code' => 101,
|
||||||
|
'Message' => 'Des paramètres de la requête sont mal renseignés ou non présents'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
$quantity = substr($panier, 0, $pos);
|
||||||
|
$quantity = str_replace("(", "", $quantity);
|
||||||
|
$couponCode = substr($panier, $pos + 1);
|
||||||
|
|
||||||
|
if (is_numeric($quantity) && is_numeric($couponCode)) {
|
||||||
|
if (isset($coupons[$couponCode])) {
|
||||||
|
$coupons[$couponCode] = $coupons[$couponCode] + $quantity;
|
||||||
|
} else {
|
||||||
|
$coupons[$couponCode] = $quantity;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$log->log_params = json_encode(['basketid' => $basketid, 'panier' => $panier]);
|
||||||
|
$log->log_statut = 'NOK';
|
||||||
|
$log->log_message = "Des paramètres de la requête sont mal renseignés ou non présents";
|
||||||
|
$log->save();
|
||||||
|
return response()->json([
|
||||||
|
'Statut' => 'KO',
|
||||||
|
'Code' => 101,
|
||||||
|
'Message' => 'Des paramètres de la requête sont mal renseignés ou non présents'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}//end foreach
|
||||||
|
// ---- Préparation message de log avec coupons
|
||||||
|
$panierCoupons = [];
|
||||||
|
foreach ($coupons as $code => $qty) {
|
||||||
|
array_push($panierCoupons, ['cp_code' => $code, 'qty' => $qty]);
|
||||||
|
}
|
||||||
|
if (count($coupons) == 0) {
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$log->log_params = json_encode(['basketid' => $basketid, 'panier' => $panier]);
|
||||||
|
$log->log_statut = 'NOK';
|
||||||
|
$log->log_message = "Des paramètres de la requête sont mal renseignés ou non présents";
|
||||||
|
$log->save();
|
||||||
|
return response()->json([
|
||||||
|
'Statut' => 'KO',
|
||||||
|
'Code' => 101,
|
||||||
|
'Message' => 'Des paramètres de la requête sont mal renseignés ou non présents'
|
||||||
|
]);
|
||||||
|
}//end if
|
||||||
|
|
||||||
|
// ---- MAJ du panier
|
||||||
|
$panier = Panier::where('panier_ref', $basketid)->first();
|
||||||
|
if ($panier) {
|
||||||
|
foreach ($coupons as $couponCode => $quantity) {
|
||||||
|
$cp = Coupon::where('coupon_code', $couponCode)->first();
|
||||||
|
$exists = $cp->campagnes->contains($panier->panier_campId);
|
||||||
|
if ($cp && $exists) {
|
||||||
|
$site = $cp->coupon_siteId;
|
||||||
|
$panierContent = PanierContent::where(['panier_content_panierId' => $panier->panier_id, 'panier_content_couponId' => $cp->coupon_id])->first();
|
||||||
|
if ($panierContent) {
|
||||||
|
$quantity += $panierContent->panier_content_quantity;
|
||||||
|
if ($quantity <= 0) {
|
||||||
|
$quantity = 0;
|
||||||
|
}
|
||||||
|
// MAJ du contenu
|
||||||
|
$panierContent->panier_content_quantity = $quantity;
|
||||||
|
$panierContent->save();
|
||||||
|
} else {
|
||||||
|
// Ajout du contenu
|
||||||
|
if ($quantity > 0) {
|
||||||
|
$panierNewContent = new PanierContent();
|
||||||
|
$panierNewContent->panier_content_panierId = $panier->panier_id;
|
||||||
|
$panierNewContent->panier_content_couponId = $cp->coupon_id;
|
||||||
|
$panierNewContent->panier_content_quantity = $quantity;
|
||||||
|
$panierNewContent->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$log->log_params = json_encode(['refcamp' => $request->refcamp, 'refadherent' => $request->refadherent, 'refsite' => $request->refsite, 'nom' => $request->nom, 'prenom' => $request->prenom, 'email' => $request->email, 'code postal' => $request->code_postal, 'commune' => $request->commune, 'panier' => $request->panier]);
|
||||||
|
$log->log_statut = 'NOK';
|
||||||
|
$log->log_message = "Le coupon ne correspond pas aux coupons liés a la campagne";
|
||||||
|
$log->save();
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'Statut' => 'KO',
|
||||||
|
'Code' => 110,
|
||||||
|
'Message' => 'Le coupon ne correspond pas aux coupons liés a la campagne'
|
||||||
|
]);
|
||||||
|
}//end if
|
||||||
|
}//end foreach
|
||||||
|
// MAJ du status du panier
|
||||||
|
$qty = $panier->panierContents()->sum('panier_content_quantity');
|
||||||
|
if ($qty == 0) {
|
||||||
|
$panier_pending = 0;
|
||||||
|
} else {
|
||||||
|
$panier_pending = 1;
|
||||||
|
}
|
||||||
|
$panier->panier_pending = $panier_pending;
|
||||||
|
$panier->save();
|
||||||
|
|
||||||
|
$campagne = Campagne::where(['camp_id' => $panier->panier_campId])->first();
|
||||||
|
$log->log_refsite = $campagne->camp_siteId;
|
||||||
|
$log->log_contactId = $panier->panier_contactId;
|
||||||
|
$log->log_params = json_encode(['refcamp' => $panier->panier_campId, 'basketid' => $basketid, 'panier' => $panier]);
|
||||||
|
$log->log_statut = 'OK';
|
||||||
|
$log->log_message = json_encode(['Message' => 'Le panier a bien été créé/mis à jour', 'Coupons' => $panierCoupons], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||||
|
$log->save();
|
||||||
|
|
||||||
|
$contact = Contact::where(['contact_id' => $panier->panier_contactId])->first();
|
||||||
|
$site = Site::where(['site_id' => $campagne->camp_siteId])->first();
|
||||||
|
|
||||||
|
if (isset($contact->contact_nom) && isset($site->site_nom)) {
|
||||||
|
if ($panier->panier_pending == 1) {
|
||||||
|
$encours = "oui";
|
||||||
|
} else {
|
||||||
|
$encours = "non";
|
||||||
|
}
|
||||||
|
$response = new \stdClass();
|
||||||
|
$response->Site = $site->site_nom . " (" . $site->site_id . ")";
|
||||||
|
$response->Campagne = $campagne->camp_name . " (" . $campagne->camp_id . ")";
|
||||||
|
$response->Panier = $panier->panier_ref;
|
||||||
|
$response->DateCreation = date("d/m/Y", strtotime($panier->panier_createdate));
|
||||||
|
$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;
|
||||||
|
|
||||||
|
$allPanierContent = $panier->panierContents()->get();
|
||||||
|
foreach ($allPanierContent as $panierContent) {
|
||||||
|
$panCont = [];
|
||||||
|
$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 . ")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$response->panierContent = $panCont;
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'Statut' => 'OK',
|
||||||
|
'Panier' => $response
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
return response()->json([
|
||||||
|
'Statut' => 'OK',
|
||||||
|
'Panier' => $panier
|
||||||
|
]);
|
||||||
|
}//end if
|
||||||
|
} else {
|
||||||
|
$log->log_params = json_encode(['basketid' => $basketid, 'panier' => $panier]);
|
||||||
|
$log->log_statut = 'NOK';
|
||||||
|
$log->log_message = "Le panier n'existe pas";
|
||||||
|
$log->save();
|
||||||
|
return response()->json([
|
||||||
|
'Statut' => 'KO',
|
||||||
|
'Code' => 106,
|
||||||
|
'Message' => 'Le panier n\'existe pas'
|
||||||
|
]);
|
||||||
|
}//end if
|
||||||
|
} else {
|
||||||
|
$log->log_params = json_encode(['basketid' => $basketid, 'panier' => $panier]);
|
||||||
|
$log->log_statut = 'NOK';
|
||||||
|
$log->log_message = "Le panier n'existe pas";
|
||||||
|
$log->save();
|
||||||
|
return response()->json([
|
||||||
|
'Statut' => 'KO',
|
||||||
|
'Code' => 106,
|
||||||
|
'Message' => 'Le panier n\'existe pas'
|
||||||
|
]);
|
||||||
|
}//end if
|
||||||
|
} else {
|
||||||
|
// ---- Contrôle des paramètres
|
||||||
|
$error = false;
|
||||||
|
if (isset($request->refcamp) && $request->refcamp != "") {
|
||||||
|
$refcamp = $request->refcamp;
|
||||||
|
$campagne = Campagne::where(['camp_id' => $refcamp])->first();
|
||||||
|
if (!$campagne || $campagne->camp_published == 0 || ($campagne->camp_type->value != 1 && $campagne->camp_type->value != 3)) {
|
||||||
|
$log->log_params = json_encode(['refcamp' => $refcamp]);
|
||||||
|
$log->log_statut = 'NOK';
|
||||||
|
$log->log_message = "La campagne n'existe pas ou n'est pas un panier";
|
||||||
|
$log->save();
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'Statut' => 'KO',
|
||||||
|
'Code' => 103,
|
||||||
|
'Message' => 'La campagne n\'existe pas ou n\'est pas un panier'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$error = true;
|
||||||
|
}
|
||||||
|
if (isset($request->refadherent) && $request->refadherent != "") {
|
||||||
|
$refadherent = $request->refadherent;
|
||||||
|
} else {
|
||||||
|
$error = true;
|
||||||
|
}
|
||||||
|
if (isset($request->nom) && $request->nom != "") {
|
||||||
|
$nom = $request->nom;
|
||||||
|
} else {
|
||||||
|
$error = true;
|
||||||
|
}
|
||||||
|
if (isset($request->refsite) && $request->refsite != "") {
|
||||||
|
$refsite = $request->refsite;
|
||||||
|
if ($refsite != $campagne->camp_siteId) {
|
||||||
|
return response()->json([
|
||||||
|
'Statut' => 'KO',
|
||||||
|
'Code' => 103,
|
||||||
|
'Message' => 'La campagne ne correspond à aucune campagnes du site'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$error = true;
|
||||||
|
}
|
||||||
|
if (isset($request->prenom) && $request->prenom != "") {
|
||||||
|
$prenom = $request->prenom;
|
||||||
|
} else {
|
||||||
|
$error = true;
|
||||||
|
}
|
||||||
|
if (isset($request->email) && $request->email != "" && filter_var($request->email, FILTER_VALIDATE_EMAIL)) {
|
||||||
|
$email = $request->email;
|
||||||
|
} else {
|
||||||
|
$error = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($request->code_postal) && $request->code_postal != "") {
|
||||||
|
$code_postal = $request->code_postal;
|
||||||
|
} else {
|
||||||
|
$error = true;
|
||||||
|
}
|
||||||
|
if (isset($request->commune) && $request->commune != "") {
|
||||||
|
$commune = $request->commune;
|
||||||
|
} else {
|
||||||
|
$error = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($request->pays) && $request->pays != "") {
|
||||||
|
if (filter_var($request->pays, FILTER_VALIDATE_INT)) {
|
||||||
|
$pays = $request->pays;
|
||||||
|
} else {
|
||||||
|
$error = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$pays = 250;
|
||||||
|
}
|
||||||
|
if (isset($request->panier) && $request->panier != "") {
|
||||||
|
$panier = $request->panier;
|
||||||
|
$panierTab = explode(",", $panier);
|
||||||
|
$coupons = [];
|
||||||
|
foreach ($panierTab as $panier) {
|
||||||
|
$pos = strpos($panier, ")");
|
||||||
|
if ($pos === false) {
|
||||||
|
$error = true;
|
||||||
|
}
|
||||||
|
$quantity = substr($panier, 0, $pos);
|
||||||
|
$quantity = str_replace("(", "", $quantity);
|
||||||
|
$couponCode = substr($panier, $pos + 1);
|
||||||
|
|
||||||
|
if (is_numeric($quantity) && is_numeric($couponCode) && $quantity > 0) {
|
||||||
|
if (isset($coupons[$couponCode])) {
|
||||||
|
$coupons[$couponCode] = $coupons[$couponCode] + $quantity;
|
||||||
|
} else {
|
||||||
|
$coupons[$couponCode] = $quantity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (count($coupons) == 0) {
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$error = true;
|
||||||
|
}//end if
|
||||||
|
|
||||||
|
// ---- Préparation message de log avec coupons
|
||||||
|
if (isset($coupons)) {
|
||||||
|
$panierCoupons = [];
|
||||||
|
foreach ($coupons as $code => $qty) {
|
||||||
|
array_push($panierCoupons, ['cp_code' => $code, 'qty' => $qty]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if ($error) {
|
||||||
|
$log->log_params = json_encode(['refcamp' => $request->refcamp, 'refadherent' => $request->refadherent, 'refsite' => $request->refsite, 'nom' => $request->nom, 'prenom' => $request->prenom, 'email' => $request->email, 'code postal' => $request->code_postal, 'commune' => $request->commune, 'panier' => $request->panier]);
|
||||||
|
$log->log_statut = 'NOK';
|
||||||
|
$log->log_message = "Des paramètres de la requête sont mal renseignés ou non présents";
|
||||||
|
$log->save();
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'Statut' => 'KO',
|
||||||
|
'Code' => 101,
|
||||||
|
'Message' => 'Des paramètres de la requête sont mal renseignés ou non présents'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- Ajout/MAJ du contact
|
||||||
|
$contact = Contact::where(['contact_siteId' => $refsite, 'contact_ref' => $refadherent])->first();
|
||||||
|
if ($contact) {
|
||||||
|
// ---- Mise à jour du contact
|
||||||
|
$contact->contact_prenom = $prenom;
|
||||||
|
$contact->contact_nom = $nom;
|
||||||
|
$contact->contact_email = $email;
|
||||||
|
$contact->contact_cp = $code_postal;
|
||||||
|
$contact->contact_ville = $commune;
|
||||||
|
$contact->contact_country = $pays;
|
||||||
|
$contact->contact_updatedate = date('Y-m-d H:i:s');
|
||||||
|
} else {
|
||||||
|
// ---- Création du contact
|
||||||
|
$site = Site::where('site_id', $refsite)->first();
|
||||||
|
|
||||||
|
if ($site) {
|
||||||
|
$contact = new Contact();
|
||||||
|
$contact->contact_nom = $nom;
|
||||||
|
$contact->contact_prenom = $prenom;
|
||||||
|
$contact->contact_ref = $refadherent;
|
||||||
|
$contact->contact_email = $email;
|
||||||
|
$contact->contact_cp = $code_postal;
|
||||||
|
$contact->contact_ville = $commune;
|
||||||
|
$contact->contact_country = $pays;
|
||||||
|
$contact->contact_siteId = $refsite;
|
||||||
|
$contact->contact_hash = strtoupper(md5(uniqid(time(), true)));
|
||||||
|
} else {
|
||||||
|
$log->log_params = json_encode(['refcamp' => $request->refcamp, 'refadherent' => $request->refadherent, 'refsite' => $request->refsite, 'nom' => $request->nom, 'prenom' => $request->prenom, 'email' => $request->email, 'code postal' => $request->code_postal, 'commune' => $request->commune, 'panier' => $request->panier]);
|
||||||
|
$log->log_statut = 'NOK';
|
||||||
|
$log->log_message = "Le site spécifié n'existe pas";
|
||||||
|
$log->save();
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'Statut' => 'KO',
|
||||||
|
'Code' => 102,
|
||||||
|
'Message' => 'Le site spécifié n\'existe pas'
|
||||||
|
]);
|
||||||
|
}//end if
|
||||||
|
}//end if
|
||||||
|
if (!$contact->save()) {
|
||||||
|
$log->log_params = json_encode(['refcamp' => $request->refcamp, 'refadherent' => $request->refadherent, 'refsite' => $request->refsite, 'nom' => $request->nom, 'prenom' => $request->prenom, 'email' => $request->email, 'code postal' => $request->code_postal, 'commune' => $request->commune, 'panier' => $request->panier]);
|
||||||
|
$log->log_statut = 'NOK';
|
||||||
|
$log->log_message = "Une erreur est survenue";
|
||||||
|
$log->save();
|
||||||
|
return response()->json([
|
||||||
|
'Statut' => 'KO',
|
||||||
|
'Code' => 109,
|
||||||
|
'Message' => 'Une erreur est survenue'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- Ajout/MAJ du panier
|
||||||
|
$panier = Panier::where(['panier_campId' => $refcamp, 'panier_contactId' => $contact->contact_id, 'panier_pending' => 1])->first();
|
||||||
|
if ($panier) {
|
||||||
|
foreach ($coupons as $couponCode => $quantity) {
|
||||||
|
$camp = Campagne::where('camp_id', $panier->panier_campId)->first();
|
||||||
|
$cp = $camp->coupons()->where('coupon_code', $couponCode)->first();
|
||||||
|
if ($cp) {
|
||||||
|
$panierContent = PanierContent::where(['panier_content_panierId' => $panier->panier_id, 'panier_content_couponId' => $cp->coupon_id])->first();
|
||||||
|
if ($panierContent) {
|
||||||
|
// $quantity += $panierContent->panier_content_quantity;
|
||||||
|
$panierContent->panier_content_quantity = $quantity + $panierContent->panier_content_quantity;
|
||||||
|
// MAJ du contenu
|
||||||
|
$panierContent->save();
|
||||||
|
// $panierContent->update(['panier_content_quantity', $quantity]);
|
||||||
|
} else {
|
||||||
|
// Ajout du contenu
|
||||||
|
if ($quantity > 0) {
|
||||||
|
$panierNewContent = new PanierContent();
|
||||||
|
$panierNewContent->panier_content_panierId = $panier->panier_id;
|
||||||
|
$panierNewContent->panier_content_couponId = $cp->coupon_id;
|
||||||
|
$panierNewContent->panier_content_quantity = $quantity;
|
||||||
|
$panierNewContent->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}//end foreach
|
||||||
|
} else {
|
||||||
|
// Ajout du panier et du contenu
|
||||||
|
$panierRef = strtoupper(md5(uniqid(time(), true)));
|
||||||
|
$panier = new Panier();
|
||||||
|
$panier->panier_ref = $panierRef;
|
||||||
|
$panier->panier_campId = $refcamp;
|
||||||
|
$panier->panier_contactId = $contact->contact_id;
|
||||||
|
$panier->panier_createdate = date('Y-m-d H:i:s');
|
||||||
|
$panier->save();
|
||||||
|
|
||||||
|
foreach ($coupons as $couponCode => $quantity) {
|
||||||
|
$cp = $campagne->coupons()->where('coupon_code', $couponCode)->first();
|
||||||
|
if ($cp) {
|
||||||
|
// Ajout du contenu
|
||||||
|
if ($quantity > 0) {
|
||||||
|
$panierNewContent = new PanierContent();
|
||||||
|
$panierNewContent->panier_content_panierId = $panier->panier_id;
|
||||||
|
$panierNewContent->panier_content_couponId = $cp->coupon_id;
|
||||||
|
$panierNewContent->panier_content_quantity = $quantity;
|
||||||
|
$panierNewContent->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}//end if
|
||||||
|
|
||||||
|
$log->log_params = json_encode(['refcamp' => $request->refcamp, 'refadherent' => $request->refadherent, 'refsite' => $request->refsite, 'nom' => $request->nom, 'prenom' => $request->prenom, 'email' => $request->email, 'code postal' => $request->code_postal, 'commune' => $request->commune, 'panier' => $request->panier]);
|
||||||
|
$log->log_contactId = $panier->panier_contactId;
|
||||||
|
$log->log_refsite = $request->refsite;
|
||||||
|
$log->log_statut = 'OK';
|
||||||
|
$log->log_message = json_encode(['Message' => 'Le panier a bien été créé/mis à jour', 'Coupons' => $panierCoupons], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||||
|
$log->save();
|
||||||
|
|
||||||
|
$contact = Contact::where(['contact_id' => $panier->panier_contactId])->first();
|
||||||
|
$site = Site::where(['site_id' => $campagne->camp_siteId])->first();
|
||||||
|
|
||||||
|
if (isset($contact->contact_nom) && isset($site->site_nom)) {
|
||||||
|
if ($panier->panier_pending == 1) {
|
||||||
|
$encours = "oui";
|
||||||
|
} else {
|
||||||
|
$encours = "non";
|
||||||
|
}
|
||||||
|
$response = new \stdClass();
|
||||||
|
$response->Site = $site->site_nom . " (" . $site->site_id . ")";
|
||||||
|
$response->Campagne = $campagne->camp_name . " (" . $campagne->camp_id . ")";
|
||||||
|
$response->Panier = $panier->panier_ref;
|
||||||
|
$response->DateCreation = date("d/m/Y", strtotime($panier->panier_createdate));
|
||||||
|
$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;
|
||||||
|
|
||||||
|
$allPanierContent = $panier->panierContents()->get();
|
||||||
|
$panCont = [];
|
||||||
|
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 . ")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$response->panierContent = $panCont;
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'Statut' => 'OK',
|
||||||
|
'Panier' => $response
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
return response()->json([
|
||||||
|
'Statut' => 'OK',
|
||||||
|
'Panier' => $panier
|
||||||
|
]);
|
||||||
|
}//end if
|
||||||
|
}//end if
|
||||||
|
}
|
||||||
|
}
|
||||||
140
app/Http/Controllers/Api/v1/BasketController.php
Normal file
140
app/Http/Controllers/Api/v1/BasketController.php
Normal file
|
|
@ -0,0 +1,140 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Api\v1;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use App\Models\Campagne;
|
||||||
|
use App\Enums\LogActions;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Models\Basket;
|
||||||
|
use App\Models\Coupon;
|
||||||
|
use App\Models\Customers;
|
||||||
|
use App\Traits\CouponTrait;
|
||||||
|
use App\Traits\ThanksTrait;
|
||||||
|
use App\Traits\LogTrait;
|
||||||
|
|
||||||
|
class BasketController extends Controller
|
||||||
|
{
|
||||||
|
use ThanksTrait, CouponTrait, LogTrait;
|
||||||
|
|
||||||
|
protected $logSource;
|
||||||
|
protected $logAction;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->logAction = LogActions::updatebasket();
|
||||||
|
$this->logSource = 'API';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateBasket(Request $request)
|
||||||
|
{
|
||||||
|
// Validate required parameters
|
||||||
|
$requiredParams = ['customer_hashcode', 'refcamp', 'refsite', 'panier'];
|
||||||
|
$error = array_any($requiredParams, fn($param) => empty($request->{$param}));
|
||||||
|
|
||||||
|
if ($error) {
|
||||||
|
$this->writeLogErrorWrongRequestParameters(
|
||||||
|
$request->refcamp ?? null,
|
||||||
|
$request->customer_hashcode ?? null,
|
||||||
|
$request->refsite ?? null,
|
||||||
|
$request->panier ?? null
|
||||||
|
);
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'Statut' => 'KO',
|
||||||
|
'Code' => 101,
|
||||||
|
'Message' => 'Des paramètres de la requête sont mal renseignés ou non présents'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate campaign
|
||||||
|
$refcamp = $request->refcamp;
|
||||||
|
$campagne = Campagne::where('camp_id', $refcamp)->first();
|
||||||
|
|
||||||
|
if (!$campagne || $campagne->camp_published == 0 || !in_array($campagne->camp_type->value, [1, 3])) {
|
||||||
|
$this->writeLogErrorIncorrectCampaign($refcamp);
|
||||||
|
return response()->json([
|
||||||
|
'Statut' => 'KO',
|
||||||
|
'Code' => 103,
|
||||||
|
'Message' => 'La campagne n\'existe pas ou n\'est pas un panier'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$refsite = $request->refsite;
|
||||||
|
if ($refsite != $campagne->camp_siteId) {
|
||||||
|
return response()->json([
|
||||||
|
'Statut' => 'KO',
|
||||||
|
'Code' => 103,
|
||||||
|
'Message' => 'La campagne ne correspond à aucune campagnes du site'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse panier
|
||||||
|
$panierTab = explode(",", $request->panier);
|
||||||
|
$coupons = [];
|
||||||
|
foreach ($panierTab as $item) {
|
||||||
|
$pos = strpos($item, ")");
|
||||||
|
if ($pos === false) {
|
||||||
|
$error = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$quantity = str_replace("(", "", substr($item, 0, $pos));
|
||||||
|
$couponCode = substr($item, $pos + 1);
|
||||||
|
|
||||||
|
if (is_numeric($quantity) && is_numeric($couponCode) && $quantity > 0) {
|
||||||
|
$coupon = Coupon::where('coupon_code', $couponCode)->first();
|
||||||
|
if (isset($coupons[$coupon->coupon_id])) {
|
||||||
|
$coupons[$coupon->coupon_id] += $quantity;
|
||||||
|
} else {
|
||||||
|
$coupons[$coupon->coupon_id] = $quantity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($coupons)) {
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($error) {
|
||||||
|
$this->writeLogErrorWrongRequestParameters(
|
||||||
|
$refcamp,
|
||||||
|
$request->customer_hashcode,
|
||||||
|
$campagne->camp_siteId,
|
||||||
|
$request->panier
|
||||||
|
);
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'Statut' => 'KO',
|
||||||
|
'Code' => 101,
|
||||||
|
'Message' => 'Des paramètres de la requête sont mal renseignés ou non présents'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepare panierCoupons for logging
|
||||||
|
$panierCoupons = [];
|
||||||
|
foreach ($coupons as $coupon_id => $qty) {
|
||||||
|
$panierCoupons[] = ['coupon_id' => $coupon_id, 'qty' => $qty];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retrieve customer
|
||||||
|
$customer = Customers::where('hashcode', $request->customer_hashcode)->first();
|
||||||
|
|
||||||
|
// Retrieve or create basket
|
||||||
|
$basket = Basket::updateContent($campagne, $coupons, $customer);
|
||||||
|
|
||||||
|
// Log success
|
||||||
|
$this->writeLogSuccessBasketCreated(
|
||||||
|
$refcamp,
|
||||||
|
$request->customer_hashcode,
|
||||||
|
$refsite,
|
||||||
|
$request->panier,
|
||||||
|
$panierCoupons
|
||||||
|
);
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'Statut' => 'OK',
|
||||||
|
'Panier' => $basket
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,19 +2,17 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers\Api\v1;
|
namespace App\Http\Controllers\Api\v1;
|
||||||
|
|
||||||
use App\Campagne;
|
use App\Models\Campagne;
|
||||||
use App\Coupon;
|
use App\Models\Coupon;
|
||||||
use App\Enums\CampaignTypes;
|
use App\Enums\CampaignTypes;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Requests\Coupons\PrintRequest;
|
use App\Http\Requests\Coupons\PrintRequest;
|
||||||
use App\Http\Resources\StatusResource;
|
use App\Http\Resources\StatusResource;
|
||||||
use App\Models\Customers;
|
use App\Models\Customers;
|
||||||
use App\Models\PrintedWalls;
|
|
||||||
use App\Statistique;
|
|
||||||
use App\Traits\CouponTrait;
|
use App\Traits\CouponTrait;
|
||||||
use App\Traits\GenerateBR;
|
use App\Traits\GenerateBR;
|
||||||
use PDF;
|
use PDF;
|
||||||
use LDC\LDCCRM\CrmApiV2;
|
use LDC\LDCCRM\CrmApiV4;
|
||||||
|
|
||||||
class CouponsController extends Controller
|
class CouponsController extends Controller
|
||||||
{
|
{
|
||||||
|
|
@ -23,10 +21,11 @@ class CouponsController extends Controller
|
||||||
|
|
||||||
public function print(PrintRequest $request)
|
public function print(PrintRequest $request)
|
||||||
{
|
{
|
||||||
$datas = $request->validated();
|
$datas = $request->validated();
|
||||||
$campagne = Campagne::find($datas['refcamp']);
|
$campagne = Campagne::find($datas['refcamp']);
|
||||||
$customer = Customers::find($datas['hashcode']);
|
$customer = Customers::find($datas['hashcode']);
|
||||||
$couponsToPrint = explode(",", $datas['coupons']);
|
$couponsToPrint = explode(",", $datas['coupons']);
|
||||||
|
$type = $request->validated()['type'] ?? 'stream';
|
||||||
|
|
||||||
if ($campagne->site->crm_token === null) {
|
if ($campagne->site->crm_token === null) {
|
||||||
return new StatusResource(['status' => 'KO', 'code' => 500, 'message' => 'CRM Token is missing for site_id : ' . $campagne->site->site_id]);
|
return new StatusResource(['status' => 'KO', 'code' => 500, 'message' => 'CRM Token is missing for site_id : ' . $campagne->site->site_id]);
|
||||||
|
|
@ -40,14 +39,14 @@ class CouponsController extends Controller
|
||||||
return new StatusResource(['status' => 'KO', 'code' => 422, 'message' => 'Coupons not found.']);
|
return new StatusResource(['status' => 'KO', 'code' => 422, 'message' => 'Coupons not found.']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$crm = new CrmApiV2(config('crm.CRM_ENDPOINT'), $campagne->site->crm_token, $campagne->site->crm_password);
|
$crm = new CrmApiV4(config('services.crm.endpoint'), $campagne->site->crm_token, $campagne->site->crm_password);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
/**
|
/**
|
||||||
* @var \LDC\LDCCRM\Models\Customer
|
* @var \LDC\LDCCRM\Models\Customer
|
||||||
*/
|
*/
|
||||||
$crmInfos = $crm->getCustomer($customer->hashcode);
|
$crmInfos = $crm->getCustomer($customer->hashcode);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception) {
|
||||||
// TODO : Update error message
|
// TODO : Update error message
|
||||||
return new StatusResource(['status' => 'KO', 'code' => 422, 'message' => 'Customer not found.']);
|
return new StatusResource(['status' => 'KO', 'code' => 422, 'message' => 'Customer not found.']);
|
||||||
}
|
}
|
||||||
|
|
@ -58,33 +57,23 @@ class CouponsController extends Controller
|
||||||
|
|
||||||
// TODO : Vérifier si les coupons sont dans la campagne
|
// TODO : Vérifier si les coupons sont dans la campagne
|
||||||
// TODO : Logs
|
// TODO : Logs
|
||||||
|
|
||||||
$coupons = [];
|
$coupons = [];
|
||||||
if ($campagne->camp_type->equals(CampaignTypes::mur())) { //---- POUR LES MURS
|
if ($campagne->camp_type->equals(CampaignTypes::mur())) {
|
||||||
foreach ($couponsToPrint as $key => $coupon_code) {
|
// ---- POUR LES MURS
|
||||||
|
foreach ($couponsToPrint as $coupon_code) {
|
||||||
$cp = Coupon::where(['coupon_code' => $coupon_code])->first();
|
$cp = Coupon::where(['coupon_code' => $coupon_code])->first();
|
||||||
|
|
||||||
if (!$this->isUsed($cp, $campagne, $customer)) {
|
if (!$this->isUsed($cp, $campagne, $customer)) {
|
||||||
$coupons[] = $this->printCoupon($cp, $customer, $crmInfos);
|
$coupons[] = $this->printCoupon($cp, $customer, $crmInfos, $campagne);
|
||||||
|
|
||||||
//----- mémorise l'impression
|
|
||||||
$mur = new PrintedWalls();
|
|
||||||
$mur->camp_id = $campagne->camp_id;
|
|
||||||
$mur->customer_id = $customer->id;
|
|
||||||
$mur->coupon_id = $cp->coupon_id;
|
|
||||||
$mur->save();
|
|
||||||
|
|
||||||
//Sauvegarde de stat
|
|
||||||
$stat = new Statistique();
|
|
||||||
$stat->stat_campId = $campagne->camp_id;
|
|
||||||
$stat->stat_couponId = $cp->coupon_id;
|
|
||||||
$stat->stat_couponPrinted = 1;
|
|
||||||
$stat->save();
|
|
||||||
}
|
}
|
||||||
}
|
}//end foreach
|
||||||
}
|
}//end if
|
||||||
|
|
||||||
|
// $coupons contains all printed coupons
|
||||||
$pdf = PDF::loadView('pdf.coupons', ['coupons' => $coupons]);
|
$pdf = PDF::loadView('pdf.coupons', ['coupons' => $coupons]);
|
||||||
|
if ($type === 'dl') {
|
||||||
|
return $pdf->download(sprintf("coupons_%s_%s_%s.pdf", $crmInfos->firstname, $crmInfos->lastname, date('d-m-Y')));
|
||||||
|
}
|
||||||
return new StatusResource(['status' => 'OK', 'pdf' => base64_encode($pdf->stream(sprintf("coupons_%s_%s_%s.pdf", $crmInfos->firstname, $crmInfos->lastname, date('d-m-Y'))))]);
|
return new StatusResource(['status' => 'OK', 'pdf' => base64_encode($pdf->stream(sprintf("coupons_%s_%s_%s.pdf", $crmInfos->firstname, $crmInfos->lastname, date('d-m-Y'))))]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,22 +2,26 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers\Api\v1;
|
namespace App\Http\Controllers\Api\v1;
|
||||||
|
|
||||||
use App\Calendrier;
|
use App\Models\Calendrier;
|
||||||
use App\Campagne;
|
use App\Models\Campagne;
|
||||||
|
use App\Enums\CampaignTypes;
|
||||||
use App\Http\Requests\Customers\StoreRequest;
|
use App\Http\Requests\Customers\StoreRequest;
|
||||||
use App\Http\Resources\CustomersResource;
|
use App\Http\Resources\CustomersResource;
|
||||||
use App\Http\Resources\StatusResource;
|
use App\Http\Resources\StatusResource;
|
||||||
use App\Models\Customers;
|
use App\Models\Customers;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\Requests\Customers\BasketRequest;
|
||||||
use App\Http\Requests\Customers\MurRequest;
|
use App\Http\Requests\Customers\MurRequest;
|
||||||
use App\Http\Resources\CouponsResource;
|
use App\Http\Resources\CouponsResource;
|
||||||
use App\Traits\CouponTrait;
|
use App\Traits\CouponTrait;
|
||||||
|
use App\Traits\GenerateBR;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Facades\Request;
|
use Illuminate\Support\Facades\Request;
|
||||||
|
|
||||||
class CustomerController extends Controller
|
class CustomerController extends Controller
|
||||||
{
|
{
|
||||||
use CouponTrait;
|
use CouponTrait;
|
||||||
|
use GenerateBR;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display a listing of the resource.
|
* Display a listing of the resource.
|
||||||
|
|
@ -66,7 +70,7 @@ class CustomerController extends Controller
|
||||||
/**
|
/**
|
||||||
* Display the specified resource.
|
* Display the specified resource.
|
||||||
*
|
*
|
||||||
* @param int $id
|
* @param integer $id
|
||||||
* @return StatusResource
|
* @return StatusResource
|
||||||
*/
|
*/
|
||||||
public function show($id)
|
public function show($id)
|
||||||
|
|
@ -77,7 +81,7 @@ class CustomerController extends Controller
|
||||||
/**
|
/**
|
||||||
* Show the form for editing the specified resource.
|
* Show the form for editing the specified resource.
|
||||||
*
|
*
|
||||||
* @param int $id
|
* @param integer $id
|
||||||
* @return StatusResource
|
* @return StatusResource
|
||||||
*/
|
*/
|
||||||
public function edit($id)
|
public function edit($id)
|
||||||
|
|
@ -99,7 +103,7 @@ class CustomerController extends Controller
|
||||||
/**
|
/**
|
||||||
* Remove the specified resource from storage.
|
* Remove the specified resource from storage.
|
||||||
*
|
*
|
||||||
* @param int $id
|
* @param integer $id
|
||||||
* @return StatusResource
|
* @return StatusResource
|
||||||
*/
|
*/
|
||||||
public function destroy($id)
|
public function destroy($id)
|
||||||
|
|
@ -107,12 +111,22 @@ class CustomerController extends Controller
|
||||||
return new StatusResource(['status' => 'KO', 'code' => '501', 'message' => 'Not Implemented']);
|
return new StatusResource(['status' => 'KO', 'code' => '501', 'message' => 'Not Implemented']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recupere le contenu d'un mur pour une campagne et un user
|
||||||
|
* @param MurRequest $request
|
||||||
|
* @return StatusResource
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
public function mur(MurRequest $request)
|
public function mur(MurRequest $request)
|
||||||
{
|
{
|
||||||
$datas = $request->validated();
|
$datas = $request->validated();
|
||||||
|
|
||||||
$customer = Customers::where('hashcode', $datas['hashcode'])->first();
|
$customer = Customers::where('hashcode', $datas['hashcode'])->first();
|
||||||
$campagne = Campagne::find($datas['refcamp']);
|
$campagne = Campagne::find($datas['refcamp']);
|
||||||
|
|
||||||
|
if (!$campagne->camp_type->equals(CampaignTypes::mur())) {
|
||||||
|
return new StatusResource(['status' => 'KO', 'code' => 404, 'message' => 'Campaign is not mur.']);
|
||||||
|
}
|
||||||
if ($campagne->camp_published === 0) {
|
if ($campagne->camp_published === 0) {
|
||||||
return new StatusResource(['status' => 'KO', 'code' => 404, 'message' => 'Campaign not found.']);
|
return new StatusResource(['status' => 'KO', 'code' => 404, 'message' => 'Campaign not found.']);
|
||||||
}
|
}
|
||||||
|
|
@ -129,7 +143,7 @@ class CustomerController extends Controller
|
||||||
if (!$calendars->isEmpty()) {
|
if (!$calendars->isEmpty()) {
|
||||||
$pub = false;
|
$pub = false;
|
||||||
foreach ($calendars as $calendar) {
|
foreach ($calendars as $calendar) {
|
||||||
if (strtotime(date('Y-m-d H:i:s')) > strtotime($calendar->calendrier_startdate) && strtotime(date('Y-m-d H:i:s')) < strtotime($calendar->calendrier_enddate)) {
|
if ($calendar->isPublished()) {
|
||||||
$pub = true;
|
$pub = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -146,7 +160,7 @@ class CustomerController extends Controller
|
||||||
if (!$coupon->isUsed) {
|
if (!$coupon->isUsed) {
|
||||||
$montantDispo += $coupon->coupon_value;
|
$montantDispo += $coupon->coupon_value;
|
||||||
}
|
}
|
||||||
}
|
}//end foreach
|
||||||
|
|
||||||
return new StatusResource([
|
return new StatusResource([
|
||||||
'status' => "OK",
|
'status' => "OK",
|
||||||
|
|
@ -158,4 +172,79 @@ class CustomerController extends Controller
|
||||||
'coupons' => CouponsResource::collection($coupons)
|
'coupons' => CouponsResource::collection($coupons)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recupere le contenu d'un panier pour une campagne et un user
|
||||||
|
* @param BasketRequest $request
|
||||||
|
* @return StatusResource
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
|
public function basket(BasketRequest $request)
|
||||||
|
{
|
||||||
|
$montantDispo = 0;
|
||||||
|
$montantTotal = 0;
|
||||||
|
$nbCoupons = 0;
|
||||||
|
$couponTotal = 0;
|
||||||
|
$coupons = [];
|
||||||
|
|
||||||
|
$datas = $request->validated();
|
||||||
|
|
||||||
|
$customer = Customers::where('hashcode', $datas['hashcode'])->first();
|
||||||
|
$campagne = Campagne::find($datas['refcamp']);
|
||||||
|
|
||||||
|
if (!$campagne->camp_type->equals(CampaignTypes::panier())) {
|
||||||
|
return new StatusResource(['status' => 'KO', 'code' => 404, 'message' => 'Campaign is not basket.']);
|
||||||
|
}
|
||||||
|
if ($campagne->camp_published === 0) {
|
||||||
|
return new StatusResource(['status' => 'KO', 'code' => 404, 'message' => 'Campaign not found.']);
|
||||||
|
}
|
||||||
|
$basket = $customer->baskets()->where('campagne_id', $campagne->camp_id)->first();
|
||||||
|
if (is_null($basket)) {
|
||||||
|
return new StatusResource(['status' => 'KO', 'code' => 404, 'message' => 'Basket not found.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($basket->contents as $content)
|
||||||
|
{
|
||||||
|
$published = true;
|
||||||
|
$nbCoupons += $content->quantity;
|
||||||
|
$couponTotal += $content->printed;
|
||||||
|
$montantTotal += ($content->coupon->coupon_value * $content->printed);
|
||||||
|
$coupon = $content->coupon()->whereRaw("coupon_published = 1 AND (coupon_mindatediffusion IS NULL OR coupon_mindatediffusion <= NOW()) AND (coupon_maxdatediffusion IS NULL OR coupon_maxdatediffusion >= NOW()) AND (coupon_maxdatevalidity IS NULL OR coupon_maxdatevalidity >= NOW())")->first();
|
||||||
|
if (!is_null($coupon))
|
||||||
|
{
|
||||||
|
// ---- Contrôle des calendriers de diffusion
|
||||||
|
$calendars = Calendrier::where(['calendrier_couponId' => $coupon->coupon_id])->get();
|
||||||
|
if (!$calendars->isEmpty()) {
|
||||||
|
$published = false;
|
||||||
|
foreach ($calendars as $calendar) {
|
||||||
|
if ($calendar->isPublished()) {
|
||||||
|
$published = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($published){
|
||||||
|
$montantDispo += ($coupon->coupon_value * $content->quantity);
|
||||||
|
$montantTotal += ($coupon->coupon_value * $content->quantity);
|
||||||
|
$couponTotal += $content->quantity;
|
||||||
|
$coupons[] = [
|
||||||
|
'quantity' => $content->quantity,
|
||||||
|
'printed' => $content->printed,
|
||||||
|
'coupon' => new CouponsResource($coupon)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new StatusResource([
|
||||||
|
'status' => "OK",
|
||||||
|
'ref' => $basket->uuid,
|
||||||
|
'name' => $campagne->camp_name,
|
||||||
|
'limited_printing' => $campagne->camp_limitedPrinting,
|
||||||
|
'available_coupon' => $nbCoupons,
|
||||||
|
'available_amount' => $montantDispo,
|
||||||
|
'total_coupon' => $couponTotal,
|
||||||
|
'total_amount' => $montantTotal,
|
||||||
|
'coupons' => $coupons
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers\Api\v1;
|
namespace App\Http\Controllers\Api\v1;
|
||||||
|
|
||||||
use App\Calendrier;
|
use App\Models\Calendrier;
|
||||||
use App\Campagne;
|
use App\Models\Campagne;
|
||||||
use App\Enums\CampaignTypes;
|
use App\Enums\CampaignTypes;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Requests\Murs\MursShowRequest;
|
use App\Http\Requests\Murs\MursShowRequest;
|
||||||
|
|
@ -39,7 +39,7 @@ class MurController extends Controller
|
||||||
if (!$calendars->isEmpty()) {
|
if (!$calendars->isEmpty()) {
|
||||||
$pub = false;
|
$pub = false;
|
||||||
foreach ($calendars as $calendar) {
|
foreach ($calendars as $calendar) {
|
||||||
if (strtotime(date('Y-m-d H:i:s')) > strtotime($calendar->calendrier_startdate) && strtotime(date('Y-m-d H:i:s')) < strtotime($calendar->calendrier_enddate)) {
|
if ($calendar->isPublished()) {
|
||||||
$pub = true;
|
$pub = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -53,7 +53,7 @@ class MurController extends Controller
|
||||||
if (!$coupon->isUsed) {
|
if (!$coupon->isUsed) {
|
||||||
$montantDispo += $coupon->coupon_value;
|
$montantDispo += $coupon->coupon_value;
|
||||||
}
|
}
|
||||||
}
|
}//end foreach
|
||||||
|
|
||||||
return new StatusResource([
|
return new StatusResource([
|
||||||
'status' => "OK",
|
'status' => "OK",
|
||||||
|
|
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\Auth;
|
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
|
||||||
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
|
|
||||||
|
|
||||||
class ForgotPasswordController extends Controller
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Password Reset Controller
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
|
|
|
||||||
| This controller is responsible for handling password reset emails and
|
|
||||||
| includes a trait which assists in sending these notifications from
|
|
||||||
| your application to your users. Feel free to explore this trait.
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
use SendsPasswordResetEmails;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new controller instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->middleware('guest');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -7,18 +7,19 @@ use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
||||||
|
|
||||||
class LoginController extends Controller
|
class LoginController extends Controller
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Login Controller
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
|
|
|
||||||
| This controller handles authenticating users for the application and
|
|
||||||
| redirecting them to your home screen. The controller uses a trait
|
|
||||||
| to conveniently provide its functionality to your applications.
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
use AuthenticatesUsers;
|
use AuthenticatesUsers;
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Login Controller
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This controller handles authenticating users for the application and
|
||||||
|
| redirecting them to your home screen. The controller uses a trait
|
||||||
|
| to conveniently provide its functionality to your applications.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Where to redirect users after login.
|
* Where to redirect users after login.
|
||||||
*
|
*
|
||||||
|
|
@ -38,9 +39,11 @@ class LoginController extends Controller
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The user has been authenticated.
|
* The user has been authenticated.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse
|
||||||
*/
|
*/
|
||||||
protected function authenticated()
|
protected function authenticated()
|
||||||
{
|
{
|
||||||
return redirect()->route('home');
|
return redirect('/');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,71 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\Auth;
|
|
||||||
|
|
||||||
use App\User;
|
|
||||||
use App\Http\Controllers\Controller;
|
|
||||||
use Illuminate\Support\Facades\Hash;
|
|
||||||
use Illuminate\Support\Facades\Validator;
|
|
||||||
use Illuminate\Foundation\Auth\RegistersUsers;
|
|
||||||
|
|
||||||
class RegisterController extends Controller
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Register Controller
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
|
|
|
||||||
| This controller handles the registration of new users as well as their
|
|
||||||
| validation and creation. By default this controller uses a trait to
|
|
||||||
| provide this functionality without requiring any additional code.
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
use RegistersUsers;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Where to redirect users after registration.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $redirectTo = '/home';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new controller instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->middleware('guest');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a validator for an incoming registration request.
|
|
||||||
*
|
|
||||||
* @param array $data
|
|
||||||
* @return \Illuminate\Contracts\Validation\Validator
|
|
||||||
*/
|
|
||||||
protected function validator(array $data)
|
|
||||||
{
|
|
||||||
return Validator::make($data, [
|
|
||||||
'name' => 'required|string|max:255',
|
|
||||||
'email' => 'required|string|email|max:255|unique:users',
|
|
||||||
'password' => 'required|string|min:6|confirmed',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new user instance after a valid registration.
|
|
||||||
*
|
|
||||||
* @param array $data
|
|
||||||
* @return \App\User
|
|
||||||
*/
|
|
||||||
protected function create(array $data)
|
|
||||||
{
|
|
||||||
return User::create([
|
|
||||||
'name' => $data['name'],
|
|
||||||
'email' => $data['email'],
|
|
||||||
'password' => Hash::make($data['password']),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\Auth;
|
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
|
||||||
use Illuminate\Foundation\Auth\ResetsPasswords;
|
|
||||||
|
|
||||||
class ResetPasswordController extends Controller
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Password Reset Controller
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
|
|
|
||||||
| This controller is responsible for handling password reset requests
|
|
||||||
| and uses a simple trait to include this behavior. You're free to
|
|
||||||
| explore this trait and override any methods you wish to tweak.
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
use ResetsPasswords;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Where to redirect users after resetting their password.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $redirectTo = '/home';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new controller instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->middleware('guest');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,40 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\Auth;
|
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
|
||||||
use Illuminate\Foundation\Auth\VerifiesEmails;
|
|
||||||
|
|
||||||
class VerificationController extends Controller
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Email Verification Controller
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
|
|
|
||||||
| This controller is responsible for handling email verification for any
|
|
||||||
| user that recently registered with the application. Emails may also
|
|
||||||
| be re-sent if the user didn't receive the original email message.
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
use VerifiesEmails;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Where to redirect users after verification.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $redirectTo = '/home';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new controller instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->middleware('auth');
|
|
||||||
$this->middleware('signed')->only('verify');
|
|
||||||
$this->middleware('throttle:6,1')->only('verify', 'resend');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
29
app/Http/Controllers/Bo/MaintenanceController.php
Normal file
29
app/Http/Controllers/Bo/MaintenanceController.php
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Bo;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Models\Log;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class MaintenanceController extends Controller
|
||||||
|
{
|
||||||
|
public function index(Request $request)
|
||||||
|
{
|
||||||
|
$datas = Log::select(
|
||||||
|
DB::raw("DATE_FORMAT(created_at, '%m/%Y') as month"),
|
||||||
|
DB::raw("COUNT(*) as count")
|
||||||
|
)
|
||||||
|
->where('log_statut', 'NOK')
|
||||||
|
->where('created_at', '>=', \Illuminate\Support\Facades\Date::now()->subMonths(5)->startOfMonth())
|
||||||
|
->groupBy('month')
|
||||||
|
->orderBy('month', 'asc')
|
||||||
|
->get();
|
||||||
|
|
||||||
|
$logs = $datas->toArray();
|
||||||
|
|
||||||
|
return view('bo.maintenance.index', compact('logs'));
|
||||||
|
}
|
||||||
|
}
|
||||||
74
app/Http/Controllers/Bo/UserController.php
Normal file
74
app/Http/Controllers/Bo/UserController.php
Normal file
|
|
@ -0,0 +1,74 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Bo;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\Requests\Bo\Users\DestroyUserRequest;
|
||||||
|
use App\Http\Requests\Bo\Users\StoreUserRequest;
|
||||||
|
use App\Http\Requests\Bo\Users\UpdateUserRequest;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use App\Models\Site;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
|
||||||
|
class UserController extends Controller
|
||||||
|
{
|
||||||
|
public function index(Request $request)
|
||||||
|
{
|
||||||
|
$users = User::all();
|
||||||
|
return view('bo.users.index')->with(['users' => $users, 'logs' => []]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create(Request $request)
|
||||||
|
{
|
||||||
|
$sites = Site::all();
|
||||||
|
return view('bo.users.create', compact('sites'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function store(StoreUserRequest $request)
|
||||||
|
{
|
||||||
|
$user = new User();
|
||||||
|
$user->fill($request->validated());
|
||||||
|
$user->password = Hash::make($request->password);
|
||||||
|
$user->save();
|
||||||
|
|
||||||
|
$sites = Site::whereIn('site_id', $request->site)->get()->pluck('id')->toArray();
|
||||||
|
$user->sites()->sync($sites);
|
||||||
|
|
||||||
|
return to_route('bo.users.edit', $user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function edit(User $user)
|
||||||
|
{
|
||||||
|
$sites = Site::all();
|
||||||
|
$usersites = $user->sites()->get()->pluck('site_id')->toArray();
|
||||||
|
|
||||||
|
return view('bo.users.edit', compact('user', 'sites', 'usersites'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(UpdateUserRequest $request, User $user)
|
||||||
|
{
|
||||||
|
$user->fill($request->validated());
|
||||||
|
$user->save();
|
||||||
|
|
||||||
|
$sites = Site::whereIn('site_id', $request->site)->get()->pluck('id')->toArray();
|
||||||
|
$user->sites()->sync($sites);
|
||||||
|
|
||||||
|
$marques = Auth::user()->sites;
|
||||||
|
$submarques = $marques->map(fn($marque) => $marque->only(['id', 'site_nom', 'site_id', 'site_logo']));
|
||||||
|
session()->put('marques', $submarques);
|
||||||
|
|
||||||
|
return to_route('bo.users.edit', $user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function destroy(DestroyUserRequest $request, User $user)
|
||||||
|
{
|
||||||
|
if ($user->delete()) {
|
||||||
|
return to_route('bo.users.index');
|
||||||
|
} else {
|
||||||
|
session()->flash('delete_nok', 'Erreur lors de la suppression');
|
||||||
|
return view('bo.user.index');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -15,8 +15,8 @@ class BrandChangeController extends Controller
|
||||||
public function __invoke(InvokeBrandChange $request)
|
public function __invoke(InvokeBrandChange $request)
|
||||||
{
|
{
|
||||||
// TODO : Revoir le passage du site
|
// TODO : Revoir le passage du site
|
||||||
$site = \App\Site::find($request->site_id);
|
$site = \App\Models\Site::find($request->site_id);
|
||||||
session()->put('site', $site);
|
session()->put('site', $site);
|
||||||
return redirect()->back();
|
return back();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,27 +2,26 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Campagne;
|
use App\Models\Campagne;
|
||||||
use App\Site;
|
use App\Models\Site;
|
||||||
use App\Coupon;
|
use App\Models\Coupon;
|
||||||
use App\Contact;
|
use App\Models\Contact;
|
||||||
use App\Enums\CampaignTypes;
|
use App\Enums\CampaignTypes;
|
||||||
use App\Http\Requests\Campaign\AddCouponsCampaign;
|
use App\Http\Requests\Campaign\AddCouponsCampaign;
|
||||||
use App\Http\Requests\Campaign\DeleteCampaign;
|
use App\Http\Requests\Campaign\DeleteCampaign;
|
||||||
use App\Http\Requests\Campaign\RemoveCouponCampaign;
|
use App\Http\Requests\Campaign\RemoveCouponCampaign;
|
||||||
|
use App\Http\Requests\Campaign\RemoveNotifCampaign;
|
||||||
|
use App\Http\Requests\Campaign\ShowDemoCampaign;
|
||||||
use App\Http\Requests\Campaign\StoreCampaign;
|
use App\Http\Requests\Campaign\StoreCampaign;
|
||||||
|
use App\Http\Requests\Campaign\StoreNotifCampaign;
|
||||||
use App\Http\Requests\Campaign\UpdateCampaign;
|
use App\Http\Requests\Campaign\UpdateCampaign;
|
||||||
use App\Mur;
|
use App\Models\Mur;
|
||||||
use App\PanierContent;
|
use App\Models\PanierContent;
|
||||||
use App\Notification;
|
use App\Models\Notification;
|
||||||
|
use App\Models\Panier;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\File;
|
use Illuminate\Support\Facades\File;
|
||||||
use App\Traits\CouponTrait;
|
use App\Traits\CouponTrait;
|
||||||
use App\Http\Controllers;
|
|
||||||
use App\Http\Requests\Campaign\RemoveNotifCampaign;
|
|
||||||
use App\Http\Requests\Campaign\ShowDemoCampaign;
|
|
||||||
use App\Http\Requests\Campaign\StoreNotifCampaign;
|
|
||||||
use App\Panier;
|
|
||||||
|
|
||||||
class CampagneController extends Controller
|
class CampagneController extends Controller
|
||||||
{
|
{
|
||||||
|
|
@ -85,7 +84,7 @@ class CampagneController extends Controller
|
||||||
/**
|
/**
|
||||||
* Show the form for editing the specified resource.
|
* Show the form for editing the specified resource.
|
||||||
*
|
*
|
||||||
* @param \App\Campagne $campagne
|
* @param \App\Models\Campagne $campagne
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function edit(Campagne $campagne)
|
public function edit(Campagne $campagne)
|
||||||
|
|
@ -93,7 +92,7 @@ class CampagneController extends Controller
|
||||||
// TODO : Revoir le passage du site id
|
// TODO : Revoir le passage du site id
|
||||||
$siteId = session()->get('site')->id;
|
$siteId = session()->get('site')->id;
|
||||||
|
|
||||||
$couponsNotLinked = Coupon::whereDoesntHave('campagnes', function ($q) use ($campagne) {
|
$couponsNotLinked = Coupon::whereDoesntHave('campagnes', function (\Illuminate\Contracts\Database\Query\Builder $q) use ($campagne): void {
|
||||||
$q->where('campagne_id', $campagne->camp_id);
|
$q->where('campagne_id', $campagne->camp_id);
|
||||||
})->where('coupon_siteId', $siteId)->where('coupon_published', 1)->get();
|
})->where('coupon_siteId', $siteId)->where('coupon_published', 1)->get();
|
||||||
|
|
||||||
|
|
@ -103,8 +102,8 @@ class CampagneController extends Controller
|
||||||
/**
|
/**
|
||||||
* Update the specified resource in storage.
|
* Update the specified resource in storage.
|
||||||
*
|
*
|
||||||
* @param UpdateCampaign $request
|
* @param UpdateCampaign $request
|
||||||
* @param \App\Campagne $campagne
|
* @param \App\Models\Campagne $campagne
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function update(UpdateCampaign $request, Campagne $campagne)
|
public function update(UpdateCampaign $request, Campagne $campagne)
|
||||||
|
|
@ -121,14 +120,14 @@ class CampagneController extends Controller
|
||||||
session()->flash('update_nok', __("Erreur lors de l'enregistrement"));
|
session()->flash('update_nok', __("Erreur lors de l'enregistrement"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect()->route('campagne.edit', ['campagne' => $campagne]);
|
return to_route('campagne.edit', ['campagne' => $campagne]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove the specified resource from storage.
|
* Remove the specified resource from storage.
|
||||||
*
|
*
|
||||||
* @param DeleteCampaign $request
|
* @param DeleteCampaign $request
|
||||||
* @param \App\Campagne $campaign
|
* @param \App\Models\Campagne $campagne
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function destroy(DeleteCampaign $request, Campagne $campagne)
|
public function destroy(DeleteCampaign $request, Campagne $campagne)
|
||||||
|
|
@ -159,7 +158,7 @@ class CampagneController extends Controller
|
||||||
return json_encode($coupon);
|
return json_encode($coupon);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
|
|
@ -170,22 +169,22 @@ class CampagneController extends Controller
|
||||||
$notification->fill(array_merge($request->validated(), ['notif_campId' => $campaign->camp_id]));
|
$notification->fill(array_merge($request->validated(), ['notif_campId' => $campaign->camp_id]));
|
||||||
$notification->save();
|
$notification->save();
|
||||||
|
|
||||||
return redirect()->back();
|
return back();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param RemoveNotifCampaign $request
|
* @param RemoveNotifCampaign $request
|
||||||
* @param \App\Notification $notification
|
* @param \App\Models\Notification $notification
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function deleteNotification(RemoveNotifCampaign $request, Notification $notification)
|
public function deleteNotification(RemoveNotifCampaign $request, Notification $notification)
|
||||||
{
|
{
|
||||||
if ($notification->delete()) {
|
if ($notification->delete()) {
|
||||||
return redirect()->back();
|
return back();
|
||||||
} else {
|
} else {
|
||||||
session()->flash('delete_nok', 'Erreur lors de la suppression');
|
session()->flash('delete_nok', 'Erreur lors de la suppression');
|
||||||
return redirect()->back();
|
return back();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -209,7 +208,7 @@ class CampagneController extends Controller
|
||||||
'pays' => 250
|
'pays' => 250
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$contact = new Controllers\ContactController();
|
$contact = new \App\Http\Controllers\ContactController();
|
||||||
$res = $contact->updateContact($req);
|
$res = $contact->updateContact($req);
|
||||||
$demoContact = Contact::where(['contact_siteId' => $siteId, 'contact_ref' => 'DEMO'])->first();
|
$demoContact = Contact::where(['contact_siteId' => $siteId, 'contact_ref' => 'DEMO'])->first();
|
||||||
}
|
}
|
||||||
|
|
@ -221,7 +220,7 @@ class CampagneController extends Controller
|
||||||
$myRequest->request->add(['refcamp' => $campaign->camp_id, 'refadherent' => 'DEMO', 'admin' => 1]);
|
$myRequest->request->add(['refcamp' => $campaign->camp_id, 'refadherent' => 'DEMO', 'admin' => 1]);
|
||||||
|
|
||||||
// ---- EFFACER LES CONTROLES SI EXISTANT
|
// ---- EFFACER LES CONTROLES SI EXISTANT
|
||||||
$mur = new Controllers\MurController();
|
$mur = new \App\Http\Controllers\MurController();
|
||||||
$res = $mur->deleteControlContact($myRequest);
|
$res = $mur->deleteControlContact($myRequest);
|
||||||
|
|
||||||
// ---- RETOURNE l'URL
|
// ---- RETOURNE l'URL
|
||||||
|
|
@ -295,7 +294,7 @@ class CampagneController extends Controller
|
||||||
|
|
||||||
// ---- Contrôle des paramètres
|
// ---- Contrôle des paramètres
|
||||||
if (isset($request->refcamp) && $request->refcamp != "") {
|
if (isset($request->refcamp) && $request->refcamp != "") {
|
||||||
$refcamp = $request->refcamp;
|
$refcamp = $request->refcamp;
|
||||||
$campagne = Campagne::where(['camp_id' => $refcamp])->first();
|
$campagne = Campagne::where(['camp_id' => $refcamp])->first();
|
||||||
if (!$campagne) {
|
if (!$campagne) {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
|
|
@ -309,7 +308,7 @@ class CampagneController extends Controller
|
||||||
}
|
}
|
||||||
if (isset($request->refsite) && $request->refsite != "") {
|
if (isset($request->refsite) && $request->refsite != "") {
|
||||||
$refsite = $request->refsite;
|
$refsite = $request->refsite;
|
||||||
$site = Site::where(['site_id' => $refsite])->first();
|
$site = Site::where(['site_id' => $refsite])->first();
|
||||||
if (!$site) {
|
if (!$site) {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'Statut' => 'KO',
|
'Statut' => 'KO',
|
||||||
|
|
@ -352,26 +351,25 @@ class CampagneController extends Controller
|
||||||
$type = "panier avec sélection";
|
$type = "panier avec sélection";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$data = array (
|
$data = [
|
||||||
'Site' => $site->site_nom,
|
'Site' => $site->site_nom,
|
||||||
'Ref campagne' => $campagne->camp_id,
|
'Ref campagne' => $campagne->camp_id,
|
||||||
'Nom campagne' => $campagne->camp_name,
|
'Nom campagne' => $campagne->camp_name,
|
||||||
"En ligne" => $enligne,
|
"En ligne" => $enligne,
|
||||||
"Type" => $type,
|
"Type" => $type,
|
||||||
);
|
];
|
||||||
|
|
||||||
|
|
||||||
$coupons = $campagne->coupons()->get();
|
$coupons = $campagne->coupons()->get();
|
||||||
|
|
||||||
if ($coupons->count() > 0) {
|
if ($coupons->count() > 0) {
|
||||||
foreach ($coupons as $coupon) {
|
foreach ($coupons as $coupon) {
|
||||||
//var_dump($coupon->coupon_id);
|
|
||||||
// ---- Calcul du nombre de BR consommé
|
// ---- Calcul du nombre de BR consommé
|
||||||
$diffuseMur = Mur::where(['mur_campId' => $campagne->camp_id, 'mur_couponId' => $coupon->coupon_id])->count();
|
$diffuseMur = Mur::where(['mur_campId' => $campagne->camp_id, 'mur_couponId' => $coupon->coupon_id])->count();
|
||||||
|
|
||||||
$diffusePanier01 = PanierContent::where(['panier_content_couponId' => $coupon->coupon_id])->sum('panier_content_quantity');
|
$diffusePanier01 = PanierContent::where(['panier_content_couponId' => $coupon->coupon_id])->sum('panier_content_quantity');
|
||||||
$diffusePanier02 = PanierContent::where(['panier_content_couponId' => $coupon->coupon_id])->sum('panier_content_printed');
|
$diffusePanier02 = PanierContent::where(['panier_content_couponId' => $coupon->coupon_id])->sum('panier_content_printed');
|
||||||
$diffusePanier = $diffusePanier01 + $diffusePanier02;
|
$diffusePanier = $diffusePanier01 + $diffusePanier02;
|
||||||
|
|
||||||
if (!$diffusePanier) {
|
if (!$diffusePanier) {
|
||||||
$diffusePanier = 0;
|
$diffusePanier = 0;
|
||||||
|
|
@ -395,7 +393,7 @@ class CampagneController extends Controller
|
||||||
$dateFinValidite = date("d/m/Y", strtotime($coupon->coupon_maxdatevalidity));
|
$dateFinValidite = date("d/m/Y", strtotime($coupon->coupon_maxdatevalidity));
|
||||||
}
|
}
|
||||||
|
|
||||||
$codeTraitement = array (
|
$codeTraitement = [
|
||||||
"Code traitement" => $coupon->coupon_code,
|
"Code traitement" => $coupon->coupon_code,
|
||||||
"Nom" => $coupon->coupon_name,
|
"Nom" => $coupon->coupon_name,
|
||||||
"Nb à diffuser" => $this->getFullQuantity($coupon),
|
"Nb à diffuser" => $this->getFullQuantity($coupon),
|
||||||
|
|
@ -405,95 +403,13 @@ class CampagneController extends Controller
|
||||||
"En ligne" => $enligne,
|
"En ligne" => $enligne,
|
||||||
"Date de fin de diffusion" => $dateFinDiffusion,
|
"Date de fin de diffusion" => $dateFinDiffusion,
|
||||||
"Date de fin de validité" => $dateFinValidite,
|
"Date de fin de validité" => $dateFinValidite,
|
||||||
);
|
];
|
||||||
$data['Coupons'][] = $codeTraitement;
|
$data['Coupons'][] = $codeTraitement;
|
||||||
}
|
}//end foreach
|
||||||
}
|
}//end if
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'Statut' => 'OK',
|
'Statut' => 'OK',
|
||||||
'Détails Campagne' => $data
|
'Détails Campagne' => $data
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDiffCamp(Request $request)
|
|
||||||
{
|
|
||||||
$error = false;
|
|
||||||
// ---- Contrôle des paramètres
|
|
||||||
if (isset($request->refcamp) && $request->refcamp != "") {
|
|
||||||
$refcamp = $request->refcamp;
|
|
||||||
$campagne = Campagne::where(['camp_id' => $refcamp])->first();
|
|
||||||
if (!$campagne) {
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'KO',
|
|
||||||
'Code' => 103,
|
|
||||||
'Message' => 'La campagne n\'existe pas'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$error = true;
|
|
||||||
}
|
|
||||||
if (isset($request->refsite) && $request->refsite != "") {
|
|
||||||
$refsite = $request->refsite;
|
|
||||||
$site = Site::where(['site_id' => $refsite])->first();
|
|
||||||
if (!$site) {
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'KO',
|
|
||||||
'Code' => 102,
|
|
||||||
'Message' => 'Le site n\'existe pas'
|
|
||||||
]);
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
$error = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($request->refadherent) && $request->refadherent != "") {
|
|
||||||
$refadherent = $request->refadherent;
|
|
||||||
$contact = Contact::where(['contact_siteId' => $refsite, 'contact_ref' => $refadherent])->first();
|
|
||||||
if (!$contact) {
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'KO',
|
|
||||||
'Code' => 104,
|
|
||||||
'Message' => 'Le contact n\'existe pas'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$error = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($error) {
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'KO',
|
|
||||||
'Code' => 101,
|
|
||||||
'Message' => 'Des paramètres de la requête sont mal renseignés ou non présents'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = array (
|
|
||||||
'Statut' => 'OK',
|
|
||||||
'Site' => $site->site_nom,
|
|
||||||
'Ref campagne' => $campagne->camp_id,
|
|
||||||
'Nom campagne' => $campagne->camp_name,
|
|
||||||
"Ref contact" => $refadherent,
|
|
||||||
"Email contact" => $contact->contact_email,
|
|
||||||
);
|
|
||||||
|
|
||||||
$coupons = $campagne->coupons()->get();
|
|
||||||
|
|
||||||
if ($coupons->count() > 0) {
|
|
||||||
foreach ($coupons as &$coupon) {
|
|
||||||
if ($this->isAvailable($coupon, $campagne, $contact)) {
|
|
||||||
$dispo = 1;
|
|
||||||
} else {
|
|
||||||
$dispo = 0;
|
|
||||||
}
|
|
||||||
$codeTraitement = array (
|
|
||||||
"Code traitement" => $coupon->coupon_code,
|
|
||||||
"Nom" => $coupon->coupon_name,
|
|
||||||
"Nb disponible" => $dispo,
|
|
||||||
);
|
|
||||||
$data['Codes traitement'][] = $codeTraitement;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return response()->json($data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,349 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
|
||||||
|
|
||||||
use App\Contact;
|
|
||||||
use App\Site;
|
|
||||||
use App\Campagne;
|
|
||||||
use App\Enums\CampaignTypes;
|
|
||||||
use App\Http\Requests\Contact\LoadWidgetContact;
|
|
||||||
use App\Http\Requests\Contact\SearchContact;
|
|
||||||
use App\Http\Requests\Contact\StoreContact;
|
|
||||||
use App\Http\Requests\Contact\UpdateContact;
|
|
||||||
use App\Log;
|
|
||||||
use App\Panier;
|
|
||||||
use App\PanierContent;
|
|
||||||
use App\Traits\CouponTrait;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
|
|
||||||
class ContactController extends Controller
|
|
||||||
{
|
|
||||||
use CouponTrait;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display a listing of the resource.
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function index(Request $request)
|
|
||||||
{
|
|
||||||
return view('contact.index')->with('search', false);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function search(SearchContact $request)
|
|
||||||
{
|
|
||||||
session()->put('active_route', 'contact');
|
|
||||||
|
|
||||||
$contacts = Contact::where('contact_siteId', session()->get('site')->site_id)
|
|
||||||
->searchFirstname($request->searchFirstname)
|
|
||||||
->searchName($request->searchName)
|
|
||||||
->searchEmail($request->searchEmail)
|
|
||||||
->searchCp($request->searchCp)
|
|
||||||
->searchVille($request->searchVille)
|
|
||||||
->searchCountry($request->searchCountry)
|
|
||||||
->orderBy('contact_createdate', 'DESC')
|
|
||||||
->paginate(15, ['*'], 'page', $request->page);
|
|
||||||
|
|
||||||
$searchData = array(
|
|
||||||
'name' => $request->searchName,
|
|
||||||
'firstname' => $request->searchFirstname,
|
|
||||||
'email' => $request->searchEmail,
|
|
||||||
'cp' => $request->searchCp,
|
|
||||||
'ville' => $request->searchVille,
|
|
||||||
'pays' => $request->searchCountry
|
|
||||||
);
|
|
||||||
|
|
||||||
return view('contact.index')->with('contacts', $contacts)->with('search', true)->with('searchData', $searchData);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show the form for creating a new resource.
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function create()
|
|
||||||
{
|
|
||||||
return view('contact.create');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Store a newly created resource in storage.
|
|
||||||
*
|
|
||||||
* @param StoreContact $request
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function store(StoreContact $request)
|
|
||||||
{
|
|
||||||
// TODO : Revoir le passage du site
|
|
||||||
$site = session()->get('site');
|
|
||||||
|
|
||||||
$contact = new Contact();
|
|
||||||
$contact->fill($request->validated());
|
|
||||||
$contact->contact_hash = strtoupper(md5(uniqid(time(), true)));
|
|
||||||
$contact->contact_siteId = $site->site_id;
|
|
||||||
$contact->save();
|
|
||||||
|
|
||||||
return redirect()->route('contact.edit', ['contact' => $contact]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show the form for editing the specified resource.
|
|
||||||
*
|
|
||||||
* @param \App\Campagne $campagne
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function edit(Contact $contact)
|
|
||||||
{
|
|
||||||
$campagnes = Campagne::where(['camp_siteId' => $contact->contact_siteId, 'camp_published' => 1])->get();
|
|
||||||
|
|
||||||
return view('contact.edit', ['contact' => $contact, 'campagnes' => $campagnes]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update the specified resource in storage.
|
|
||||||
*
|
|
||||||
* @param UpdateContact $request
|
|
||||||
* @param \App\Contact $contact
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function update(UpdateContact $request, Contact $contact)
|
|
||||||
{
|
|
||||||
$contact->fill($request->validated());
|
|
||||||
if ($contact->save()) {
|
|
||||||
session()->flash('update_ok', __('La campagne a bien été modifiée'));
|
|
||||||
} else {
|
|
||||||
session()->flash('update_nok', "Erreur lors de l'enregistrement");
|
|
||||||
}
|
|
||||||
return redirect()->route('contact.edit', ['contact' => $contact]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove the specified resource from storage.
|
|
||||||
*
|
|
||||||
* @param \App\Contact $contact
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function destroy(Contact $contact)
|
|
||||||
{
|
|
||||||
if ($contact->delete()) {
|
|
||||||
return redirect()->route('contact.index');
|
|
||||||
} else {
|
|
||||||
session()->flash('delete_nok', __('Erreur lors de la suppression'));
|
|
||||||
redirect()->route('contact.edit', ['contact' => $contact]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function updateContact(Request $request)
|
|
||||||
{
|
|
||||||
$error = false;
|
|
||||||
// ---- Contrôle des paramètres
|
|
||||||
if (isset($request->refadherent) && $request->refadherent != "") {
|
|
||||||
$refadherent = $request->refadherent;
|
|
||||||
} else {
|
|
||||||
$error = true;
|
|
||||||
}
|
|
||||||
if (isset($request->nom) && $request->nom != "") {
|
|
||||||
$nom = $request->nom;
|
|
||||||
} else {
|
|
||||||
$error = true;
|
|
||||||
}
|
|
||||||
if (isset($request->refsite) && $request->refsite != "") {
|
|
||||||
$refsite = $request->refsite;
|
|
||||||
} else {
|
|
||||||
$error = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($request->prenom) && $request->prenom != "") {
|
|
||||||
$prenom = $request->prenom;
|
|
||||||
} else {
|
|
||||||
$error = true;
|
|
||||||
}
|
|
||||||
if (isset($request->email) && $request->email != "" && filter_var($request->email, FILTER_VALIDATE_EMAIL)) {
|
|
||||||
$email = $request->email;
|
|
||||||
} else {
|
|
||||||
$error = true;
|
|
||||||
}
|
|
||||||
if (isset($request->code_postal) && $request->code_postal != "") {
|
|
||||||
$code_postal = $request->code_postal;
|
|
||||||
} else {
|
|
||||||
$error = true;
|
|
||||||
}
|
|
||||||
if (isset($request->commune) && $request->commune != "") {
|
|
||||||
$commune = $request->commune;
|
|
||||||
} else {
|
|
||||||
$error = true;
|
|
||||||
}
|
|
||||||
if (isset($request->pays) && $request->pays != "") {
|
|
||||||
if (filter_var($request->pays, FILTER_VALIDATE_INT)) {
|
|
||||||
$pays = $request->pays;
|
|
||||||
} else {
|
|
||||||
$error = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$pays = 250;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($error) {
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'KO',
|
|
||||||
'Code' => 101,
|
|
||||||
'Message' => 'Des paramètres de la requête sont mal renseignés ou non présents'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$contact = Contact::where(['contact_siteId' => $refsite, 'contact_ref' => $refadherent])->first();
|
|
||||||
|
|
||||||
if ($contact) {
|
|
||||||
$contact->contact_prenom = $prenom;
|
|
||||||
$contact->contact_nom = $nom;
|
|
||||||
$contact->contact_email = $email;
|
|
||||||
$contact->contact_cp = $code_postal;
|
|
||||||
$contact->contact_ville = $commune;
|
|
||||||
$contact->contact_country = $pays;
|
|
||||||
$contact->contact_updatedate = date('Y-m-d H:i:s');
|
|
||||||
if (isset($request->hashcode) && $request->hashcode != "") {
|
|
||||||
$contact->contact_hash = $request->hashcode;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$site = Site::where('site_id', $refsite)->first();
|
|
||||||
|
|
||||||
if ($site) {
|
|
||||||
$contact = new Contact();
|
|
||||||
$contact->contact_nom = $nom;
|
|
||||||
$contact->contact_prenom = $prenom;
|
|
||||||
$contact->contact_ref = $refadherent;
|
|
||||||
$contact->contact_email = $email;
|
|
||||||
$contact->contact_cp = $code_postal;
|
|
||||||
$contact->contact_ville = $commune;
|
|
||||||
$contact->contact_country = $pays;
|
|
||||||
$contact->contact_siteId = $refsite;
|
|
||||||
if (isset($request->hashcode) && $request->hashcode != "") {
|
|
||||||
$contact->contact_hash = $request->hashcode;
|
|
||||||
} else {
|
|
||||||
$contact->contact_hash = strtoupper(md5(uniqid(time(), true)));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'KO',
|
|
||||||
'Code' => 102,
|
|
||||||
'Message' => 'Le site spécifié n\'existe pas'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($contact->save()) {
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'OK',
|
|
||||||
'contact' => $contact
|
|
||||||
]);
|
|
||||||
} else {
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'KO',
|
|
||||||
'Code' => 109,
|
|
||||||
'Message' => 'Une erreur est survenue'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function loadWidget(LoadWidgetContact $request, Contact $contact)
|
|
||||||
{
|
|
||||||
$camp_id = $request->camp_id;
|
|
||||||
$campagne = Campagne::where(['camp_id' => $camp_id])->first();
|
|
||||||
$coupons = $campagne->coupons;
|
|
||||||
|
|
||||||
foreach ($coupons as $key => $coupon) {
|
|
||||||
if (!$this->isAvailableToPrint($coupon, $campagne)) {
|
|
||||||
$coupons->forget($key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$allLogs = Log::where(['log_refsite' => $campagne->camp_siteId, 'log_contactId' => $contact->contact_id, 'log_statut' => 'OK'])->orderBy('created_at', 'DESC')->get();
|
|
||||||
$logs = array();
|
|
||||||
foreach ($allLogs as &$l) {
|
|
||||||
$params = json_decode($l->log_params);
|
|
||||||
if ($l->log_action == 3 || $l->log_action == 1) {
|
|
||||||
$l->log_message = json_decode($l->log_message, true);
|
|
||||||
}
|
|
||||||
if (intval($params->refcamp) == $camp_id) {
|
|
||||||
array_push($logs, $l);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---- Pour les types murs
|
|
||||||
if ($campagne->camp_type->equals(CampaignTypes::mur()) || $campagne->camp_type->equals(CampaignTypes::murss())) {
|
|
||||||
foreach ($coupons as &$coupon) {
|
|
||||||
$coupon->isAvailable = $this->isAvailable($coupon, $campagne, $contact);
|
|
||||||
}
|
|
||||||
unset($coupon);
|
|
||||||
|
|
||||||
// Montant total et Nombre réductions disponible
|
|
||||||
$montantDispo = 0;
|
|
||||||
$montantTotal = 0;
|
|
||||||
$nbCoupon = 0;
|
|
||||||
foreach ($coupons as $coupon) {
|
|
||||||
$montantTotal += $coupon->coupon_value;
|
|
||||||
if ($coupon->isAvailable == true) {
|
|
||||||
$montantDispo += $coupon->coupon_value;
|
|
||||||
$nbCoupon++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count($coupons) === $nbCoupon) {
|
|
||||||
$reset = false;
|
|
||||||
} else {
|
|
||||||
$reset = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
$campagne->url = url('/') . "/?refsite=" . $campagne->camp_siteId . "&refcamp=" . $camp_id . "&hash=" . $contact->contact_hash;
|
|
||||||
|
|
||||||
$returnHTML = view('widgets.mur')
|
|
||||||
->with([
|
|
||||||
'campagne' => $campagne,
|
|
||||||
'reset' => $reset,
|
|
||||||
'montantTotal' => $montantTotal,
|
|
||||||
'montantDispo' => $montantDispo,
|
|
||||||
'logs' => $logs,
|
|
||||||
'contact' => $contact])
|
|
||||||
->renderSections()['widget'];
|
|
||||||
|
|
||||||
return json_encode(array('success' => true, 'html' => $returnHTML));
|
|
||||||
} else {
|
|
||||||
// ---- Pour les types paniers
|
|
||||||
$panier = Panier::where(['panier_campId' => $campagne->camp_id, 'panier_contactId' => $contact->contact_id, 'panier_pending' => 1])->first();
|
|
||||||
if ($panier) {
|
|
||||||
$panier_ref = $panier->panier_ref;
|
|
||||||
foreach ($coupons as &$coupon) {
|
|
||||||
$paniercontent = PanierContent::where(['panier_content_couponId' => $coupon->coupon_id, 'panier_content_panierId' => $panier->panier_id])->first();
|
|
||||||
if ($paniercontent) {
|
|
||||||
$coupon->qty = $paniercontent->panier_content_quantity;
|
|
||||||
} else {
|
|
||||||
$coupon->qty = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$campagne->url = url('/') . "/?basketid=" . $panier_ref;
|
|
||||||
unset($coupon);
|
|
||||||
} else {
|
|
||||||
$panier_ref = "";
|
|
||||||
foreach ($coupons as &$coupon) {
|
|
||||||
$coupon->qty = 0;
|
|
||||||
}
|
|
||||||
$campagne->url = "Pas d'url disponible (panier non créé)";
|
|
||||||
}
|
|
||||||
|
|
||||||
$returnHTML = view('widgets.panier')
|
|
||||||
->with([
|
|
||||||
'campagne' => $campagne,
|
|
||||||
'contact' => $contact,
|
|
||||||
'panier' => $panier_ref,
|
|
||||||
'logs' => $logs,
|
|
||||||
'coupons' => $coupons
|
|
||||||
])
|
|
||||||
->renderSections()['widget'];
|
|
||||||
return json_encode(array('success' => true, 'html' => $returnHTML));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -3,11 +3,12 @@
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use App\Coupon;
|
use Illuminate\Support\Str;
|
||||||
use App\Site;
|
use App\Models\Coupon;
|
||||||
use App\Campagne;
|
use App\Models\Site;
|
||||||
use App\Mouvement;
|
use App\Models\Campagne;
|
||||||
use App\Calendrier;
|
use App\Models\Mouvement;
|
||||||
|
use App\Models\Calendrier;
|
||||||
use App\Http\Requests\Coupons\StoreCoupons;
|
use App\Http\Requests\Coupons\StoreCoupons;
|
||||||
use App\Http\Requests\Coupons\UpdateCoupons;
|
use App\Http\Requests\Coupons\UpdateCoupons;
|
||||||
use App\Traits\GenerateBR;
|
use App\Traits\GenerateBR;
|
||||||
|
|
@ -32,7 +33,8 @@ class CouponController extends Controller
|
||||||
// ---- Calcul de la quantité mise à disposition grace aux fonctions dans CouponTrait.php
|
// ---- Calcul de la quantité mise à disposition grace aux fonctions dans CouponTrait.php
|
||||||
$coupon->coupon_quantity = $this->getFullQuantity($coupon);
|
$coupon->coupon_quantity = $this->getFullQuantity($coupon);
|
||||||
// ---- Calcul de la quantité restante toutes campagnes comprises grace aux fonctions dans CouponTrait.php
|
// ---- Calcul de la quantité restante toutes campagnes comprises grace aux fonctions dans CouponTrait.php
|
||||||
$coupon->coupon_left = $coupon->coupon_quantity - $this->getUsedQuantity($coupon);
|
$coupon->coupon_left = 0;
|
||||||
|
// $coupon->coupon_quantity - $this->getUsedQuantity($coupon);
|
||||||
}
|
}
|
||||||
return view('coupon.index', ['coupons' => $coupons]);
|
return view('coupon.index', ['coupons' => $coupons]);
|
||||||
}
|
}
|
||||||
|
|
@ -47,16 +49,17 @@ class CouponController extends Controller
|
||||||
// TODO : Revoir le passage du site
|
// TODO : Revoir le passage du site
|
||||||
$site = session()->get('site');
|
$site = session()->get('site');
|
||||||
|
|
||||||
$campagnes = Campagne::where('camp_siteId', $site->id)->get()->pluck('camp_name', 'camp_id');
|
$campagnes = Campagne::where('camp_siteId', session()->get('site')->site_id)->get()
|
||||||
$site = Site::findOrFail($site->id);
|
->pluck('camp_name', 'camp_id');
|
||||||
|
|
||||||
|
$site = Site::findOrFail($site->id);
|
||||||
return view('coupon.create')->with('campagnes', $campagnes)->with('site', $site);
|
return view('coupon.create')->with('campagnes', $campagnes)->with('site', $site);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store a newly created resource in storage.
|
* Store a newly created resource in storage.
|
||||||
*
|
*
|
||||||
* @param StoreCoupons $request
|
* @param StoreCoupons $request
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function store(StoreCoupons $request)
|
public function store(StoreCoupons $request)
|
||||||
|
|
@ -85,7 +88,7 @@ class CouponController extends Controller
|
||||||
$coupon->coupon_image = $datas['coupon_image'];
|
$coupon->coupon_image = $datas['coupon_image'];
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO : Voir si on peut mettre le set a 0 dans la request
|
//TODO : Voir si on peut mettre le set a 0 dans la request
|
||||||
if (!isset($datas['coupon_published'])) {
|
if (!isset($datas['coupon_published'])) {
|
||||||
$coupon->coupon_published = 0;
|
$coupon->coupon_published = 0;
|
||||||
}
|
}
|
||||||
|
|
@ -99,29 +102,31 @@ class CouponController extends Controller
|
||||||
$coupon->save();
|
$coupon->save();
|
||||||
|
|
||||||
$site = Site::findOrFail($site_id);
|
$site = Site::findOrFail($site_id);
|
||||||
|
|
||||||
$site->coupons()->save($coupon);
|
$site->coupons()->save($coupon);
|
||||||
|
|
||||||
if (isset($datas['initial_quantity'])) {
|
if (isset($datas['initial_quantity'])) {
|
||||||
$mouvement = new Mouvement();
|
$mouvement = new Mouvement();
|
||||||
$mouvement->mouvement_nombre = $datas['initial_quantity'];
|
$mouvement->mouvement_nombre = $datas['initial_quantity'];
|
||||||
$coupon->mouvements()->save($mouvement);
|
$coupon->mouvements()->save($mouvement);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($datas['startdate'])) {
|
if (isset($datas['startdate'])) {
|
||||||
foreach ($datas['startdate'] as $key => $value) {
|
foreach ($datas['startdate'] as $key => $value) {
|
||||||
$calendar = new Calendrier();
|
$calendar = new Calendrier();
|
||||||
$calendar->calendrier_startdate = $value;
|
$calendar->calendrier_startdate = $value;
|
||||||
$calendar->calendrier_enddate = $datas['enddate'][$key];
|
$calendar->calendrier_enddate = $datas['enddate'][$key];
|
||||||
$coupon->calendriers()->save($calendar);
|
$coupon->calendriers()->save($calendar);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return redirect()->route('coupon.edit', ['coupon' => $coupon]);
|
|
||||||
|
return to_route('coupon.edit', ['coupon' => $coupon]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the form for editing the specified resource.
|
* Show the form for editing the specified resource.
|
||||||
*
|
*
|
||||||
* @param \App\Coupon $coupon
|
* @param \App\Models\Coupon $coupon
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function edit(Coupon $coupon)
|
public function edit(Coupon $coupon)
|
||||||
|
|
@ -132,8 +137,8 @@ class CouponController extends Controller
|
||||||
/**
|
/**
|
||||||
* Update the specified resource in storage.
|
* Update the specified resource in storage.
|
||||||
*
|
*
|
||||||
* @param UpdateCoupons $request
|
* @param UpdateCoupons $request
|
||||||
* @param \App\Coupon $coupon
|
* @param \App\Models\Coupon $coupon
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function update(UpdateCoupons $request, Coupon $coupon)
|
public function update(UpdateCoupons $request, Coupon $coupon)
|
||||||
|
|
@ -159,7 +164,7 @@ class CouponController extends Controller
|
||||||
// On sauvegarde les informations
|
// On sauvegarde les informations
|
||||||
if ($coupon->update($datas)) {
|
if ($coupon->update($datas)) {
|
||||||
// Si l'update est OK on met à jour l'image du BR
|
// Si l'update est OK on met à jour l'image du BR
|
||||||
$br_path = $this->generateBase($request, $coupon);
|
$br_path = $this->generateBase($request, $coupon);
|
||||||
$coupon->coupon_image = $br_path;
|
$coupon->coupon_image = $br_path;
|
||||||
$coupon->save();
|
$coupon->save();
|
||||||
|
|
||||||
|
|
@ -167,8 +172,8 @@ class CouponController extends Controller
|
||||||
// TODO : Gestion de l'erreur si on ajoute une ligne vide
|
// TODO : Gestion de l'erreur si on ajoute une ligne vide
|
||||||
if (isset($datas['mouvementNbre'])) {
|
if (isset($datas['mouvementNbre'])) {
|
||||||
foreach ($datas['mouvementNbre'] as $key => $value) {
|
foreach ($datas['mouvementNbre'] as $key => $value) {
|
||||||
$mouvement = new Mouvement();
|
$mouvement = new Mouvement();
|
||||||
$mouvement->mouvement_nombre = $value;
|
$mouvement->mouvement_nombre = $value;
|
||||||
$mouvement->mouvement_created_at = $datas['mouvementDate'][$key];
|
$mouvement->mouvement_created_at = $datas['mouvementDate'][$key];
|
||||||
$coupon->mouvements()->save($mouvement);
|
$coupon->mouvements()->save($mouvement);
|
||||||
}
|
}
|
||||||
|
|
@ -178,26 +183,26 @@ class CouponController extends Controller
|
||||||
if (isset($datas['startdate'])) {
|
if (isset($datas['startdate'])) {
|
||||||
$coupon->calendriers()->delete();
|
$coupon->calendriers()->delete();
|
||||||
foreach ($datas['startdate'] as $key => $value) {
|
foreach ($datas['startdate'] as $key => $value) {
|
||||||
$calendar = new Calendrier();
|
$calendar = new Calendrier();
|
||||||
$calendar->calendrier_startdate = $value;
|
$calendar->calendrier_startdate = $value;
|
||||||
$calendar->calendrier_enddate = $datas['enddate'][$key];
|
$calendar->calendrier_enddate = $datas['enddate'][$key];
|
||||||
$coupon->calendriers()->save($calendar);
|
$coupon->calendriers()->save($calendar);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
session()->flash('update_ok', 'Mise à jour du coupon réussie !');
|
session()->flash('update_ok', 'Mise à jour du coupon réussie !');
|
||||||
|
|
||||||
return redirect()->route('coupon.edit', ['coupon' => $coupon]);
|
return to_route('coupon.edit', ['coupon' => $coupon]);
|
||||||
} else {
|
} else {
|
||||||
return view('holder');
|
return view('holder');
|
||||||
}
|
} //end if
|
||||||
|
|
||||||
return redirect()->route('coupon.edit', ['coupon' => $coupon]);
|
return to_route('coupon.edit', ['coupon' => $coupon]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove the specified resource from storage.
|
* Remove the specified resource from storage.
|
||||||
*
|
*
|
||||||
* @param \App\Coupon $coupon
|
* @param \App\Models\Coupon $coupon
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function destroy(Coupon $coupon)
|
public function destroy(Coupon $coupon)
|
||||||
|
|
@ -205,7 +210,7 @@ class CouponController extends Controller
|
||||||
$coupon->coupon_published = 0;
|
$coupon->coupon_published = 0;
|
||||||
$coupon->save();
|
$coupon->save();
|
||||||
if ($coupon->delete()) {
|
if ($coupon->delete()) {
|
||||||
return redirect()->route('coupon.index');
|
return to_route('coupon.index');
|
||||||
} else {
|
} else {
|
||||||
session()->flash('delete_nok', 'Erreur lors de la suppression');
|
session()->flash('delete_nok', 'Erreur lors de la suppression');
|
||||||
return back();
|
return back();
|
||||||
|
|
@ -213,7 +218,7 @@ class CouponController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
|
|
@ -224,8 +229,9 @@ class CouponController extends Controller
|
||||||
foreach ($datas as $key => $item) {
|
foreach ($datas as $key => $item) {
|
||||||
if ($key == 'coupon_image' || $key == 'coupon_gs1code' || $key == 'coupon_decoration_image' || $key == 'coupon_logo_image' || (substr($key, 7, 9) == 'thumbnail' && strlen($key) < 18)) {
|
if ($key == 'coupon_image' || $key == 'coupon_gs1code' || $key == 'coupon_decoration_image' || $key == 'coupon_logo_image' || (substr($key, 7, 9) == 'thumbnail' && strlen($key) < 18)) {
|
||||||
if (isset($item)) {
|
if (isset($item)) {
|
||||||
$path = $item->store('coupons');
|
/** @var \Illuminate\Http\UploadedFile $item */
|
||||||
$path = str_replace('public/', '', $path);
|
$path = $item->store('modelfiles/coupons', 'public');
|
||||||
|
$path = Str::start($path, 'storage/');
|
||||||
$datas->put($key, $path);
|
$datas->put($key, $path);
|
||||||
} else {
|
} else {
|
||||||
$datas->put($key, $request->input($key . '_hidden'));
|
$datas->put($key, $request->input($key . '_hidden'));
|
||||||
|
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
|
||||||
|
|
||||||
use App\Campagne;
|
|
||||||
use App\Http\Requests\Customers\SearchCustomers;
|
|
||||||
use App\Models\Customers;
|
|
||||||
use App\Models\PrintedWalls;
|
|
||||||
use App\Site;
|
|
||||||
|
|
||||||
class CustomersController extends Controller
|
|
||||||
{
|
|
||||||
public function index(SearchCustomers $request, Site $site)
|
|
||||||
{
|
|
||||||
$campaigns = [];
|
|
||||||
$customer = null;
|
|
||||||
$email = $request->email;
|
|
||||||
|
|
||||||
$site->load("campagnes");
|
|
||||||
|
|
||||||
if ($email) {
|
|
||||||
$customer = Customers::where('email', $email)->first();
|
|
||||||
if ($customer) {
|
|
||||||
$publishedCampaign = $site->campagnes->where('camp_published', 1)->pluck('camp_id');
|
|
||||||
|
|
||||||
$campaigns = Campagne::where('camp_published', 1)->whereHas('printedWalls', function ($q) use ($customer, $publishedCampaign) {
|
|
||||||
$q->where('customer_id', $customer->id)->whereIn('camp_id', $publishedCampaign);
|
|
||||||
})->get();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return view('customers.index', compact('site', 'customer', 'campaigns', 'email'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,86 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
|
||||||
|
|
||||||
use App;
|
|
||||||
use CpChart\Data;
|
|
||||||
use CpChart\Image;
|
|
||||||
use App\Traits\CouponTrait;
|
|
||||||
use App\Traits\GraphTrait;
|
|
||||||
use App\Site;
|
|
||||||
use App\Coupon;
|
|
||||||
use App\Http\Requests\Export\PDFExport;
|
|
||||||
use Datetime;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
|
|
||||||
class ExportController extends Controller
|
|
||||||
{
|
|
||||||
use CouponTrait;
|
|
||||||
use GraphTrait;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle the incoming request.
|
|
||||||
*
|
|
||||||
* @param \Illuminate\Http\Request $request
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function show(Request $request)
|
|
||||||
{
|
|
||||||
$sites = Site::all();
|
|
||||||
$startdate = new DateTime("first day of last month");
|
|
||||||
$startdate = $startdate->format('Y-m-d');
|
|
||||||
$enddate = date('Y-m-d');
|
|
||||||
|
|
||||||
return view('export.index')->with(['sites' => $sites, 'startdate' => $startdate, 'enddate' => $enddate]);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------ AJAX Export
|
|
||||||
public function exportCoupons(PDFExport $request)
|
|
||||||
{
|
|
||||||
$ids = $request->ids;
|
|
||||||
$startdate = $request->startdate;
|
|
||||||
$enddate = $request->enddate;
|
|
||||||
|
|
||||||
$coupons = Coupon::find($ids);
|
|
||||||
|
|
||||||
$labels = $this->getLabelsForStats($startdate, $enddate);
|
|
||||||
|
|
||||||
$paths = array();
|
|
||||||
|
|
||||||
foreach ($coupons as $coupon) {
|
|
||||||
$cpName = str_replace(' ', '', $coupon->coupon_name);
|
|
||||||
$full_path = 'export/' . $cpName . '_' . date('d_m_Y') . '.pdf';
|
|
||||||
$dataCoupon = $this->getDataForCouponAllCamp($labels, $coupon);
|
|
||||||
$coupon->couponQuantity = $this->getFullQuantity($coupon);
|
|
||||||
$coupon->couponFullPrinted = $this->getUsedQuantity($coupon);
|
|
||||||
$coupon->couponPrinted = $this->getUsedQuantityOnPeriod($coupon, $startdate, $enddate);
|
|
||||||
|
|
||||||
$pdf = App::make('dompdf.wrapper');
|
|
||||||
|
|
||||||
$myData = new Data();
|
|
||||||
|
|
||||||
$myData->addPoints($dataCoupon, "My Serie 1");
|
|
||||||
$myData->addPoints($labels, "My Serie 2");
|
|
||||||
$myData->setAxisName(0, "Coupons Diffusés");
|
|
||||||
$myData->setAbscissa("My Serie 2");
|
|
||||||
$myData->setSerieTicks("My Serie 2", 2);
|
|
||||||
$serieSettings = array("R" => 229,"G" => 11,"B" => 11);
|
|
||||||
$myData->setPalette("My Serie 1", $serieSettings);
|
|
||||||
$myPicture = new Image(700, 230, $myData);
|
|
||||||
$myPicture->setGraphArea(60, 40, 670, 190);
|
|
||||||
$myPicture->setFontProperties(array("FontSize" => 10));
|
|
||||||
$myPicture->drawScale(array("DrawSubTicks" => true, 'LabelSkip' => 1, 'LabelRotation' => 25, "Mode" => SCALE_MODE_START0, "CycleBackground" => true,"GridR" => 102,"GridG" => 102,"GridB" => 102));
|
|
||||||
$myPicture->setShadow(true, array("X" => 1,"Y" => 1,"R" => 0,"G" => 0,"B" => 0,"Alpha" => 10));
|
|
||||||
$myPicture->drawLineChart(array("DisplayColor" => DISPLAY_AUTO));
|
|
||||||
$myPicture->Render('export/temp.png');
|
|
||||||
|
|
||||||
$view = view('export.template')->with(['src' => 'export/temp.png', 'coupon' => $coupon, 'startdate' => $startdate, 'enddate' => $enddate])->render();
|
|
||||||
|
|
||||||
$pdf->loadHTML($view);
|
|
||||||
$pdf->save($full_path);
|
|
||||||
array_push($paths, $full_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return json_encode($paths);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
88
app/Http/Controllers/Fo/BasketController.php
Normal file
88
app/Http/Controllers/Fo/BasketController.php
Normal file
|
|
@ -0,0 +1,88 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Fo;
|
||||||
|
|
||||||
|
use App\Models\Calendrier;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\Requests\Fo\Basket\PrintRequest;
|
||||||
|
use App\Models\Basket;
|
||||||
|
use App\Traits\GenerateBR;
|
||||||
|
use PDF;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use LDC\LDCCRM\CrmApiV4;
|
||||||
|
|
||||||
|
class BasketController extends Controller
|
||||||
|
{
|
||||||
|
use GenerateBR;
|
||||||
|
|
||||||
|
// FIXME: Docblock
|
||||||
|
public function show(Request $request, Basket $basket)
|
||||||
|
{
|
||||||
|
$totalQuantity = $basket->contents->sum(fn($content) => $content->quantity - $content->printed);
|
||||||
|
|
||||||
|
if (!$totalQuantity) {
|
||||||
|
return view('fo.basket.empty', compact('basket'));
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('fo.basket.show', compact('basket', 'totalQuantity'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: Docblock
|
||||||
|
public function print(PrintRequest $request, Basket $basket)
|
||||||
|
{
|
||||||
|
$campagne = $basket->campagne;
|
||||||
|
|
||||||
|
$crm = new CrmApiV4(config('services.crm.endpoint'), $campagne->site->crm_token, $campagne->site->crm_password);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \LDC\LDCCRM\Models\Customer
|
||||||
|
*/
|
||||||
|
$crmInfos = $crm->getCustomer($basket->customer->hashcode);
|
||||||
|
|
||||||
|
throw_if(is_null($crmInfos), \Exception::class, 'Customer not found.');
|
||||||
|
|
||||||
|
$coupons = [];
|
||||||
|
$currentDateTime = date('Y-m-d H:i:s');
|
||||||
|
|
||||||
|
foreach ($basket->contents as $content) {
|
||||||
|
$coupon = $content->coupon()->whereRaw(
|
||||||
|
"coupon_published = 1 AND
|
||||||
|
(coupon_mindatediffusion IS NULL OR coupon_mindatediffusion <= NOW()) AND
|
||||||
|
(coupon_maxdatediffusion IS NULL OR coupon_maxdatediffusion >= NOW()) AND
|
||||||
|
(coupon_maxdatevalidity IS NULL OR coupon_maxdatevalidity >= NOW())"
|
||||||
|
)->first();
|
||||||
|
|
||||||
|
if ($coupon !== null) {
|
||||||
|
$calendars = Calendrier::where('calendrier_couponId', $coupon->coupon_id)->get();
|
||||||
|
|
||||||
|
$published = true;
|
||||||
|
if (!$calendars->isEmpty()) {
|
||||||
|
$published = false;
|
||||||
|
foreach ($calendars as $calendar) {
|
||||||
|
if ($currentDateTime > $calendar->calendrier_startdate && $currentDateTime < $calendar->calendrier_enddate) {
|
||||||
|
$published = true;
|
||||||
|
break; // Exit loop early as condition is met
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($published) {
|
||||||
|
$qtyToPrint = $content->quantity - $content->printed;
|
||||||
|
for ($i = 0; $i < $qtyToPrint; $i++) {
|
||||||
|
$coupons[] = $this->printCoupon($coupon, $basket->customer, $crmInfos, $campagne);
|
||||||
|
}
|
||||||
|
$content->printed = $content->quantity;
|
||||||
|
$content->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($coupons)) {
|
||||||
|
return to_route('fo.basket.show', $basket);
|
||||||
|
}
|
||||||
|
|
||||||
|
// $coupons contains all printed coupons
|
||||||
|
$pdf = PDF::loadView('pdf.coupons', ['coupons' => $coupons]);
|
||||||
|
return $pdf->download(sprintf("coupons_%s_%s_%s.pdf", $crmInfos->firstname, $crmInfos->lastname, date('d-m-Y_H-i-s')));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,89 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
|
||||||
|
|
||||||
use App\Http\Requests\Users\StoreUsers;
|
|
||||||
use App\Http\Requests\Users\UpdateUsers;
|
|
||||||
use App\Site;
|
|
||||||
use App\User;
|
|
||||||
use App\Log;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Support\Facades\Auth;
|
|
||||||
use Illuminate\Support\Facades\Hash;
|
|
||||||
|
|
||||||
class MaintenanceController extends Controller
|
|
||||||
{
|
|
||||||
|
|
||||||
public function show(Request $request)
|
|
||||||
{
|
|
||||||
$users = User::all();
|
|
||||||
|
|
||||||
$dates = array(date('m/Y'));
|
|
||||||
for ($i = 1; $i < 6; $i++) {
|
|
||||||
$datebefore = date("m/Y", strtotime("-" . $i . " months"));
|
|
||||||
array_push($dates, $datebefore);
|
|
||||||
}
|
|
||||||
$count = array();
|
|
||||||
foreach ($dates as $month) {
|
|
||||||
$logs = Log::where(['log_statut' => 'NOK'])->whereMonth('created_at', $month)->count();
|
|
||||||
array_push($count, [$month, $logs]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return view('maintenance.index')->with(['users' => $users, 'logs' => $count]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function usercreate(Request $request)
|
|
||||||
{
|
|
||||||
$sites = Site::all();
|
|
||||||
return view('user.create')->with(['sites' => $sites]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function userstore(StoreUsers $request)
|
|
||||||
{
|
|
||||||
$user = new User();
|
|
||||||
$user->fill($request->validated());
|
|
||||||
$user->password = Hash::make($request->password);
|
|
||||||
$user->save();
|
|
||||||
|
|
||||||
$sites = Site::whereIn('site_id', $request->site)->get()->pluck('id')->toArray();
|
|
||||||
$user->sites()->sync($sites);
|
|
||||||
|
|
||||||
return redirect()->route('maintenance.user.edit', ['user' => $user]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function useredit(User $user)
|
|
||||||
{
|
|
||||||
$sites = Site::all();
|
|
||||||
$usersites = $user->sites()->get()->pluck('site_id')->toArray();
|
|
||||||
return view('user.edit')->with(['user' => $user, 'sites' => $sites, 'usersites' => $usersites]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function userupdate(UpdateUsers $request, User $user)
|
|
||||||
{
|
|
||||||
//MAJ du User
|
|
||||||
$user->fill($request->validated());
|
|
||||||
$user->save();
|
|
||||||
|
|
||||||
//MAJ des sites liés
|
|
||||||
$sites = Site::whereIn('site_id', $request->site)->get()->pluck('id')->toArray();
|
|
||||||
$user->sites()->sync($sites);
|
|
||||||
|
|
||||||
$marques = Auth::user()->sites;
|
|
||||||
$submarques = $marques->map(function ($marque) {
|
|
||||||
return $marque->only(['id', 'site_nom', 'site_id', 'site_logo']);
|
|
||||||
});
|
|
||||||
|
|
||||||
session()->put('marques', $submarques);
|
|
||||||
return redirect()->route('maintenance.show');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function userdestroy(User $user)
|
|
||||||
{
|
|
||||||
if ($user->delete()) {
|
|
||||||
return redirect()->route('maintenance.show');
|
|
||||||
} else {
|
|
||||||
session()->flash('delete_nok', 'Erreur lors de la suppression');
|
|
||||||
return view('maintenance.user.edit')->with('user', $user);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,315 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use App\Campagne;
|
|
||||||
use App\Contact;
|
|
||||||
use App\Mur;
|
|
||||||
use App\Log;
|
|
||||||
use App\Traits\CouponTrait;
|
|
||||||
use App\Traits\ThanksTrait;
|
|
||||||
|
|
||||||
class MurController extends Controller
|
|
||||||
{
|
|
||||||
use CouponTrait;
|
|
||||||
use ThanksTrait;
|
|
||||||
|
|
||||||
public function show(Request $request)
|
|
||||||
{
|
|
||||||
$datas = $request->all();
|
|
||||||
if (isset($datas['refcamp'])) {
|
|
||||||
$ref = intval($datas['refcamp']);
|
|
||||||
$campagne = Campagne::where(['camp_id' => $ref])->first();
|
|
||||||
} else {
|
|
||||||
abort(404);
|
|
||||||
}
|
|
||||||
if (!isset($datas['refsite'])) {
|
|
||||||
abort(404);
|
|
||||||
}
|
|
||||||
if (!isset($campagne) || $campagne->camp_published == 0 || ($campagne->camp_type->value != 0 && $campagne->camp_type->value != 2)) {
|
|
||||||
abort(404);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($datas['hash'])) {
|
|
||||||
$contact = Contact::where([
|
|
||||||
'contact_hash' => $datas['hash'], 'contact_siteId' => $campagne->camp_siteId
|
|
||||||
])->first();
|
|
||||||
} else {
|
|
||||||
abort(404);
|
|
||||||
}
|
|
||||||
|
|
||||||
$coupons = $this->getCouponsPublished($campagne);
|
|
||||||
|
|
||||||
foreach ($coupons as $coupon) {
|
|
||||||
$coupon->isAvailable = $this->isAvailable($coupon, $campagne, $contact);
|
|
||||||
$coupon->isAvailableToPrint = $this->isAvailableToPrint($coupon, $campagne);
|
|
||||||
}
|
|
||||||
unset($coupon);
|
|
||||||
|
|
||||||
// Montant total et Nombre réductions disponible
|
|
||||||
$montantDispo = 0;
|
|
||||||
$montantTotal = 0;
|
|
||||||
$nbCoupon = 0;
|
|
||||||
$nbCouponToPrint = 0;
|
|
||||||
foreach ($coupons as $coupon) {
|
|
||||||
$montantTotal += $coupon->coupon_value;
|
|
||||||
if ($coupon->isAvailable == true) {
|
|
||||||
$montantDispo += $coupon->coupon_value;
|
|
||||||
$nbCoupon++;
|
|
||||||
}
|
|
||||||
if ($coupon->isAvailableToPrint == true) {
|
|
||||||
$nbCouponToPrint++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
session()->put('campagne', $campagne);
|
|
||||||
session()->put('site', $campagne->site);
|
|
||||||
session()->put('contact', $contact);
|
|
||||||
|
|
||||||
return view('landings::' . $ref . '.index')
|
|
||||||
->with(['ref' => $ref, 'coupons' => $coupons, 'contact' => $contact, 'nb' => $nbCoupon, 'nbAvailableToPrint' => $nbCouponToPrint, 'montantDispo' => $montantDispo]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function printMur(Request $request)
|
|
||||||
{
|
|
||||||
if (isset($request->coupons)) {
|
|
||||||
session()->put('coupons', $request->coupons);
|
|
||||||
$coupons = $request->coupons;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request->session()->has('campagne')) {
|
|
||||||
$campagne = $request->session()->get('campagne');
|
|
||||||
} else {
|
|
||||||
abort(419);
|
|
||||||
}
|
|
||||||
|
|
||||||
$ref = $campagne->camp_id;
|
|
||||||
|
|
||||||
return view('landings::' . $ref . '.imprimer')
|
|
||||||
->with(['ref' => $ref, 'coupons' => $coupons, 'contact' => $request->session()->get('contact')]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function deleteControlContact(Request $request)
|
|
||||||
{
|
|
||||||
if (isset($request->admin)) {
|
|
||||||
$source = 'ADMIN';
|
|
||||||
} else {
|
|
||||||
$source = 'API';
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---- INIT du log
|
|
||||||
$log = new Log();
|
|
||||||
$log->log_action = config('constants.delctrlcontact');
|
|
||||||
$log->log_source = $source;
|
|
||||||
|
|
||||||
$error = false;
|
|
||||||
// ---- Contrôle des paramètres
|
|
||||||
if (isset($request->refcamp) && $request->refcamp != "") {
|
|
||||||
$refcamp = $request->refcamp;
|
|
||||||
} else {
|
|
||||||
$error = true;
|
|
||||||
}
|
|
||||||
if (isset($request->refadherent) && $request->refadherent != "") {
|
|
||||||
$refadherent = $request->refadherent;
|
|
||||||
} else {
|
|
||||||
$error = true;
|
|
||||||
}
|
|
||||||
// Erreur si paramètres mal renseignés
|
|
||||||
if ($error) {
|
|
||||||
$log->log_params = json_encode(['refcamp' => $request->refcamp, 'refadherent' => $request->refadherent]);
|
|
||||||
$log->log_statut = 'NOK';
|
|
||||||
$log->log_message = "Des paramètres de la requête sont mal renseignés ou non présents";
|
|
||||||
$log->save();
|
|
||||||
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'KO',
|
|
||||||
'Code' => 101,
|
|
||||||
'Message' => 'Des paramètres de la requête sont mal renseignés ou non présents'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Check de la campagne
|
|
||||||
$campagne = Campagne::where('camp_id', $refcamp)->first();
|
|
||||||
|
|
||||||
if (!$campagne) {
|
|
||||||
$log->log_params = json_encode(['refcamp' => $request->refcamp, 'refadherent' => $request->refadherent]);
|
|
||||||
$log->log_statut = 'NOK';
|
|
||||||
$log->log_message = "La campagne n'existe pas";
|
|
||||||
$log->save();
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'KO',
|
|
||||||
'Code' => 103,
|
|
||||||
'Message' => 'La campagne n\'existe pas'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//Check du contact
|
|
||||||
$contact = Contact::where(['contact_ref' => $refadherent, 'contact_siteId' => $campagne->camp_siteId])->first();
|
|
||||||
|
|
||||||
if (!$contact) {
|
|
||||||
$log->log_params = json_encode(['refcamp' => $request->refcamp, 'refadherent' => $request->refadherent]);
|
|
||||||
$log->log_refsite = $campagne->camp_siteId;
|
|
||||||
$log->log_statut = 'NOK';
|
|
||||||
$log->log_message = "Le contact n'existe pas";
|
|
||||||
$log->save();
|
|
||||||
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'KO',
|
|
||||||
'Code' => 104,
|
|
||||||
'Message' => 'Le contact n\'existe pas'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($campagne) {
|
|
||||||
//Update
|
|
||||||
$mur = Mur::where(['mur_campId' => $refcamp, 'mur_contactId' => $contact->contact_id])->update(['mur_deleted' => '1']);
|
|
||||||
if ($mur != 0) {
|
|
||||||
$log->log_params = json_encode(['refcamp' => $request->refcamp, 'refadherent' => $request->refadherent]);
|
|
||||||
$log->log_refsite = $campagne->camp_siteId;
|
|
||||||
$log->log_contactId = $contact->contact_id;
|
|
||||||
$log->log_statut = 'OK';
|
|
||||||
$log->log_message = $mur . " enregistrements ont été mis à jour.";
|
|
||||||
$log->save();
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'OK',
|
|
||||||
'Message' => $mur . " enregistrements ont été mis à jour."
|
|
||||||
]);
|
|
||||||
} else {
|
|
||||||
$log->log_params = json_encode(['refcamp' => $request->refcamp, 'refadherent' => $request->refadherent]);
|
|
||||||
$log->log_refsite = $campagne->camp_siteId;
|
|
||||||
$log->log_contactId = $contact->contact_id;
|
|
||||||
$log->log_statut = 'OK';
|
|
||||||
$log->log_message = 'Aucun contrôle à effacer';
|
|
||||||
$log->save();
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'KO',
|
|
||||||
'Code' => 110,
|
|
||||||
'Message' => 'Aucun contrôle à effacer'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function montantDispoCampagne(Request $request)
|
|
||||||
{
|
|
||||||
|
|
||||||
// ---- Contrôle des paramètres
|
|
||||||
if (isset($request->refcamp) && $request->refcamp != "") {
|
|
||||||
$refcamp = $request->refcamp;
|
|
||||||
} else {
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'KO',
|
|
||||||
'Code' => 101,
|
|
||||||
'Message' => 'Des paramètres de la requête sont mal renseignés ou non présents'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------ Recuperation de la campagne
|
|
||||||
$camp = Campagne::where(['camp_id' => $refcamp])->first();
|
|
||||||
if (!$camp) {
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'KO',
|
|
||||||
'Code' => 103,
|
|
||||||
'Message' => 'La campagne n\'existe pas'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------ Récupération des coupons de la campagne
|
|
||||||
$coupons = $camp->coupons()->where(['coupon_published' => 1])->get();
|
|
||||||
if (count($coupons) == 0) {
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'KO',
|
|
||||||
'Code' => 105,
|
|
||||||
'Message' => 'La campagne est vide'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---- Montant total et Nombre réductions disponible
|
|
||||||
$montantTotal = 0;
|
|
||||||
foreach ($coupons as $coupon) {
|
|
||||||
$montantTotal += $coupon->coupon_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
$montantTotal = number_format($montantTotal, 2, ",", " ");
|
|
||||||
$montantTotal = str_pad($montantTotal, 6, "0", STR_PAD_LEFT);
|
|
||||||
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'OK',
|
|
||||||
'Message' => $montantTotal
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function montantDispoContact(Request $request)
|
|
||||||
{
|
|
||||||
$error = false;
|
|
||||||
if (isset($request->refcamp) && $request->refcamp != "") {
|
|
||||||
$refcamp = $request->refcamp;
|
|
||||||
} else {
|
|
||||||
$error = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($request->refsite) && $request->refsite != "") {
|
|
||||||
$refsite = $request->refsite;
|
|
||||||
} else {
|
|
||||||
$error = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($request->refadherent) && $request->refadherent != "") {
|
|
||||||
$refadherent = $request->refadherent;
|
|
||||||
} else {
|
|
||||||
$error = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($error) {
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'KO',
|
|
||||||
'Code' => 101,
|
|
||||||
'Message' => 'Des paramètres de la requête sont mal renseignés ou non présents'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$campagne = Campagne::where(['camp_id' => $refcamp])->where('camp_type', 'IN', array(0,2))->first();
|
|
||||||
|
|
||||||
if (!$campagne) {
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'KO',
|
|
||||||
'Code' => 103,
|
|
||||||
'Message' => 'La campagne n\'existe pas'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$contact = Contact::where(['contact_siteId' => $refsite, 'contact_ref' => $refadherent])->first();
|
|
||||||
if (!$contact) {
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'KO',
|
|
||||||
'Code' => 104,
|
|
||||||
'Message' => 'Le contact n\'existe pas'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$coupons = $this->getCouponsPublished($campagne);
|
|
||||||
|
|
||||||
foreach ($coupons as &$coupon) {
|
|
||||||
$coupon->isAvailable = $this->isAvailable($coupon, $campagne, $contact);
|
|
||||||
}
|
|
||||||
unset($coupon);
|
|
||||||
|
|
||||||
$montantDispo = 0;
|
|
||||||
foreach ($coupons as $coupon) {
|
|
||||||
if ($coupon->isAvailable == true) {
|
|
||||||
$montantDispo += $coupon->coupon_value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$montantDispo = number_format($montantDispo, 2, ",", " ");
|
|
||||||
$montantDispo = str_pad($montantDispo, 6, "0", STR_PAD_LEFT);
|
|
||||||
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'OK',
|
|
||||||
'Message' => $montantDispo
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -3,14 +3,11 @@
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use App\Panier;
|
use App\Models\Panier;
|
||||||
use App\Campagne;
|
use App\Models\Campagne;
|
||||||
use App\Coupon;
|
use App\Models\Coupon;
|
||||||
use App\Contact;
|
use App\Models\Contact;
|
||||||
use App\Enums\CampaignTypes;
|
use App\Enums\CampaignTypes;
|
||||||
use App\Site;
|
|
||||||
use App\Log;
|
|
||||||
use App\PanierContent;
|
|
||||||
use App\Traits\CouponTrait;
|
use App\Traits\CouponTrait;
|
||||||
use App\Traits\ThanksTrait;
|
use App\Traits\ThanksTrait;
|
||||||
|
|
||||||
|
|
@ -21,32 +18,26 @@ class PanierController extends Controller
|
||||||
|
|
||||||
public function showTemplate(Request $request)
|
public function showTemplate(Request $request)
|
||||||
{
|
{
|
||||||
//$panier = Panier::find($request->query('basketid'));
|
// $panier = Panier::find($request->query('basketid'));
|
||||||
$panier = Panier::where(['panier_ref' => $request->basketid])->first();
|
$panier = Panier::where(['panier_ref' => $request->basketid])->first();
|
||||||
if (!$panier) {
|
abort_unless($panier, 404);
|
||||||
abort(404);
|
|
||||||
}
|
|
||||||
session()->put('panier', $panier);
|
session()->put('panier', $panier);
|
||||||
$panierCouponsCount = $this->getCountCouponsPanierPublished($panier);
|
$panierCouponsCount = $this->getCountCouponsPanierPublished($panier);
|
||||||
$contact = Contact::where(['contact_id' => $panier->panier_contactId])->first();
|
$contact = Contact::where(['contact_id' => $panier->panier_contactId])->first();
|
||||||
if (!$contact) {
|
abort_unless($contact, 404);
|
||||||
abort(404);
|
|
||||||
}
|
|
||||||
session()->put('contact', $contact);
|
session()->put('contact', $contact);
|
||||||
|
|
||||||
$campagne = Campagne::where(['camp_id' => $panier->panier_campId, 'camp_published' => 1])->first();
|
$campagne = Campagne::where(['camp_id' => $panier->panier_campId, 'camp_published' => 1])->first();
|
||||||
if (!$campagne) {
|
abort_unless($campagne, 404);
|
||||||
abort(404);
|
|
||||||
}
|
|
||||||
session()->put('campagne', $campagne);
|
session()->put('campagne', $campagne);
|
||||||
|
|
||||||
if ($campagne->camp_type->equals(CampaignTypes::panier())) {
|
if ($campagne->camp_type->equals(CampaignTypes::panier())) {
|
||||||
$coupons = $this->getCouponsPublished($campagne);
|
$coupons = $this->getCouponsPublished($campagne);
|
||||||
} else {
|
} else {
|
||||||
$panierContents = $this->getPanierContentPublished($panier);
|
$panierContents = $this->getPanierContentPublished($panier);
|
||||||
$coupons = array();
|
$coupons = [];
|
||||||
foreach ($panierContents as $panierContent) {
|
foreach ($panierContents as $panierContent) {
|
||||||
$cp = Coupon::where(['coupon_id' => $panierContent->panier_content_couponId])->first();
|
$cp = Coupon::where(['coupon_id' => $panierContent->panier_content_couponId])->first();
|
||||||
$qty = $panierContent->panier_content_quantity;
|
$qty = $panierContent->panier_content_quantity;
|
||||||
for ($i = 0; $i < $qty; $i++) {
|
for ($i = 0; $i < $qty; $i++) {
|
||||||
$coupons[] = $cp;
|
$coupons[] = $cp;
|
||||||
|
|
@ -62,12 +53,13 @@ class PanierController extends Controller
|
||||||
{
|
{
|
||||||
if (isset($request->coupons)) {
|
if (isset($request->coupons)) {
|
||||||
session()->put('coupons', $request->coupons);
|
session()->put('coupons', $request->coupons);
|
||||||
$coupons = $request->coupons;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->session()->has('campagne')) {
|
$coupons = session('coupons', []);
|
||||||
$campagne = $request->session()->get('campagne');
|
|
||||||
}
|
abort_unless($request->session()->has('campagne'), 404);
|
||||||
|
|
||||||
|
$campagne = $request->session()->get('campagne');
|
||||||
|
|
||||||
$ref = $campagne->camp_id;
|
$ref = $campagne->camp_id;
|
||||||
|
|
||||||
|
|
@ -75,495 +67,6 @@ class PanierController extends Controller
|
||||||
->with(['ref' => $ref, 'coupons' => $coupons, 'contact' => $request->session()->get('contact')]);
|
->with(['ref' => $ref, 'coupons' => $coupons, 'contact' => $request->session()->get('contact')]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateBasket(Request $request)
|
|
||||||
{
|
|
||||||
if (isset($request->admin)) {
|
|
||||||
$source = 'ADMIN';
|
|
||||||
} else {
|
|
||||||
$source = 'API';
|
|
||||||
}
|
|
||||||
// ---- INIT du log
|
|
||||||
$log = new Log();
|
|
||||||
$log->log_action = config('constants.updatebasket');
|
|
||||||
$log->log_source = $source;
|
|
||||||
|
|
||||||
if (isset($request->basketid)) {
|
|
||||||
$basketid = $request->basketid;
|
|
||||||
if ($basketid != '') {
|
|
||||||
$panier = Panier::where('panier_ref', $basketid)->first();
|
|
||||||
if (!$panier) {
|
|
||||||
$log->log_params = json_encode(['basketid' => $basketid]);
|
|
||||||
$log->log_statut = 'NOK';
|
|
||||||
$log->log_message = "Le panier n'existe pas";
|
|
||||||
$log->save();
|
|
||||||
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'KO',
|
|
||||||
'Code' => 106,
|
|
||||||
'Message' => 'Le panier n\'existe pas'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($request->panier) && $request->panier != "") {
|
|
||||||
$panier = $request->panier;
|
|
||||||
$panierTab = explode(",", $panier);
|
|
||||||
$coupons = array();
|
|
||||||
foreach ($panierTab as $panier) {
|
|
||||||
$pos = strpos($panier, ")");
|
|
||||||
if ($pos === false || substr_count($panier, ")") != 1) {
|
|
||||||
$log->log_params = json_encode(['basketid' => $basketid, 'panier' => $panier]);
|
|
||||||
$log->log_statut = 'NOK';
|
|
||||||
$log->log_message = "Des paramètres de la requête sont mal renseignés ou non présents";
|
|
||||||
$log->save();
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'KO',
|
|
||||||
'Code' => 101,
|
|
||||||
'Message' => 'Des paramètres de la requête sont mal renseignés ou non présents'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
$quantity = substr($panier, 0, $pos);
|
|
||||||
$quantity = str_replace("(", "", $quantity);
|
|
||||||
$couponCode = substr($panier, $pos + 1);
|
|
||||||
|
|
||||||
if (is_numeric($quantity) && is_numeric($couponCode)) {
|
|
||||||
if (isset($coupons[$couponCode])) {
|
|
||||||
$coupons[$couponCode] = $coupons[$couponCode] + $quantity;
|
|
||||||
} else {
|
|
||||||
$coupons[$couponCode] = $quantity;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$log->log_params = json_encode(['basketid' => $basketid, 'panier' => $panier]);
|
|
||||||
$log->log_statut = 'NOK';
|
|
||||||
$log->log_message = "Des paramètres de la requête sont mal renseignés ou non présents";
|
|
||||||
$log->save();
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'KO',
|
|
||||||
'Code' => 101,
|
|
||||||
'Message' => 'Des paramètres de la requête sont mal renseignés ou non présents'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//---- Préparation message de log avec coupons
|
|
||||||
$panierCoupons = array();
|
|
||||||
foreach ($coupons as $code => $qty) {
|
|
||||||
array_push($panierCoupons, ['cp_code' => $code, 'qty' => $qty]);
|
|
||||||
}
|
|
||||||
if (count($coupons) == 0) {
|
|
||||||
die();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$log->log_params = json_encode(['basketid' => $basketid, 'panier' => $panier]);
|
|
||||||
$log->log_statut = 'NOK';
|
|
||||||
$log->log_message = "Des paramètres de la requête sont mal renseignés ou non présents";
|
|
||||||
$log->save();
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'KO',
|
|
||||||
'Code' => 101,
|
|
||||||
'Message' => 'Des paramètres de la requête sont mal renseignés ou non présents'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---- MAJ du panier
|
|
||||||
$panier = Panier::where('panier_ref', $basketid)->first();
|
|
||||||
if ($panier) {
|
|
||||||
foreach ($coupons as $couponCode => $quantity) {
|
|
||||||
$cp = Coupon::where('coupon_code', $couponCode)->first();
|
|
||||||
$exists = $cp->campagnes->contains($panier->panier_campId);
|
|
||||||
if ($cp && $exists) {
|
|
||||||
$site = $cp->coupon_siteId;
|
|
||||||
$panierContent = PanierContent::where(['panier_content_panierId' => $panier->panier_id, 'panier_content_couponId' => $cp->coupon_id])->first();
|
|
||||||
if ($panierContent) {
|
|
||||||
$quantity += $panierContent->panier_content_quantity;
|
|
||||||
if ($quantity <= 0) {
|
|
||||||
$quantity = 0;
|
|
||||||
}
|
|
||||||
// MAJ du contenu
|
|
||||||
$panierContent->panier_content_quantity = $quantity;
|
|
||||||
$panierContent->save();
|
|
||||||
} else {
|
|
||||||
// Ajout du contenu
|
|
||||||
if ($quantity > 0) {
|
|
||||||
$panierNewContent = new PanierContent();
|
|
||||||
$panierNewContent->panier_content_panierId = $panier->panier_id;
|
|
||||||
$panierNewContent->panier_content_couponId = $cp->coupon_id;
|
|
||||||
$panierNewContent->panier_content_quantity = $quantity;
|
|
||||||
$panierNewContent->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$log->log_params = json_encode(['refcamp' => $request->refcamp, 'refadherent' => $request->refadherent, 'refsite' => $request->refsite, 'nom' => $request->nom, 'prenom' => $request->prenom, 'email' => $request->email, 'code postal' => $request->code_postal, 'commune' => $request->commune, 'panier' => $request->panier]);
|
|
||||||
$log->log_statut = 'NOK';
|
|
||||||
$log->log_message = "Le coupon ne correspond pas aux coupons liés a la campagne";
|
|
||||||
$log->save();
|
|
||||||
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'KO',
|
|
||||||
'Code' => 110,
|
|
||||||
'Message' => 'Le coupon ne correspond pas aux coupons liés a la campagne'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// MAJ du status du panier
|
|
||||||
$qty = $panier->panierContents()->sum('panier_content_quantity');
|
|
||||||
if ($qty == 0) {
|
|
||||||
$panier_pending = 0;
|
|
||||||
} else {
|
|
||||||
$panier_pending = 1;
|
|
||||||
}
|
|
||||||
$panier->panier_pending = $panier_pending;
|
|
||||||
$panier->save();
|
|
||||||
|
|
||||||
$campagne = Campagne::where(['camp_id' => $panier->panier_campId])->first();
|
|
||||||
//var_dump($panier->panier_campId);
|
|
||||||
$log->log_refsite = $campagne->camp_siteId;
|
|
||||||
$log->log_contactId = $panier->panier_contactId;
|
|
||||||
$log->log_params = json_encode(['refcamp' => $panier->panier_campId, 'basketid' => $basketid, 'panier' => $panier]);
|
|
||||||
$log->log_statut = 'OK';
|
|
||||||
$log->log_message = json_encode(['Message' => 'Le panier a bien été créé/mis à jour', 'Coupons' => $panierCoupons], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
|
||||||
$log->save();
|
|
||||||
|
|
||||||
$contact = Contact::where(['contact_id' => $panier->panier_contactId])->first();
|
|
||||||
$site = Site::where(['site_id' => $campagne->camp_siteId])->first();
|
|
||||||
|
|
||||||
if (isset($contact->contact_nom) && isset($site->site_nom)) {
|
|
||||||
if ($panier->panier_pending == 1) {
|
|
||||||
$encours = "oui";
|
|
||||||
} else {
|
|
||||||
$encours = "non";
|
|
||||||
}
|
|
||||||
$response = new \stdClass();
|
|
||||||
$response->Site = $site->site_nom . " (" . $site->site_id . ")";
|
|
||||||
$response->Campagne = $campagne->camp_name . " (" . $campagne->camp_id . ")";
|
|
||||||
$response->Panier = $panier->panier_ref;
|
|
||||||
$response->DateCreation = date("d/m/Y", strtotime($panier->panier_createdate));
|
|
||||||
$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;
|
|
||||||
|
|
||||||
$allPanierContent = $panier->panierContents()->get();
|
|
||||||
foreach ($allPanierContent as $panierContent) {
|
|
||||||
$panCont = [];
|
|
||||||
$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 . ")");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$response->panierContent = $panCont;
|
|
||||||
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'OK',
|
|
||||||
'Panier' => $response
|
|
||||||
]);
|
|
||||||
} else {
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'OK',
|
|
||||||
'Panier' => $panier
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$log->log_params = json_encode(['basketid' => $basketid, 'panier' => $panier]);
|
|
||||||
$log->log_statut = 'NOK';
|
|
||||||
$log->log_message = "Le panier n'existe pas";
|
|
||||||
$log->save();
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'KO',
|
|
||||||
'Code' => 106,
|
|
||||||
'Message' => 'Le panier n\'existe pas'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$log->log_params = json_encode(['basketid' => $basketid, 'panier' => $panier]);
|
|
||||||
$log->log_statut = 'NOK';
|
|
||||||
$log->log_message = "Le panier n'existe pas";
|
|
||||||
$log->save();
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'KO',
|
|
||||||
'Code' => 106,
|
|
||||||
'Message' => 'Le panier n\'existe pas'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// ---- Contrôle des paramètres
|
|
||||||
$error = false;
|
|
||||||
if (isset($request->refcamp) && $request->refcamp != "") {
|
|
||||||
$refcamp = $request->refcamp;
|
|
||||||
$campagne = Campagne::where(['camp_id' => $refcamp])->first();
|
|
||||||
if (!$campagne || $campagne->camp_published->equals(CampaignTypes::mur()) || ($campagne->camp_type->value != 1 && $campagne->camp_type->value != 3)) {
|
|
||||||
$log->log_params = json_encode(['refcamp' => $refcamp]);
|
|
||||||
$log->log_statut = 'NOK';
|
|
||||||
$log->log_message = "La campagne n'existe pas ou n'est pas un panier";
|
|
||||||
$log->save();
|
|
||||||
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'KO',
|
|
||||||
'Code' => 103,
|
|
||||||
'Message' => 'La campagne n\'existe pas ou n\'est pas un panier'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$error = true;
|
|
||||||
}
|
|
||||||
if (isset($request->refadherent) && $request->refadherent != "") {
|
|
||||||
$refadherent = $request->refadherent;
|
|
||||||
} else {
|
|
||||||
$error = true;
|
|
||||||
}
|
|
||||||
if (isset($request->nom) && $request->nom != "") {
|
|
||||||
$nom = $request->nom;
|
|
||||||
} else {
|
|
||||||
$error = true;
|
|
||||||
}
|
|
||||||
if (isset($request->refsite) && $request->refsite != "") {
|
|
||||||
$refsite = $request->refsite;
|
|
||||||
if ($refsite != $campagne->camp_siteId) {
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'KO',
|
|
||||||
'Code' => 103,
|
|
||||||
'Message' => 'La campagne ne correspond à aucune campagnes du site'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$error = true;
|
|
||||||
}
|
|
||||||
if (isset($request->prenom) && $request->prenom != "") {
|
|
||||||
$prenom = $request->prenom;
|
|
||||||
} else {
|
|
||||||
$error = true;
|
|
||||||
}
|
|
||||||
if (isset($request->email) && $request->email != "" && filter_var($request->email, FILTER_VALIDATE_EMAIL)) {
|
|
||||||
$email = $request->email;
|
|
||||||
} else {
|
|
||||||
$error = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($request->code_postal) && $request->code_postal != "") {
|
|
||||||
$code_postal = $request->code_postal;
|
|
||||||
} else {
|
|
||||||
$error = true;
|
|
||||||
}
|
|
||||||
if (isset($request->commune) && $request->commune != "") {
|
|
||||||
$commune = $request->commune;
|
|
||||||
} else {
|
|
||||||
$error = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($request->pays) && $request->pays != "") {
|
|
||||||
if (filter_var($request->pays, FILTER_VALIDATE_INT)) {
|
|
||||||
$pays = $request->pays;
|
|
||||||
} else {
|
|
||||||
$error = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$pays = 250;
|
|
||||||
}
|
|
||||||
if (isset($request->panier) && $request->panier != "") {
|
|
||||||
$panier = $request->panier;
|
|
||||||
$panierTab = explode(",", $panier);
|
|
||||||
$coupons = array();
|
|
||||||
foreach ($panierTab as $panier) {
|
|
||||||
$pos = strpos($panier, ")");
|
|
||||||
if ($pos === false) {
|
|
||||||
$error = true;
|
|
||||||
}
|
|
||||||
$quantity = substr($panier, 0, $pos);
|
|
||||||
$quantity = str_replace("(", "", $quantity);
|
|
||||||
$couponCode = substr($panier, $pos + 1);
|
|
||||||
|
|
||||||
if (is_numeric($quantity) && is_numeric($couponCode) && $quantity > 0) {
|
|
||||||
if (isset($coupons[$couponCode])) {
|
|
||||||
$coupons[$couponCode] = $coupons[$couponCode] + $quantity;
|
|
||||||
} else {
|
|
||||||
$coupons[$couponCode] = $quantity;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (count($coupons) == 0) {
|
|
||||||
die();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$error = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//---- Préparation message de log avec coupons
|
|
||||||
if (isset($coupons)) {
|
|
||||||
$panierCoupons = array();
|
|
||||||
foreach ($coupons as $code => $qty) {
|
|
||||||
array_push($panierCoupons, ['cp_code' => $code, 'qty' => $qty]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if ($error) {
|
|
||||||
$log->log_params = json_encode(['refcamp' => $request->refcamp, 'refadherent' => $request->refadherent, 'refsite' => $request->refsite, 'nom' => $request->nom, 'prenom' => $request->prenom, 'email' => $request->email, 'code postal' => $request->code_postal, 'commune' => $request->commune, 'panier' => $request->panier]);
|
|
||||||
$log->log_statut = 'NOK';
|
|
||||||
$log->log_message = "Des paramètres de la requête sont mal renseignés ou non présents";
|
|
||||||
$log->save();
|
|
||||||
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'KO',
|
|
||||||
'Code' => 101,
|
|
||||||
'Message' => 'Des paramètres de la requête sont mal renseignés ou non présents'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---- Ajout/MAJ du contact
|
|
||||||
$contact = Contact::where(['contact_siteId' => $refsite, 'contact_ref' => $refadherent])->first();
|
|
||||||
if ($contact) {
|
|
||||||
// ---- Mise à jour du contact
|
|
||||||
$contact->contact_prenom = $prenom;
|
|
||||||
$contact->contact_nom = $nom;
|
|
||||||
$contact->contact_email = $email;
|
|
||||||
$contact->contact_cp = $code_postal;
|
|
||||||
$contact->contact_ville = $commune;
|
|
||||||
$contact->contact_country = $pays;
|
|
||||||
$contact->contact_updatedate = date('Y-m-d H:i:s');
|
|
||||||
} else {
|
|
||||||
// ---- Création du contact
|
|
||||||
$site = Site::where('site_id', $refsite)->first();
|
|
||||||
|
|
||||||
if ($site) {
|
|
||||||
$contact = new Contact();
|
|
||||||
$contact->contact_nom = $nom;
|
|
||||||
$contact->contact_prenom = $prenom;
|
|
||||||
$contact->contact_ref = $refadherent;
|
|
||||||
$contact->contact_email = $email;
|
|
||||||
$contact->contact_cp = $code_postal;
|
|
||||||
$contact->contact_ville = $commune;
|
|
||||||
$contact->contact_country = $pays;
|
|
||||||
$contact->contact_siteId = $refsite;
|
|
||||||
$contact->contact_hash = strtoupper(md5(uniqid(time(), true)));
|
|
||||||
} else {
|
|
||||||
$log->log_params = json_encode(['refcamp' => $request->refcamp, 'refadherent' => $request->refadherent, 'refsite' => $request->refsite, 'nom' => $request->nom, 'prenom' => $request->prenom, 'email' => $request->email, 'code postal' => $request->code_postal, 'commune' => $request->commune, 'panier' => $request->panier]);
|
|
||||||
$log->log_statut = 'NOK';
|
|
||||||
$log->log_message = "Le site spécifié n'existe pas";
|
|
||||||
$log->save();
|
|
||||||
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'KO',
|
|
||||||
'Code' => 102,
|
|
||||||
'Message' => 'Le site spécifié n\'existe pas'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!$contact->save()) {
|
|
||||||
$log->log_params = json_encode(['refcamp' => $request->refcamp, 'refadherent' => $request->refadherent, 'refsite' => $request->refsite, 'nom' => $request->nom, 'prenom' => $request->prenom, 'email' => $request->email, 'code postal' => $request->code_postal, 'commune' => $request->commune, 'panier' => $request->panier]);
|
|
||||||
$log->log_statut = 'NOK';
|
|
||||||
$log->log_message = "Une erreur est survenue";
|
|
||||||
$log->save();
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'KO',
|
|
||||||
'Code' => 109,
|
|
||||||
'Message' => 'Une erreur est survenue'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---- Ajout/MAJ du panier
|
|
||||||
$panier = Panier::where(['panier_campId' => $refcamp, 'panier_contactId' => $contact->contact_id, 'panier_pending' => 1])->first();
|
|
||||||
if ($panier) {
|
|
||||||
foreach ($coupons as $couponCode => $quantity) {
|
|
||||||
$camp = Campagne::where('camp_id', $panier->panier_campId)->first();
|
|
||||||
$cp = $camp->coupons()->where('coupon_code', $couponCode)->first();
|
|
||||||
if ($cp) {
|
|
||||||
$panierContent = PanierContent::where(['panier_content_panierId' => $panier->panier_id, 'panier_content_couponId' => $cp->coupon_id])->first();
|
|
||||||
if ($panierContent) {
|
|
||||||
//$quantity += $panierContent->panier_content_quantity;
|
|
||||||
$panierContent->panier_content_quantity = $quantity + $panierContent->panier_content_quantity;
|
|
||||||
// MAJ du contenu
|
|
||||||
$panierContent->save();
|
|
||||||
//$panierContent->update(['panier_content_quantity', $quantity]);
|
|
||||||
} else {
|
|
||||||
// Ajout du contenu
|
|
||||||
if ($quantity > 0) {
|
|
||||||
$panierNewContent = new PanierContent();
|
|
||||||
$panierNewContent->panier_content_panierId = $panier->panier_id;
|
|
||||||
$panierNewContent->panier_content_couponId = $cp->coupon_id;
|
|
||||||
$panierNewContent->panier_content_quantity = $quantity;
|
|
||||||
$panierNewContent->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Ajout du panier et du contenu
|
|
||||||
$panierRef = strtoupper(md5(uniqid(time(), true)));
|
|
||||||
$panier = new Panier();
|
|
||||||
$panier->panier_ref = $panierRef;
|
|
||||||
$panier->panier_campId = $refcamp;
|
|
||||||
$panier->panier_contactId = $contact->contact_id;
|
|
||||||
$panier->panier_createdate = date('Y-m-d H:i:s');
|
|
||||||
$panier->save();
|
|
||||||
|
|
||||||
foreach ($coupons as $couponCode => $quantity) {
|
|
||||||
$cp = $campagne->coupons()->where('coupon_code', $couponCode)->first();
|
|
||||||
if ($cp) {
|
|
||||||
// Ajout du contenu
|
|
||||||
if ($quantity > 0) {
|
|
||||||
$panierNewContent = new PanierContent();
|
|
||||||
$panierNewContent->panier_content_panierId = $panier->panier_id;
|
|
||||||
$panierNewContent->panier_content_couponId = $cp->coupon_id;
|
|
||||||
$panierNewContent->panier_content_quantity = $quantity;
|
|
||||||
$panierNewContent->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$log->log_params = json_encode(['refcamp' => $request->refcamp, 'refadherent' => $request->refadherent, 'refsite' => $request->refsite, 'nom' => $request->nom, 'prenom' => $request->prenom, 'email' => $request->email, 'code postal' => $request->code_postal, 'commune' => $request->commune, 'panier' => $request->panier]);
|
|
||||||
$log->log_contactId = $panier->panier_contactId;
|
|
||||||
$log->log_refsite = $request->refsite;
|
|
||||||
$log->log_statut = 'OK';
|
|
||||||
$log->log_message = json_encode(['Message' => 'Le panier a bien été créé/mis à jour', 'Coupons' => $panierCoupons], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
|
||||||
$log->save();
|
|
||||||
|
|
||||||
$contact = Contact::where(['contact_id' => $panier->panier_contactId])->first();
|
|
||||||
$site = Site::where(['site_id' => $campagne->camp_siteId])->first();
|
|
||||||
|
|
||||||
if (isset($contact->contact_nom) && isset($site->site_nom)) {
|
|
||||||
if ($panier->panier_pending == 1) {
|
|
||||||
$encours = "oui";
|
|
||||||
} else {
|
|
||||||
$encours = "non";
|
|
||||||
}
|
|
||||||
$response = new \stdClass();
|
|
||||||
$response->Site = $site->site_nom . " (" . $site->site_id . ")";
|
|
||||||
$response->Campagne = $campagne->camp_name . " (" . $campagne->camp_id . ")";
|
|
||||||
$response->Panier = $panier->panier_ref;
|
|
||||||
$response->DateCreation = date("d/m/Y", strtotime($panier->panier_createdate));
|
|
||||||
$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;
|
|
||||||
|
|
||||||
$allPanierContent = $panier->panierContents()->get();
|
|
||||||
$panCont = [];
|
|
||||||
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 . ")");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$response->panierContent = $panCont;
|
|
||||||
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'OK',
|
|
||||||
'Panier' => $response
|
|
||||||
]);
|
|
||||||
} else {
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'OK',
|
|
||||||
'Panier' => $panier
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function showBasket(Request $request)
|
public function showBasket(Request $request)
|
||||||
{
|
{
|
||||||
// ---- Contrôle des paramètres
|
// ---- Contrôle des paramètres
|
||||||
|
|
@ -628,18 +131,18 @@ class PanierController extends Controller
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$response = new \stdClass();
|
$response = new \stdClass();
|
||||||
$response->Site = $site->site_nom . " (" . $site->site_id . ")";
|
$response->Site = $site->site_nom . " (" . $site->site_id . ")";
|
||||||
$response->Campagne = $campagne->camp_name . " (" . $campagne->camp_id . ")";
|
$response->Campagne = $campagne->camp_name . " (" . $campagne->camp_id . ")";
|
||||||
$response->Panier = $panier->panier_ref;
|
$response->Panier = $panier->panier_ref;
|
||||||
$response->DateCreation = date("d/m/Y", strtotime($panier->panier_createdate));
|
$response->DateCreation = date("d/m/Y", strtotime($panier->panier_createdate));
|
||||||
$response->EnCours = $encours;
|
$response->EnCours = $encours;
|
||||||
$response->Nom = $contact->contact_nom;
|
$response->Nom = $contact->contact_nom;
|
||||||
$response->Prenom = $contact->contact_prenom;
|
$response->Prenom = $contact->contact_prenom;
|
||||||
$response->Email = $contact->contact_email;
|
$response->Email = $contact->contact_email;
|
||||||
$response->CodePostal = $contact->contact_cp;
|
$response->CodePostal = $contact->contact_cp;
|
||||||
$response->Commune = $contact->contact_ville;
|
$response->Commune = $contact->contact_ville;
|
||||||
$panCont = [];
|
$panCont = [];
|
||||||
foreach ($allPanierContent as $panierContent) {
|
foreach ($allPanierContent as $panierContent) {
|
||||||
$coupon = Coupon::where(['coupon_id' => $panierContent->panier_content_couponId])->first();
|
$coupon = Coupon::where(['coupon_id' => $panierContent->panier_content_couponId])->first();
|
||||||
if ($coupon) {
|
if ($coupon) {
|
||||||
|
|
|
||||||
|
|
@ -10,20 +10,17 @@ class RedirectController extends Controller
|
||||||
/**
|
/**
|
||||||
* Handle the incoming request.
|
* Handle the incoming request.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function __invoke(Request $request)
|
public function __invoke(Request $request)
|
||||||
{
|
{
|
||||||
$mur = new Controllers\MurController();
|
|
||||||
$panier = new Controllers\PanierController();
|
$panier = new Controllers\PanierController();
|
||||||
|
|
||||||
if (isset($request->basketid)) {
|
if (isset($request->basketid)) {
|
||||||
return $panier->showTemplate($request); //$this->showTemplate($request);
|
return $panier->showTemplate($request);
|
||||||
} elseif (isset($request->hash)) {
|
|
||||||
return $mur->show($request);
|
|
||||||
} else {
|
} else {
|
||||||
return redirect()->route('home');
|
return to_route('login');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Site;
|
use App\Models\Site;
|
||||||
use App\User;
|
use App\Models\User;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
|
|
@ -34,7 +34,7 @@ class SiteController extends Controller
|
||||||
/**
|
/**
|
||||||
* Store a newly created resource in storage.
|
* Store a newly created resource in storage.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
|
|
@ -48,13 +48,13 @@ class SiteController extends Controller
|
||||||
'site_libelle' => 'required'
|
'site_libelle' => 'required'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$site = new Site();
|
$site = new Site();
|
||||||
$datas = $this->saveImg($request);
|
$datas = $this->saveImg($request);
|
||||||
$site->site_id = $datas['site_id'];
|
$site->site_id = $datas['site_id'];
|
||||||
$site->site_nom = $datas['site_nom'];
|
$site->site_nom = $datas['site_nom'];
|
||||||
$site->site_contact = $datas['site_contact'];
|
$site->site_contact = $datas['site_contact'];
|
||||||
$site->site_logo = $datas['site_logo'];
|
$site->site_logo = $datas['site_logo'];
|
||||||
$site->site_rcs = $datas['site_rcs'];
|
$site->site_rcs = $datas['site_rcs'];
|
||||||
$site->site_libelle = $datas['site_libelle'];
|
$site->site_libelle = $datas['site_libelle'];
|
||||||
|
|
||||||
$site->save();
|
$site->save();
|
||||||
|
|
@ -65,10 +65,8 @@ class SiteController extends Controller
|
||||||
$admin->sites()->save($site);
|
$admin->sites()->save($site);
|
||||||
}
|
}
|
||||||
// --- MAJ Selecteur marques
|
// --- MAJ Selecteur marques
|
||||||
$marques = Auth::user()->sites;
|
$marques = Auth::user()->sites;
|
||||||
$submarques = $marques->map(function ($marque) {
|
$submarques = $marques->map(fn($marque) => $marque->only(['id', 'site_nom', 'site_id', 'site_logo']));
|
||||||
return $marque->only(['id', 'site_nom', 'site_id', 'site_logo']);
|
|
||||||
});
|
|
||||||
|
|
||||||
session()->put('marques', $submarques);
|
session()->put('marques', $submarques);
|
||||||
|
|
||||||
|
|
@ -78,7 +76,7 @@ class SiteController extends Controller
|
||||||
/**
|
/**
|
||||||
* Show the form for editing the specified resource.
|
* Show the form for editing the specified resource.
|
||||||
*
|
*
|
||||||
* @param \App\Site $site
|
* @param \App\Models\Site $site
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function edit(Site $site)
|
public function edit(Site $site)
|
||||||
|
|
@ -89,8 +87,8 @@ class SiteController extends Controller
|
||||||
/**
|
/**
|
||||||
* Update the specified resource in storage.
|
* Update the specified resource in storage.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
* @param \App\Site $site
|
* @param \App\Models\Site $site
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function update(Request $request, Site $site)
|
public function update(Request $request, Site $site)
|
||||||
|
|
@ -101,11 +99,11 @@ class SiteController extends Controller
|
||||||
session()->flash('update_nok', 'Erreur lors de l\'enregistrement');
|
session()->flash('update_nok', 'Erreur lors de l\'enregistrement');
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect()->route('site.edit', ['site' => $site]);
|
return to_route('site.edit', ['site' => $site]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -1,91 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
|
||||||
|
|
||||||
use App\Campagne;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Support\Facades\Auth;
|
|
||||||
use App\Traits\CouponTrait;
|
|
||||||
use App\Traits\GraphTrait;
|
|
||||||
|
|
||||||
class StatistiqueController extends Controller
|
|
||||||
{
|
|
||||||
use CouponTrait;
|
|
||||||
use GraphTrait;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display a listing of the resource.
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function index()
|
|
||||||
{
|
|
||||||
$sites = Auth::user()->sites()->get();
|
|
||||||
foreach ($sites as $site) {
|
|
||||||
if (isset($site->campagnes)) {
|
|
||||||
$campagnes = $site->campagnes;
|
|
||||||
foreach ($campagnes as $campagne) {
|
|
||||||
foreach ($campagne->coupons as $coupon) {
|
|
||||||
$coupon->quantity = $this->getFullQuantity($coupon);
|
|
||||||
$coupon->remain = $coupon->quantity - $this->getUsedQuantity($coupon);
|
|
||||||
$coupon->diffused = $this->getDiffusedQuantity($coupon);
|
|
||||||
$coupon->isPrintable = $this->isAvailableToPrint($coupon, $campagne);
|
|
||||||
$coupon->isPaused = $this->isPausedToPrint($coupon, $campagne);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return view('stats.index')->with(['sites' => $sites]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show the stat detail of a campaign.
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function statdetail(Campagne $campagne)
|
|
||||||
{
|
|
||||||
$count = 0;
|
|
||||||
$colors = config('constants.colors');
|
|
||||||
|
|
||||||
$coupons = $campagne->coupons;
|
|
||||||
foreach ($coupons as $coupon) {
|
|
||||||
$coupon->quantity = $this->getFullQuantity($coupon);
|
|
||||||
$coupon->remain = $coupon->quantity - $this->getUsedQuantity($coupon);
|
|
||||||
$coupon->diffused = $this->getDiffusedQuantity($coupon);
|
|
||||||
$coupon->isPrintable = $this->isAvailableToPrint($coupon, $campagne);
|
|
||||||
$coupon->isPaused = $this->isPausedToPrint($coupon, $campagne);
|
|
||||||
$coupon->color = $coupon->color = "#" . str_pad(dechex(mt_rand(0, 255)), 2, '0', STR_PAD_LEFT) . str_pad(dechex(mt_rand(0, 255)), 2, '0', STR_PAD_LEFT) . str_pad(dechex(mt_rand(0, 255)), 2, '0', STR_PAD_LEFT);
|
|
||||||
$count++;
|
|
||||||
}
|
|
||||||
$enddate = date('Y-m-d');
|
|
||||||
$startdate = date('Y-m-d', strtotime("-30 days"));
|
|
||||||
return view('stats.detail')->with(['campagne' => $campagne, 'startdate' => $startdate, 'enddate' => $enddate]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function loadStats(Request $request)
|
|
||||||
{
|
|
||||||
$campid = $request->campid;
|
|
||||||
$startdate = $request->startdate;
|
|
||||||
$enddate = $request->enddate;
|
|
||||||
|
|
||||||
// ---- Labels pour la période
|
|
||||||
$labels = $this->getLabelsForStats($startdate, $enddate);
|
|
||||||
|
|
||||||
// ---- Data pour le graphique global
|
|
||||||
$dataGlobal = $this->getDataForCamp($labels, $campid);
|
|
||||||
|
|
||||||
// ---- Data pour le graphique par coupons
|
|
||||||
$campagne = Campagne::where(['camp_id' => $campid])->first();
|
|
||||||
$coupons = $campagne->coupons;
|
|
||||||
$dataSpec = [];
|
|
||||||
foreach ($coupons as $coupon) {
|
|
||||||
$dataCoupon = $this->getDataForCoupon($labels, $campid, $coupon);
|
|
||||||
$dataSpec[$coupon->coupon_code] = $dataCoupon;
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = array('labels' => $labels, 'dataGlobal' => $dataGlobal, 'dataSpec' => $dataSpec);
|
|
||||||
|
|
||||||
return json_encode($data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -6,7 +6,6 @@ use Illuminate\Foundation\Http\Kernel as HttpKernel;
|
||||||
|
|
||||||
class Kernel extends HttpKernel
|
class Kernel extends HttpKernel
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The application's global HTTP middleware stack.
|
* The application's global HTTP middleware stack.
|
||||||
*
|
*
|
||||||
|
|
@ -51,7 +50,7 @@ class Kernel extends HttpKernel
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $routeMiddleware = [
|
protected $middlewareAliases = [
|
||||||
'auth' => \App\Http\Middleware\Authenticate::class,
|
'auth' => \App\Http\Middleware\Authenticate::class,
|
||||||
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
|
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
|
||||||
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
|
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||||
|
|
@ -61,11 +60,7 @@ class Kernel extends HttpKernel
|
||||||
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
|
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
|
||||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||||
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
|
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
|
||||||
'process.url' => \App\Http\Middleware\ProcessSpecificUrl::class,
|
|
||||||
'saveroute' => \App\Http\Middleware\SaveCurrentRoute::class,
|
'saveroute' => \App\Http\Middleware\SaveCurrentRoute::class,
|
||||||
'superadmin' => \App\Http\Middleware\SuperAdmin::class,
|
|
||||||
'admin' => \App\Http\Middleware\Admin::class,
|
|
||||||
'marketing' => \App\Http\Middleware\Marketing::class,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Middleware;
|
|
||||||
|
|
||||||
use Auth;
|
|
||||||
use Closure;
|
|
||||||
|
|
||||||
class Admin
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Handle an incoming request.
|
|
||||||
*
|
|
||||||
* @param \Illuminate\Http\Request $request
|
|
||||||
* @param \Closure $next
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function handle($request, Closure $next)
|
|
||||||
{
|
|
||||||
if (Auth::check() && Auth::user()->roles == 'admin') {
|
|
||||||
return $next($request);
|
|
||||||
} elseif (Auth::check() && Auth::user()->roles == 'superadmin') {
|
|
||||||
return $next($request);
|
|
||||||
} else {
|
|
||||||
return redirect('/bo/home');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -9,7 +9,7 @@ class Authenticate extends Middleware
|
||||||
/**
|
/**
|
||||||
* Get the path the user should be redirected to when they are not authenticated.
|
* Get the path the user should be redirected to when they are not authenticated.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function redirectTo($request)
|
protected function redirectTo($request)
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,12 @@ use Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode as Middleware;
|
||||||
|
|
||||||
class CheckForMaintenanceMode extends Middleware
|
class CheckForMaintenanceMode extends Middleware
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The URIs that should be reachable while maintenance mode is enabled.
|
* The URIs that should be reachable while maintenance mode is enabled.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected $except = [
|
protected $except = [
|
||||||
//
|
];
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,12 @@ use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
|
||||||
|
|
||||||
class EncryptCookies extends Middleware
|
class EncryptCookies extends Middleware
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The names of the cookies that should not be encrypted.
|
* The names of the cookies that should not be encrypted.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected $except = [
|
protected $except = [
|
||||||
//
|
];
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Middleware;
|
|
||||||
|
|
||||||
use Closure;
|
|
||||||
|
|
||||||
class Marketing
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Handle an incoming request.
|
|
||||||
*
|
|
||||||
* @param \Illuminate\Http\Request $request
|
|
||||||
* @param \Closure $next
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function handle($request, Closure $next)
|
|
||||||
{
|
|
||||||
return $next($request);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,96 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Middleware;
|
|
||||||
|
|
||||||
use Closure;
|
|
||||||
use App\Http\Controllers;
|
|
||||||
|
|
||||||
class ProcessSpecificUrl
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Handle an incoming request.
|
|
||||||
*
|
|
||||||
* @param \Illuminate\Http\Request $request
|
|
||||||
* @param \Closure $next
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function handle($request, Closure $next)
|
|
||||||
{
|
|
||||||
$path = $request->path();
|
|
||||||
$params = $request->all();
|
|
||||||
$paramsCount = count($params);
|
|
||||||
$contact = new Controllers\ContactController();
|
|
||||||
$mur = new Controllers\MurController();
|
|
||||||
$panier = new Controllers\PanierController();
|
|
||||||
$campagne = new Controllers\CampagneController();
|
|
||||||
$ajax = new Controllers\AjaxController();
|
|
||||||
switch ($path) {
|
|
||||||
case 'updatecontact':
|
|
||||||
$res = $contact->updateContact($request);
|
|
||||||
break;
|
|
||||||
case 'delctrlcontact':
|
|
||||||
$res = $mur->deleteControlContact($request);
|
|
||||||
break;
|
|
||||||
case 'mntdispocampagne':
|
|
||||||
$res = $mur->montantDispoCampagne($request);
|
|
||||||
break;
|
|
||||||
case 'mntdispocontact':
|
|
||||||
$res = $mur->montantDispoContact($request);
|
|
||||||
break;
|
|
||||||
case 'updatebasket':
|
|
||||||
$res = $panier->updateBasket($request);
|
|
||||||
break;
|
|
||||||
case 'showbasket':
|
|
||||||
$res = $panier->showBasket($request);
|
|
||||||
break;
|
|
||||||
case 'getdetailcampaign':
|
|
||||||
$res = $campagne->getDetail($request);
|
|
||||||
break;
|
|
||||||
case 'getdiffctccampaign':
|
|
||||||
$res = $campagne->getDiffCamp($request);
|
|
||||||
break;
|
|
||||||
case 'imprime':
|
|
||||||
$res = $panier->printPanierSelect($request);
|
|
||||||
return $next($request);
|
|
||||||
break;
|
|
||||||
case 'imprimer':
|
|
||||||
$res = $mur->printMur($request);
|
|
||||||
return $next($request);
|
|
||||||
break;
|
|
||||||
case 'merci':
|
|
||||||
$res = $mur->getThanks($request);
|
|
||||||
return $next($request);
|
|
||||||
break;
|
|
||||||
case 'merci-panier':
|
|
||||||
$res = $panier->getThanks($request);
|
|
||||||
return $next($request);
|
|
||||||
break;
|
|
||||||
case 'index':
|
|
||||||
$res = $ajax->backToIndex($request);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
switch ($paramsCount) {
|
|
||||||
case 0:
|
|
||||||
return redirect('bo/home');
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
$res = $panier->showTemplate($request);
|
|
||||||
return $next($request);
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
$res = $mur->show($request);
|
|
||||||
return $next($request);
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
$res = $mur->show($request);
|
|
||||||
return $next($request);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $res;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -10,15 +10,15 @@ class RedirectIfAuthenticated
|
||||||
/**
|
/**
|
||||||
* Handle an incoming request.
|
* Handle an incoming request.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
* @param \Closure $next
|
* @param \Closure $next
|
||||||
* @param string|null $guard
|
* @param string|null $guard
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function handle($request, Closure $next, $guard = null)
|
public function handle($request, Closure $next, $guard = null)
|
||||||
{
|
{
|
||||||
if (Auth::guard($guard)->check()) {
|
if (Auth::guard($guard)->check()) {
|
||||||
return redirect()->route('home');
|
return to_route('campagne.index');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $next($request);
|
return $next($request);
|
||||||
|
|
|
||||||
|
|
@ -2,40 +2,34 @@
|
||||||
|
|
||||||
namespace App\Http\Middleware;
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
use Auth;
|
|
||||||
use Closure;
|
use Closure;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
class SaveCurrentRoute
|
class SaveCurrentRoute
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Handle an incoming request.
|
* Handle an incoming request.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
* @param \Closure $next
|
* @param \Closure $next
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function handle($request, Closure $next)
|
public function handle($request, Closure $next)
|
||||||
{
|
{
|
||||||
$routeName = explode('.', \Route::currentRouteName());
|
|
||||||
|
|
||||||
session()->put('active_route', $routeName[0]);
|
|
||||||
|
|
||||||
$site = session()->get('site');
|
$site = session()->get('site');
|
||||||
|
|
||||||
if (!isset($site)) {
|
|
||||||
session()->put('site', Auth::user()->sites->first());
|
|
||||||
}
|
|
||||||
|
|
||||||
$currentLogo = session()->get('site')->only(['site_logo']);
|
|
||||||
session()->put('current_logo', $currentLogo);
|
|
||||||
$siteId = session()->get('marques');
|
$siteId = session()->get('marques');
|
||||||
|
|
||||||
if (!isset($siteId)) {
|
if (!$site) {
|
||||||
$marques = Auth::user()->sites;
|
$site = Auth::user()->sites->first();
|
||||||
$submarques = $marques->map(function ($marque) {
|
session()->put('site', $site);
|
||||||
return $marque->only(['id', 'site_nom', 'site_id', 'site_logo']);
|
}
|
||||||
});
|
|
||||||
|
|
||||||
|
$currentLogo = $site->only(['site_logo']);
|
||||||
|
session()->put('current_logo', $currentLogo);
|
||||||
|
|
||||||
|
if (!$siteId) {
|
||||||
|
$marques = Auth::user()->sites;
|
||||||
|
$submarques = $marques->map(fn($marque) => $marque->only(['id', 'site_nom', 'site_id', 'site_logo']));
|
||||||
session()->put('marques', $submarques);
|
session()->put('marques', $submarques);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Middleware;
|
|
||||||
|
|
||||||
use Auth;
|
|
||||||
use Closure;
|
|
||||||
|
|
||||||
class SuperAdmin
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Handle an incoming request.
|
|
||||||
*
|
|
||||||
* @param \Illuminate\Http\Request $request
|
|
||||||
* @param \Closure $next
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function handle($request, Closure $next)
|
|
||||||
{
|
|
||||||
if (Auth::check() && Auth::user()->roles == 'superadmin') {
|
|
||||||
return $next($request);
|
|
||||||
} else {
|
|
||||||
return redirect('/bo/home');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -6,12 +6,12 @@ use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;
|
||||||
|
|
||||||
class TrimStrings extends Middleware
|
class TrimStrings extends Middleware
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The names of the attributes that should not be trimmed.
|
* The names of the attributes that should not be trimmed.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected $except = [
|
protected $except = [
|
||||||
'password',
|
'password',
|
||||||
'password_confirmation',
|
'password_confirmation',
|
||||||
|
|
|
||||||
21
app/Http/Middleware/TrustHosts.php
Normal file
21
app/Http/Middleware/TrustHosts.php
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Illuminate\Http\Middleware\TrustHosts as Middleware;
|
||||||
|
|
||||||
|
class TrustHosts extends Middleware
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get the host patterns that should be trusted.
|
||||||
|
*
|
||||||
|
* @return array<int, string|null>
|
||||||
|
*/
|
||||||
|
public function hosts()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
$this->allSubdomainsOfApplicationUrl(),
|
||||||
|
config('app.k8s_internal_host'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,11 +3,10 @@
|
||||||
namespace App\Http\Middleware;
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Fideloper\Proxy\TrustProxies as Middleware;
|
use Illuminate\Http\Middleware\TrustProxies as Middleware;
|
||||||
|
|
||||||
class TrustProxies extends Middleware
|
class TrustProxies extends Middleware
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The trusted proxies for this application.
|
* The trusted proxies for this application.
|
||||||
*
|
*
|
||||||
|
|
@ -18,7 +17,12 @@ class TrustProxies extends Middleware
|
||||||
/**
|
/**
|
||||||
* The headers that should be used to detect proxies.
|
* The headers that should be used to detect proxies.
|
||||||
*
|
*
|
||||||
* @var int
|
* @var integer
|
||||||
*/
|
*/
|
||||||
protected $headers = Request::HEADER_X_FORWARDED_ALL;
|
protected $headers =
|
||||||
|
Request::HEADER_X_FORWARDED_FOR |
|
||||||
|
Request::HEADER_X_FORWARDED_HOST |
|
||||||
|
Request::HEADER_X_FORWARDED_PORT |
|
||||||
|
Request::HEADER_X_FORWARDED_PROTO |
|
||||||
|
Request::HEADER_X_FORWARDED_AWS_ELB;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,14 +4,14 @@ namespace App\Http\Middleware;
|
||||||
|
|
||||||
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
|
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
|
||||||
|
|
||||||
class VerifyCsrfToken extends Middleware
|
class VerifyCsrfToken extends \Illuminate\Foundation\Http\Middleware\PreventRequestForgery
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates whether the XSRF-TOKEN cookie should be set on the response.
|
* Indicates whether the XSRF-TOKEN cookie should be set on the response.
|
||||||
*
|
*
|
||||||
* @var bool
|
* @var boolean
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected $addHttpCookie = true;
|
protected $addHttpCookie = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -19,10 +19,10 @@ class VerifyCsrfToken extends Middleware
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected $except = [
|
protected $except = [
|
||||||
'updatecontact',
|
'updatecontact',
|
||||||
'updatebasket',
|
'updatebasket',
|
||||||
'showbasket',
|
'showbasket',
|
||||||
'delctrlcontact'
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Requests\Contact;
|
namespace App\Http\Requests\Bo\Users;
|
||||||
|
|
||||||
use App\Enums\UserRoles;
|
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
class LoadWidgetContact extends FormRequest
|
class DestroyUserRequest extends FormRequest
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Determine if the user is authorized to make this request.
|
* Determine if the user is authorized to make this request.
|
||||||
|
|
@ -15,7 +14,7 @@ class LoadWidgetContact extends FormRequest
|
||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize()
|
||||||
{
|
{
|
||||||
return Auth::check() && (Auth::user()->roles === UserRoles::superadmin()->value || Auth::user()->roles === UserRoles::admin()->value);
|
return Auth::check();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -26,7 +25,7 @@ class LoadWidgetContact extends FormRequest
|
||||||
public function rules()
|
public function rules()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'camp_id' => 'required|exists:campagne,camp_id'
|
//
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,12 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Requests\Users;
|
namespace App\Http\Requests\Bo\Users;
|
||||||
|
|
||||||
use App\Enums\UserRoles;
|
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
class StoreUsers extends FormRequest
|
class StoreUserRequest extends FormRequest
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Determine if the user is authorized to make this request.
|
* Determine if the user is authorized to make this request.
|
||||||
|
|
@ -15,7 +14,7 @@ class StoreUsers extends FormRequest
|
||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize()
|
||||||
{
|
{
|
||||||
return Auth::check() && (Auth::user()->roles === UserRoles::superadmin()->value || Auth::user()->roles === UserRoles::admin()->value);
|
return Auth::check();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -1,13 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Requests\Users;
|
namespace App\Http\Requests\Bo\Users;
|
||||||
|
|
||||||
use App\Enums\UserRoles;
|
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
class UpdateUsers extends FormRequest
|
class UpdateUserRequest extends FormRequest
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Determine if the user is authorized to make this request.
|
* Determine if the user is authorized to make this request.
|
||||||
|
|
@ -16,7 +15,7 @@ class UpdateUsers extends FormRequest
|
||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize()
|
||||||
{
|
{
|
||||||
return Auth::check() && (Auth::user()->roles === UserRoles::superadmin()->value || Auth::user()->roles === UserRoles::admin()->value);
|
return Auth::check();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -30,9 +30,7 @@ class StoreNotifCampaign extends FormRequest
|
||||||
'notif_name' => 'min:5|required',
|
'notif_name' => 'min:5|required',
|
||||||
'notif_email' => [
|
'notif_email' => [
|
||||||
'required',
|
'required',
|
||||||
Rule::unique('notification')->where(function ($query) {
|
Rule::unique('notification')->where(fn($query) => $query->where('notif_campId', $this->campaign->camp_id)),
|
||||||
return $query->where('notif_campId', $this->campaign->camp_id);
|
|
||||||
}),
|
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Requests\Contact;
|
|
||||||
|
|
||||||
use App\Enums\UserRoles;
|
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
|
||||||
use Illuminate\Support\Facades\Auth;
|
|
||||||
|
|
||||||
class SearchContact extends FormRequest
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Determine if the user is authorized to make this request.
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function authorize()
|
|
||||||
{
|
|
||||||
return Auth::check() && (Auth::user()->roles === UserRoles::superadmin()->value || Auth::user()->roles === UserRoles::admin()->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the validation rules that apply to the request.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function rules()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'page' => 'sometimes|integer|nullable',
|
|
||||||
'searchName' => 'sometimes|alpha|max:50|nullable',
|
|
||||||
'searchFirstname' => 'sometimes|alpha|max:50|nullable',
|
|
||||||
'searchEmail' => 'sometimes|email|max:100|nullable',
|
|
||||||
'searchCp' => 'sometimes|integer|max:10|nullable',
|
|
||||||
'searchVille' => 'sometimes|alpha|max:50|nullable',
|
|
||||||
'searchCountry' => 'sometimes|integer|nullable',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Requests\Contact;
|
|
||||||
|
|
||||||
use App\Enums\UserRoles;
|
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
|
||||||
use Illuminate\Support\Facades\Auth;
|
|
||||||
|
|
||||||
class StoreContact extends FormRequest
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Determine if the user is authorized to make this request.
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function authorize()
|
|
||||||
{
|
|
||||||
return Auth::check() && (Auth::user()->roles === UserRoles::superadmin()->value || Auth::user()->roles === UserRoles::admin()->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the validation rules that apply to the request.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function rules()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'contact_ref' => 'required|unique:contact',
|
|
||||||
'contact_nom' => 'min:3|max:50|required',
|
|
||||||
'contact_prenom' => 'min:3|max:50|required',
|
|
||||||
'contact_email' => 'email|required',
|
|
||||||
'contact_cp' => 'max:10|required',
|
|
||||||
'contact_ville' => 'max:50|required',
|
|
||||||
'contact_country' => 'integer|required'
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,42 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Requests\Contact;
|
|
||||||
|
|
||||||
use App\Enums\UserRoles;
|
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
|
||||||
use Illuminate\Support\Facades\Auth;
|
|
||||||
use Illuminate\Validation\Rule;
|
|
||||||
|
|
||||||
class UpdateContact extends FormRequest
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Determine if the user is authorized to make this request.
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function authorize()
|
|
||||||
{
|
|
||||||
return Auth::check() && (Auth::user()->roles === UserRoles::superadmin()->value || Auth::user()->roles === UserRoles::admin()->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the validation rules that apply to the request.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function rules()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'contact_ref' => [
|
|
||||||
'required',
|
|
||||||
Rule::unique('contact')->ignore($this->contact->contact_id, 'contact_id'),
|
|
||||||
],
|
|
||||||
'contact_nom' => 'min:3|max:50|required',
|
|
||||||
'contact_prenom' => 'min:3|max:50|required',
|
|
||||||
'contact_email' => 'email|required',
|
|
||||||
'contact_cp' => 'max:10|required',
|
|
||||||
'contact_ville' => 'max:50|required',
|
|
||||||
'contact_country' => 'integer|required'
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -12,7 +12,7 @@ class PrintRequest extends FormRequest
|
||||||
/**
|
/**
|
||||||
* Determine if the user is authorized to make this request.
|
* Determine if the user is authorized to make this request.
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize()
|
||||||
{
|
{
|
||||||
|
|
@ -30,7 +30,8 @@ class PrintRequest extends FormRequest
|
||||||
return [
|
return [
|
||||||
'refcamp' => 'string|exists:campagne,camp_id|required',
|
'refcamp' => 'string|exists:campagne,camp_id|required',
|
||||||
'hashcode' => 'string|exists:customers,hashcode|required',
|
'hashcode' => 'string|exists:customers,hashcode|required',
|
||||||
'coupons' => 'required'
|
'coupons' => 'required',
|
||||||
|
'type' => 'nullable|in:stream,dl'
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,21 +55,15 @@ class StoreCoupons extends FormRequest
|
||||||
/**
|
/**
|
||||||
* Configure the validator instance.
|
* Configure the validator instance.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Validation\Validator $validator
|
* @param \Illuminate\Contracts\Validation\Validator $validator
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function withValidator($validator)
|
public function withValidator($validator)
|
||||||
{
|
{
|
||||||
$validator->sometimes('coupon_gs1code', 'required|image|mimes:jpeg', function ($input) {
|
$validator->sometimes('coupon_gs1code', 'required|image|mimes:jpeg', fn($input) => isset($input->coupon_norme));
|
||||||
return isset($input->coupon_norme);
|
|
||||||
});
|
|
||||||
|
|
||||||
$validator->sometimes('coupon_limitquantity', 'integer|required', function ($input) {
|
$validator->sometimes('coupon_limitquantity', 'integer|required', fn($input) => !is_null($input->coupon_enablelimitquantity));
|
||||||
return !is_null($input->coupon_enablelimitquantity);
|
|
||||||
});
|
|
||||||
|
|
||||||
$validator->sometimes('coupon_limitperiod', 'integer|required', function ($input) {
|
$validator->sometimes('coupon_limitperiod', 'integer|required', fn($input) => !is_null($input->coupon_enablelimitperiod));
|
||||||
return !is_null($input->coupon_enablelimitperiod);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ class UpdateCoupons extends FormRequest
|
||||||
/**
|
/**
|
||||||
* Configure the validator instance.
|
* Configure the validator instance.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Validation\Validator $validator
|
* @param \Illuminate\Contracts\Validation\Validator $validator
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function withValidator($validator)
|
public function withValidator($validator)
|
||||||
|
|
@ -71,12 +71,8 @@ class UpdateCoupons extends FormRequest
|
||||||
return isset($input->coupon_norme);
|
return isset($input->coupon_norme);
|
||||||
});
|
});
|
||||||
|
|
||||||
$validator->sometimes('coupon_limitquantity', 'integer|required', function ($input) {
|
$validator->sometimes('coupon_limitquantity', 'integer|required', fn($input) => !is_null($input->coupon_enablelimitquantity));
|
||||||
return !is_null($input->coupon_enablelimitquantity);
|
|
||||||
});
|
|
||||||
|
|
||||||
$validator->sometimes('coupon_limitperiod', 'integer|required', function ($input) {
|
$validator->sometimes('coupon_limitperiod', 'integer|required', fn($input) => !is_null($input->coupon_enablelimitperiod));
|
||||||
return !is_null($input->coupon_enablelimitperiod);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
45
app/Http/Requests/Customers/BasketRequest.php
Normal file
45
app/Http/Requests/Customers/BasketRequest.php
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Customers;
|
||||||
|
|
||||||
|
use App\Http\Resources\StatusResource;
|
||||||
|
use Illuminate\Contracts\Validation\Validator;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
use Illuminate\Http\Exceptions\HttpResponseException;
|
||||||
|
|
||||||
|
class BasketRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'refcamp' => 'string|exists:campagne,camp_id|required',
|
||||||
|
'hashcode' => 'string|exists:customers,hashcode|required'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function failedValidation(Validator $validator)
|
||||||
|
{
|
||||||
|
if ($this->wantsJson()) {
|
||||||
|
throw new HttpResponseException(response()->json(new StatusResource([
|
||||||
|
'status' => 'KO',
|
||||||
|
'code' => 422,
|
||||||
|
'message' => $validator->errors()->messages()
|
||||||
|
]), 422));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -12,7 +12,7 @@ class MurRequest extends FormRequest
|
||||||
/**
|
/**
|
||||||
* Determine if the user is authorized to make this request.
|
* Determine if the user is authorized to make this request.
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ class StoreRequest extends FormRequest
|
||||||
/**
|
/**
|
||||||
* Determine if the user is authorized to make this request.
|
* Determine if the user is authorized to make this request.
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
41
app/Http/Requests/Fo/Basket/PrintRequest.php
Normal file
41
app/Http/Requests/Fo/Basket/PrintRequest.php
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Fo\Basket;
|
||||||
|
|
||||||
|
use App\Enums\CampaignTypes;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class PrintRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: Docblock
|
||||||
|
protected function prepareForValidation()
|
||||||
|
{
|
||||||
|
$campagne = $this->basket->campagne;
|
||||||
|
|
||||||
|
throw_unless($campagne->camp_type->equals(CampaignTypes::panier()), \Exception::class, 'Campaign is not basket.');
|
||||||
|
|
||||||
|
throw_if($campagne->camp_published === 0, \Exception::class, 'Campaign is not published.');
|
||||||
|
throw_if($campagne->site->crm_token === null, \Exception::class, 'CRM Token is missing.');
|
||||||
|
throw_if($campagne->site->crm_password === null, \Exception::class, 'CRM Password is missing.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -12,7 +12,7 @@ class MursShowRequest extends FormRequest
|
||||||
/**
|
/**
|
||||||
* Determine if the user is authorized to make this request.
|
* Determine if the user is authorized to make this request.
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -9,21 +9,29 @@ class CouponsResource extends JsonResource
|
||||||
/**
|
/**
|
||||||
* Transform the resource collection into an array.
|
* Transform the resource collection into an array.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function toArray($request)
|
public function toArray($request)
|
||||||
{
|
{
|
||||||
return [
|
$coupon = [
|
||||||
'code' => $this->coupon_code,
|
'code' => $this->coupon_code,
|
||||||
'name' => $this->coupon_name,
|
'name' => $this->coupon_name,
|
||||||
'value' => $this->coupon_value,
|
'value' => $this->coupon_value,
|
||||||
'used' => isset($this->isUsed) ? $this->isUsed : false,
|
'used' => $this->isUsed ?? false,
|
||||||
'desktop_image_available' => $this->returnUrl($this->coupon_thumbnail1),
|
'desktop_image_available' => $this->returnUrl($this->coupon_thumbnail1),
|
||||||
'desktop_image_unavailable' => $this->returnUrl($this->coupon_thumbnail2),
|
'desktop_image_unavailable' => $this->returnUrl($this->coupon_thumbnail2),
|
||||||
'mobile_image_available' => $this->returnUrl($this->coupon_thumbnail3),
|
'mobile_image_available' => $this->returnUrl($this->coupon_thumbnail3),
|
||||||
'mobile_image_unavailable' => $this->returnUrl($this->coupon_thumbnail4)
|
'mobile_image_unavailable' => $this->returnUrl($this->coupon_thumbnail4),
|
||||||
|
'validity_text' => $this->coupon_validity_text
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if (isset($this->isUsed)){
|
||||||
|
return array_merge($coupon, [
|
||||||
|
'used' => $this->isUsed,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
return $coupon;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function returnUrl($assets)
|
private function returnUrl($assets)
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ class CustomersResource extends JsonResource
|
||||||
/**
|
/**
|
||||||
* Transform the resource into an array.
|
* Transform the resource into an array.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
* @return StatusResource
|
* @return StatusResource
|
||||||
*/
|
*/
|
||||||
public function toArray($request)
|
public function toArray($request)
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ class StatusResource extends JsonResource
|
||||||
/**
|
/**
|
||||||
* Transform the resource into an array.
|
* Transform the resource into an array.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function toArray($request)
|
public function toArray($request)
|
||||||
|
|
|
||||||
67
app/Jobs/ArchiveStatsJob.php
Normal file
67
app/Jobs/ArchiveStatsJob.php
Normal file
|
|
@ -0,0 +1,67 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs;
|
||||||
|
|
||||||
|
use App\Models\ArchiveStat;
|
||||||
|
use App\Models\Statistique;
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
class ArchiveStatsJob implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Dispatchable;
|
||||||
|
use InteractsWithQueue;
|
||||||
|
use Queueable;
|
||||||
|
use SerializesModels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new job instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
// Construct method.
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the job.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
DB::transaction(function (): void {
|
||||||
|
Statistique::query()
|
||||||
|
->where('date', '<', now())
|
||||||
|
->each(function ($stat): void {
|
||||||
|
$archiveStat = new ArchiveStat();
|
||||||
|
$archiveStat->quantity = $stat->stat_couponPrinted;
|
||||||
|
$archiveStat->date = $stat->date;
|
||||||
|
$archiveStat->archive_coupon_id = $stat->stat_couponId;
|
||||||
|
$archiveStat->archive_campaign_id = $stat->stat_campId;
|
||||||
|
$archiveStat->saveOrFail();
|
||||||
|
});
|
||||||
|
|
||||||
|
Statistique::query()
|
||||||
|
->where('date', '<', now())
|
||||||
|
->delete();
|
||||||
|
});
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Log::error(
|
||||||
|
sprintf(
|
||||||
|
"ArchiveStatsJob failed - Code : %s - %s",
|
||||||
|
$e->getCode(),
|
||||||
|
$e->getMessage(),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
\report($e);
|
||||||
|
} //end try
|
||||||
|
}
|
||||||
|
}
|
||||||
81
app/Jobs/CleanOldDatasJob.php
Normal file
81
app/Jobs/CleanOldDatasJob.php
Normal file
|
|
@ -0,0 +1,81 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs;
|
||||||
|
|
||||||
|
use App\Models\Contact;
|
||||||
|
use App\Models\Log as LogModel;
|
||||||
|
use App\Models\Customers;
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
class CleanOldDatasJob implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Dispatchable;
|
||||||
|
use InteractsWithQueue;
|
||||||
|
use Queueable;
|
||||||
|
use SerializesModels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new job instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
// Construct method.
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the job.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
|
||||||
|
try {
|
||||||
|
DB::transaction(function (): void {
|
||||||
|
// Delete old contacts.
|
||||||
|
$deletedContact = Contact::query()
|
||||||
|
->where('contact_updatedate', '<', now()->subYears(3))
|
||||||
|
->delete();
|
||||||
|
Log::info(\sprintf(
|
||||||
|
'CleanOldDatasJob : %s contacts deleted',
|
||||||
|
$deletedContact
|
||||||
|
));
|
||||||
|
|
||||||
|
// Delete old customers.
|
||||||
|
$deletedCustomers = Customers::query()
|
||||||
|
->where('updated_at', '<', now()->subYears(3))
|
||||||
|
->delete();
|
||||||
|
Log::info(\sprintf(
|
||||||
|
'CleanOldDatasJob : %s customers deleted',
|
||||||
|
$deletedCustomers
|
||||||
|
));
|
||||||
|
|
||||||
|
// Delete old logs.
|
||||||
|
$deletedLogs = LogModel::query()
|
||||||
|
->where('created_at', '<', now()->subYears(3))
|
||||||
|
->delete();
|
||||||
|
Log::info(\sprintf(
|
||||||
|
'CleanOldDatasJob : %s logs deleted',
|
||||||
|
$deletedLogs
|
||||||
|
));
|
||||||
|
});
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Log::error(
|
||||||
|
sprintf(
|
||||||
|
"CleanOldDatasJob failed - Code : %s - %s",
|
||||||
|
$e->getCode(),
|
||||||
|
$e->getMessage(),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
\report($e);
|
||||||
|
} //end try
|
||||||
|
}
|
||||||
|
}
|
||||||
103
app/Jobs/DeleteCrmCustomerJob.php
Normal file
103
app/Jobs/DeleteCrmCustomerJob.php
Normal file
|
|
@ -0,0 +1,103 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs;
|
||||||
|
|
||||||
|
use App\Models\Contact;
|
||||||
|
use App\Models\Customers;
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
class DeleteCrmCustomerJob implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Dispatchable;
|
||||||
|
use InteractsWithQueue;
|
||||||
|
use Queueable;
|
||||||
|
use SerializesModels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new job instance.
|
||||||
|
*
|
||||||
|
* @param array $customer
|
||||||
|
*/
|
||||||
|
public function __construct(private $customer)
|
||||||
|
{
|
||||||
|
$this->onConnection('rabbitmq');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the job.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$hashchode = $this->customer['hashcode'];
|
||||||
|
$email = $this->customer['email'];
|
||||||
|
|
||||||
|
try {
|
||||||
|
DB::transaction(function () use ($hashchode, $email): void {
|
||||||
|
// For baskets and old walls.
|
||||||
|
$contact = Contact::query()->where('contact_ref', $hashchode)->first();
|
||||||
|
if ($contact) {
|
||||||
|
$contact->deleteOrFail();
|
||||||
|
|
||||||
|
$this->writeCsvLog('Contact deleted');
|
||||||
|
}
|
||||||
|
|
||||||
|
// For walls.
|
||||||
|
$customer = Customers::query()->where('hashcode', $hashchode)->first();
|
||||||
|
if ($customer) {
|
||||||
|
$customer->deleteOrFail();
|
||||||
|
|
||||||
|
$this->writeCsvLog('Customer deleted');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Log::info(
|
||||||
|
sprintf(
|
||||||
|
"DeleteCrmCustomerJob failed - Code : %s - %s",
|
||||||
|
$e->getCode(),
|
||||||
|
$e->getMessage(),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
\report($e);
|
||||||
|
} //end try
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write logs in /logs/crm.csv.
|
||||||
|
*
|
||||||
|
* @param string $message
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function writeCsvLog(string $message)
|
||||||
|
{
|
||||||
|
|
||||||
|
$csvPath = \storage_path('/logs/crm.csv');
|
||||||
|
if (!\file_exists($csvPath)) {
|
||||||
|
$logFile = fopen($csvPath, 'w');
|
||||||
|
\fputcsv($logFile, ['date', 'hashcode', 'email', 'action'], ';', escape: '\\');
|
||||||
|
\fclose($logFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
$logFile = fopen($csvPath, 'a');
|
||||||
|
\fputcsv(
|
||||||
|
$logFile,
|
||||||
|
[
|
||||||
|
\now()->toAtomString(),
|
||||||
|
$this->customer['hashcode'],
|
||||||
|
$this->customer['email'],
|
||||||
|
$message
|
||||||
|
],
|
||||||
|
';',
|
||||||
|
escape: '\\'
|
||||||
|
);
|
||||||
|
\fclose($logFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
183
app/Lib/Helpers/ExceptionsHelper.php
Normal file
183
app/Lib/Helpers/ExceptionsHelper.php
Normal file
|
|
@ -0,0 +1,183 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Lib\Helpers;
|
||||||
|
|
||||||
|
class ExceptionsHelper
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle sentry event
|
||||||
|
*
|
||||||
|
* @param \Sentry\Event $event
|
||||||
|
* @return null|\Sentry\Event
|
||||||
|
*/
|
||||||
|
public static function sentryEventHandler(\Sentry\Event $event): ?\Sentry\Event
|
||||||
|
{
|
||||||
|
// Remove unwanted reports.
|
||||||
|
$event->setModules([]);
|
||||||
|
$event->setOsContext(null);
|
||||||
|
|
||||||
|
/** @var \Sentry\ExceptionDataBag[] */
|
||||||
|
$exceptionBag = [];
|
||||||
|
foreach ($event->getExceptions() as $exceptionDataBag) {
|
||||||
|
$exceptionBag[] = self::getAnonymizedSentryException($exceptionDataBag);
|
||||||
|
}
|
||||||
|
$event->setExceptions($exceptionBag);
|
||||||
|
return $event;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Anonimize Sentry Exception bag
|
||||||
|
*
|
||||||
|
* @param \Sentry\ExceptionDataBag $exceptionDataBag
|
||||||
|
* @return \Sentry\ExceptionDataBag
|
||||||
|
*/
|
||||||
|
private static function getAnonymizedSentryException(
|
||||||
|
\Sentry\ExceptionDataBag $exceptionDataBag
|
||||||
|
): \Sentry\ExceptionDataBag {
|
||||||
|
$exceptionDataBag->setValue(self::getAnonymizedMessage($exceptionDataBag->getValue()));
|
||||||
|
if ($stackTrace = $exceptionDataBag->getStacktrace()) {
|
||||||
|
$exceptionDataBag->setStacktrace(self::getAnonymizedSentryStackTrace($stackTrace));
|
||||||
|
}
|
||||||
|
return $exceptionDataBag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Anonymise sentry stacktrace
|
||||||
|
*
|
||||||
|
* @param \Sentry\Stacktrace $stackTrace
|
||||||
|
* @return \Sentry\Stacktrace
|
||||||
|
*/
|
||||||
|
private static function getAnonymizedSentryStackTrace(\Sentry\Stacktrace $stackTrace): \Sentry\Stacktrace
|
||||||
|
{
|
||||||
|
/** @var \Sentry\Frame[] */
|
||||||
|
$frames = \array_reverse($stackTrace->getFrames(), true);
|
||||||
|
$i = \count($frames) - 1;
|
||||||
|
// * Remove all but keep first (index.php).
|
||||||
|
while ($i-- > 0) {
|
||||||
|
$stackTrace->removeFrame(count($stackTrace->getFrames()) - 1);
|
||||||
|
}
|
||||||
|
foreach ($frames as $index => $frame) {
|
||||||
|
$frame->setPostContext([]);
|
||||||
|
$frame->setPreContext([]);
|
||||||
|
$frame->setContextLine('');
|
||||||
|
$frame->setVars(self::getAnonymizedSentryParams($frame->getVars()));
|
||||||
|
$stackTrace->addFrame($frame);
|
||||||
|
if ($index === 0) {
|
||||||
|
$stackTrace->removeFrame(count($stackTrace->getFrames()) - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $stackTrace;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get anonymized sentry params
|
||||||
|
*
|
||||||
|
* @param mixed[] $params
|
||||||
|
* @return string[]
|
||||||
|
*/
|
||||||
|
private static function getAnonymizedSentryParams(array $params): array
|
||||||
|
{
|
||||||
|
foreach ($params as &$param) {
|
||||||
|
$type = \strtolower(\gettype($param));
|
||||||
|
if (\is_string($param)) {
|
||||||
|
$type = \explode(' ', \trim(strtolower($param)))[0] ?? null;
|
||||||
|
}
|
||||||
|
switch (true) {
|
||||||
|
case $type === 'lambda':
|
||||||
|
case $type === 'object':
|
||||||
|
continue 2;
|
||||||
|
case $type === 'array' and \is_array($param):
|
||||||
|
$param = sprintf('Array(%d)', \count($param));
|
||||||
|
continue 2;
|
||||||
|
default:
|
||||||
|
if (\is_numeric($param)) {
|
||||||
|
$param = \ucfirst($type);
|
||||||
|
continue 2;
|
||||||
|
}
|
||||||
|
if (\is_string($param)) {
|
||||||
|
$param = sprintf('String(%d)', \strlen($param));
|
||||||
|
continue 2;
|
||||||
|
}
|
||||||
|
} //end switch
|
||||||
|
} //end foreach
|
||||||
|
return $params;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Anonymize at least Sql queries
|
||||||
|
*
|
||||||
|
* @param string $message
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function getAnonymizedMessage(string $message): string
|
||||||
|
{
|
||||||
|
$message = \preg_replace('/^(.*)( \(SQL:.*\))$/', '$1', $message) ?? $message;
|
||||||
|
if ($sqlPos = \strpos($message, 'to use near')) {
|
||||||
|
$message = \mb_strcut($message, 0, $sqlPos);
|
||||||
|
}
|
||||||
|
return $message;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Anonymize stack trace
|
||||||
|
*
|
||||||
|
* @param \Throwable $e
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function getAnonymizedStackTrace(\Throwable $e): string
|
||||||
|
{
|
||||||
|
$projectPath = \realpath(\sprintf('%s/../', \app_path()));
|
||||||
|
$traceStack = $e->getTrace();
|
||||||
|
$traceStr = '';
|
||||||
|
$maxStackStage = 0;
|
||||||
|
foreach ($traceStack as $stackStage => $stack) {
|
||||||
|
$maxStackStage = $stackStage;
|
||||||
|
$traceStr .= \sprintf(
|
||||||
|
'#%s %s(%d): ',
|
||||||
|
$stackStage,
|
||||||
|
str_replace($projectPath, '', $stack['file'] ?? ''),
|
||||||
|
$stack['line'] ?? ''
|
||||||
|
);
|
||||||
|
if (isset($stack['class'])) {
|
||||||
|
$traceStr .= "{$stack['class']}->{$stack['function']}(";
|
||||||
|
if (isset($stack['args'])) {
|
||||||
|
$traceStr .= self::handleArgs($stack);
|
||||||
|
}
|
||||||
|
$traceStr .= ")\n";
|
||||||
|
} else {
|
||||||
|
$traceStr .= "{$stack['function']}(";
|
||||||
|
if (isset($stack['args'])) {
|
||||||
|
$traceStr .= self::handleArgs($stack);
|
||||||
|
}
|
||||||
|
$traceStr .= ")\n";
|
||||||
|
}
|
||||||
|
} //end foreach
|
||||||
|
$maxStackStage++;
|
||||||
|
$traceStr .= "#$maxStackStage {main}";
|
||||||
|
return $traceStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle Args
|
||||||
|
*
|
||||||
|
* @param array $stack
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function handleArgs(array $stack): string
|
||||||
|
{
|
||||||
|
$traceArgs = '';
|
||||||
|
$argsCount = count($stack['args']);
|
||||||
|
for ($i = 0; $i < $argsCount; $i++) {
|
||||||
|
$type = \gettype($stack['args'][$i]);
|
||||||
|
match ($type) {
|
||||||
|
'object' => $traceArgs .= sprintf('Object(%s)', $stack['args'][$i]::class),
|
||||||
|
'array' => $traceArgs .= sprintf('Array(%d)', \count($stack['args'][$i])),
|
||||||
|
'string' => $traceArgs .= sprintf('String(%d)', \strlen($stack['args'][$i])),
|
||||||
|
default => $traceArgs .= \gettype($stack['args'][$i]),
|
||||||
|
};
|
||||||
|
$traceArgs .= ($i !== ($argsCount - 1) ? ',' : '');
|
||||||
|
}
|
||||||
|
return $traceArgs;
|
||||||
|
}
|
||||||
|
}
|
||||||
104
app/Lib/Helpers/ToolboxHelper.php
Normal file
104
app/Lib/Helpers/ToolboxHelper.php
Normal file
|
|
@ -0,0 +1,104 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Lib\Helpers;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Contracts\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
|
use Illuminate\Support\Facades\File;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Illuminate\Support\Facades\Route;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
use Illuminate\Validation\Rules\Enum;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
use Symfony\Component\Finder\SplFileInfo;
|
||||||
|
|
||||||
|
class ToolboxHelper
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Mutltibyte string replace.
|
||||||
|
*
|
||||||
|
* @param array|string $search
|
||||||
|
* @param array|string $replace
|
||||||
|
* @param array|string $subject
|
||||||
|
* @param integer $count
|
||||||
|
* @return array|string|false
|
||||||
|
*/
|
||||||
|
public static function mbReplace(
|
||||||
|
$search,
|
||||||
|
$replace,
|
||||||
|
$subject,
|
||||||
|
int &$count = 0
|
||||||
|
) {
|
||||||
|
if (!is_array($search) && is_array($replace)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (is_array($subject)) {
|
||||||
|
// Call mb_replace for each single string in $subject .
|
||||||
|
foreach ($subject as &$string) {
|
||||||
|
$string = &self::mbReplace($search, $replace, $string, $count);
|
||||||
|
}
|
||||||
|
} elseif (is_array($search)) {
|
||||||
|
if (!is_array($replace)) {
|
||||||
|
foreach ($search as &$string) {
|
||||||
|
$subject = self::mbReplace($string, $replace, $subject, $count);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$n = max(count($search), count($replace));
|
||||||
|
while ($n--) {
|
||||||
|
$subject = self::mbReplace(current($search), current($replace), $subject, $count);
|
||||||
|
next($search);
|
||||||
|
next($replace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$parts = mb_split(preg_quote($search), $subject);
|
||||||
|
$count = count($parts) - 1;
|
||||||
|
$subject = implode($replace, $parts);
|
||||||
|
} //end if
|
||||||
|
return $subject;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that the field is unique.
|
||||||
|
*
|
||||||
|
* @param string $table
|
||||||
|
* @param string $field
|
||||||
|
* @param string|integer|float|boolean|null|array $value
|
||||||
|
* @param integer|null $id
|
||||||
|
* @param callable|null $query
|
||||||
|
* @return void
|
||||||
|
* @throws \Illuminate\Validation\ValidationException If the field is not unique.
|
||||||
|
*/
|
||||||
|
public static function assertFieldIsUnique(
|
||||||
|
string $table,
|
||||||
|
string $field,
|
||||||
|
$value,
|
||||||
|
?int $id = null,
|
||||||
|
?callable $query = null
|
||||||
|
): void {
|
||||||
|
if (!$query) {
|
||||||
|
Validator::make([$field => $value], [
|
||||||
|
self::mbReplace('.', '\.', $field) => Rule::unique($table, $field)->ignore($id),
|
||||||
|
], [
|
||||||
|
self::mbReplace('.', '\.', "{$field}.unique")
|
||||||
|
=> trans('crud.libs.toolbox.assertFieldIsUnique', ['attribute' => $field, 'value' => $value])
|
||||||
|
])->validate();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Validator::make([$field => $value], [
|
||||||
|
$field => Rule::unique($table)->where($query)->ignore($id),
|
||||||
|
], [
|
||||||
|
$field . '.unique' => trans(
|
||||||
|
'crud.libs.toolbox.assertFieldIsUnique',
|
||||||
|
['attribute' => $field, 'value' => $value]
|
||||||
|
)
|
||||||
|
])->validate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -11,9 +11,6 @@ class AlertBr extends Mailable
|
||||||
use Queueable;
|
use Queueable;
|
||||||
use SerializesModels;
|
use SerializesModels;
|
||||||
|
|
||||||
public $couponSeuil;
|
|
||||||
|
|
||||||
public $couponDiffusion;
|
|
||||||
|
|
||||||
public $subject;
|
public $subject;
|
||||||
|
|
||||||
|
|
@ -23,11 +20,9 @@ class AlertBr extends Mailable
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct($couponSeuil, $couponDiffusion, $sitename)
|
public function __construct(public $couponSeuil, public $couponDiffusion, $sitename)
|
||||||
{
|
{
|
||||||
$this->couponSeuil = $couponSeuil;
|
$this->subject = 'Notification mes BR : ' . $sitename;
|
||||||
$this->couponDiffusion = $couponDiffusion;
|
|
||||||
$this->subject = 'Notification mes BR : ' . $sitename;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,6 @@ class AlertBrAdmin extends Mailable
|
||||||
use Queueable;
|
use Queueable;
|
||||||
use SerializesModels;
|
use SerializesModels;
|
||||||
|
|
||||||
public $couponSeuil;
|
|
||||||
|
|
||||||
public $couponDiffusion;
|
|
||||||
|
|
||||||
public $subject;
|
public $subject;
|
||||||
|
|
||||||
|
|
@ -23,11 +20,9 @@ class AlertBrAdmin extends Mailable
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct($couponSeuil, $couponDiffusion)
|
public function __construct(public $couponSeuil, public $couponDiffusion)
|
||||||
{
|
{
|
||||||
$this->couponSeuil = $couponSeuil;
|
$this->subject = 'Notification mes BR : Récapitulatif global';
|
||||||
$this->couponDiffusion = $couponDiffusion;
|
|
||||||
$this->subject = 'Notification mes BR : Récapitulatif global';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
83
app/Models/ArchiveCampaign.php
Normal file
83
app/Models/ArchiveCampaign.php
Normal file
|
|
@ -0,0 +1,83 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Models\Site;
|
||||||
|
use App\Traits\HasUniqueField;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property string $name Name of the archived campaign.
|
||||||
|
* @property string $campaign_id Id of the archived campaign.
|
||||||
|
* @property-read \Carbon\Carbon $created_at Created date.
|
||||||
|
* @property-read \Carbon\Carbon $updated_at Updated date.
|
||||||
|
*
|
||||||
|
* @property-read \App\Models\ArchiveStat $archiveStat ArchiveStat Has many relationship.
|
||||||
|
* @property-read \App\Models\ArchiveSite $archiveSite ArchiveSite Belongs to relationship.
|
||||||
|
*/
|
||||||
|
class ArchiveCampaign extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
use HasUniqueField;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that are mass assignable.
|
||||||
|
*
|
||||||
|
* @var array<int, string>
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'name',
|
||||||
|
'campaign_id',
|
||||||
|
'archive_site_id'
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform any actions required after the model boots.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected static function booted(): void
|
||||||
|
{
|
||||||
|
static::creating(function (self $model): void {
|
||||||
|
$model->assertFieldIsUnique('campaign_id', $model->campaign_id);
|
||||||
|
$site = Site::query()->where('site_id', $model->archive_site_id)->firstOrFail();
|
||||||
|
$archiveSite = ArchiveSite::query()->firstOrCreate(
|
||||||
|
[
|
||||||
|
'site_id' => $model->archive_site_id
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => $site->site_nom
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$model->archiveSite()->associate($archiveSite);
|
||||||
|
});
|
||||||
|
static::updating(function (): void {
|
||||||
|
throw new \RuntimeException('Updating an archived campaign is not authorized');
|
||||||
|
});
|
||||||
|
static::deleting(function (): void {
|
||||||
|
throw new \RuntimeException('Deleting an archived campaign is not authorized');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// * RELATIONS
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ArchiveSite model relation
|
||||||
|
* @return Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||||
|
*/
|
||||||
|
public function archiveSite()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(ArchiveSite::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ArchiveSite model relation
|
||||||
|
* @return Illuminate\Database\Eloquent\Relations\HasMany
|
||||||
|
*/
|
||||||
|
public function archiveStat()
|
||||||
|
{
|
||||||
|
return $this->hasMany(ArchiveStat::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
61
app/Models/ArchiveCoupon.php
Normal file
61
app/Models/ArchiveCoupon.php
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Traits\HasUniqueField;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property string $name Name of the archived coupon.
|
||||||
|
* @property string $coupon_code Treatment code of the archived coupon.
|
||||||
|
* @property-read \Carbon\Carbon $created_at Created date.
|
||||||
|
* @property-read \Carbon\Carbon $updated_at Updated date.
|
||||||
|
*
|
||||||
|
* @property-read \App\Models\ArchiveStat $archiveStat ArchiveStat Has many relationship.
|
||||||
|
*/
|
||||||
|
class ArchiveCoupon extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
use HasUniqueField;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that are mass assignable.
|
||||||
|
*
|
||||||
|
* @var array<int, string>
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'name',
|
||||||
|
'coupon_code',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform any actions required after the model boots.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected static function booted(): void
|
||||||
|
{
|
||||||
|
static::creating(function (self $model): void {
|
||||||
|
$model->assertFieldIsUnique('coupon_code', $model->coupon_code);
|
||||||
|
});
|
||||||
|
static::updating(function (): void {
|
||||||
|
throw new \RuntimeException('Updating an archived coupon is not authorized');
|
||||||
|
});
|
||||||
|
static::deleting(function (): void {
|
||||||
|
throw new \RuntimeException('Deleting an archived coupon is not authorized');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// * RELATIONS
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ArchiveStat model relation
|
||||||
|
* @return Illuminate\Database\Eloquent\Relations\HasMany
|
||||||
|
*/
|
||||||
|
public function archiveStat()
|
||||||
|
{
|
||||||
|
return $this->hasMany(ArchiveStat::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
61
app/Models/ArchiveSite.php
Normal file
61
app/Models/ArchiveSite.php
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Traits\HasUniqueField;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property string $name Name of the archived site.
|
||||||
|
* @property string $site_id Id of the archived site.
|
||||||
|
* @property-read \Carbon\Carbon $created_at Created date.
|
||||||
|
* @property-read \Carbon\Carbon $updated_at Updated date.
|
||||||
|
*
|
||||||
|
* @property-read \App\Models\ArchiveCampaign $archiveCampaign ArchiveCampaign Has many relationship.
|
||||||
|
*/
|
||||||
|
class ArchiveSite extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
use HasUniqueField;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that are mass assignable.
|
||||||
|
*
|
||||||
|
* @var array<int, string>
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'name',
|
||||||
|
'site_id',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform any actions required after the model boots.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected static function booted(): void
|
||||||
|
{
|
||||||
|
static::creating(function (self $model): void {
|
||||||
|
$model->assertFieldIsUnique('site_id', $model->site_id);
|
||||||
|
});
|
||||||
|
static::updating(function (self $model): void {
|
||||||
|
throw new \RuntimeException('Updating an archived site is not authorized');
|
||||||
|
});
|
||||||
|
static::deleting(function (): void {
|
||||||
|
throw new \RuntimeException('Deleting an archived site is not authorized');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// * RELATIONS
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ArchiveCampaign model relation
|
||||||
|
* @return Illuminate\Database\Eloquent\Relations\HasMany
|
||||||
|
*/
|
||||||
|
public function archiveCampaign()
|
||||||
|
{
|
||||||
|
return $this->hasMany(ArchiveCampaign::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
92
app/Models/ArchiveStat.php
Normal file
92
app/Models/ArchiveStat.php
Normal file
|
|
@ -0,0 +1,92 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Models\Campagne;
|
||||||
|
use App\Models\Coupon;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property integer $quantity Quantity of distributed coupons.
|
||||||
|
* @property \Carbon\Carbon $date Date when the coupon has been distributed.
|
||||||
|
* @property-read \Carbon\Carbon $created_at Created date.
|
||||||
|
* @property-read \Carbon\Carbon $updated_at Updated date.
|
||||||
|
*
|
||||||
|
* @property-read \App\Models\ArchiveCoupon $archiveCoupon ArchiveCoupon Belongs to relationship.
|
||||||
|
* @property-read \App\Models\ArchiveCampaign $archiveCampaign ArchiveCampaign Belongs to relationship.
|
||||||
|
*/
|
||||||
|
class ArchiveStat extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that are mass assignable.
|
||||||
|
*
|
||||||
|
* @var array<int, string>
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'date',
|
||||||
|
'quantity',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform any actions required after the model boots.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected static function booted(): void
|
||||||
|
{
|
||||||
|
static::creating(function (self $model): void {
|
||||||
|
$campaign = Campagne::withTrashed()->where('camp_id', $model->archive_campaign_id)->firstOrFail();
|
||||||
|
$archiveCampaign = ArchiveCampaign::query()->firstOrCreate(
|
||||||
|
[
|
||||||
|
'campaign_id' => $model->archive_campaign_id
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => $campaign->camp_name,
|
||||||
|
'archive_site_id' => $campaign->camp_siteId,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$model->archiveCampaign()->associate($archiveCampaign);
|
||||||
|
|
||||||
|
$coupon = Coupon::withTrashed()->where('coupon_id', $model->archive_coupon_id)->firstOrFail();
|
||||||
|
$archiveCoupon = ArchiveCoupon::query()->firstOrCreate(
|
||||||
|
[
|
||||||
|
'coupon_code' => $model->archive_coupon_id
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => $coupon->coupon_code,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$model->archiveCoupon()->associate($archiveCoupon);
|
||||||
|
});
|
||||||
|
static::updating(function (): void {
|
||||||
|
throw new \RuntimeException('Upating an archived stat is not authorized');
|
||||||
|
});
|
||||||
|
static::deleting(function (): void {
|
||||||
|
throw new \RuntimeException('Deleting an archived stat is not authorized');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// * RELATIONS
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ArchiveCoupon model relation
|
||||||
|
* @return Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||||
|
*/
|
||||||
|
public function archiveCoupon()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(ArchiveCoupon::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ArchiveCampaign model relation
|
||||||
|
* @return Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||||
|
*/
|
||||||
|
public function archiveCampaign()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(ArchiveCampaign::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
83
app/Models/Basket.php
Normal file
83
app/Models/Basket.php
Normal file
|
|
@ -0,0 +1,83 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Models\Campagne;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
class Basket extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'campagne_id'
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Customer model relation
|
||||||
|
* @return BelongsTo
|
||||||
|
*/
|
||||||
|
public function customer()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Customers::class, 'customer_id', 'id');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Campagne model relation
|
||||||
|
* @return BelongsTo
|
||||||
|
*/
|
||||||
|
public function campagne()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Campagne::class, 'campagne_id', 'camp_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BasketContent model relation
|
||||||
|
* @return HasMany
|
||||||
|
*/
|
||||||
|
public function contents()
|
||||||
|
{
|
||||||
|
return $this->hasMany(BasketContent::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updateContent(Campagne $campagne, array $coupons, Customers $customer)
|
||||||
|
{
|
||||||
|
$basket = self::where(['campagne_id' => $campagne->camp_id, 'customer_id' => $customer->id])->first();
|
||||||
|
|
||||||
|
if (!$basket) {
|
||||||
|
$basket = new Basket();
|
||||||
|
$basket->uuid = (string) Str::uuid();
|
||||||
|
$basket->campagne()->associate($campagne);
|
||||||
|
$basket->customer()->associate($customer);
|
||||||
|
$basket->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($coupons as $couponId => $quantity) {
|
||||||
|
$associatedCoupon = $campagne->coupons()->where('coupon_id', $couponId)->first();
|
||||||
|
|
||||||
|
if ($associatedCoupon) {
|
||||||
|
$basketContent = BasketContent::where(['basket_id' => $basket->id, 'coupon_id' => $associatedCoupon->coupon_id])->first();
|
||||||
|
if ($basketContent) {
|
||||||
|
$basketContent->quantity += $quantity;
|
||||||
|
$basketContent->save();
|
||||||
|
} else {
|
||||||
|
if ($quantity > 0) {
|
||||||
|
$newBasketContent = new BasketContent();
|
||||||
|
$newBasketContent->basket_id = $basket->id;
|
||||||
|
$newBasketContent->coupon_id = $associatedCoupon->coupon_id;
|
||||||
|
$newBasketContent->quantity = $quantity;
|
||||||
|
$newBasketContent->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return $basket;
|
||||||
|
}
|
||||||
|
}
|
||||||
43
app/Models/BasketContent.php
Normal file
43
app/Models/BasketContent.php
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Models\Coupon;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||||
|
|
||||||
|
class BasketContent extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* booted method
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected static function booted()
|
||||||
|
{
|
||||||
|
static::creating(function (self $model): void {
|
||||||
|
$model->printed = 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Basket model relation
|
||||||
|
* @return HasOne
|
||||||
|
*/
|
||||||
|
public function basket()
|
||||||
|
{
|
||||||
|
return $this->hasOne(Basket::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Coupon model relation
|
||||||
|
* @return HasOne
|
||||||
|
*/
|
||||||
|
public function coupon()
|
||||||
|
{
|
||||||
|
return $this->hasOne(Coupon::class, 'coupon_id', 'coupon_id');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,32 +1,37 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class Calendrier extends Model
|
class Calendrier extends Model
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected $table = 'calendrier';
|
protected $table = 'calendrier';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var bool
|
* @var boolean
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public $timestamps = false;
|
public $timestamps = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected $primaryKey = 'calendrier_id';
|
protected $primaryKey = 'calendrier_id';
|
||||||
|
|
||||||
|
|
||||||
protected $dates = ['calendrier_startdate', 'calendrier_enddate'];
|
protected $dates = ['calendrier_startdate', 'calendrier_enddate'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'calendrier_startdate',
|
'calendrier_startdate',
|
||||||
'calendrier_enddate'
|
'calendrier_enddate'
|
||||||
|
|
@ -38,6 +43,21 @@ class Calendrier extends Model
|
||||||
*/
|
*/
|
||||||
public function coupon()
|
public function coupon()
|
||||||
{
|
{
|
||||||
return $this->belongsTo('App\Coupon', 'calendrier_couponId');
|
return $this->belongsTo(\App\Models\Coupon::class, 'calendrier_couponId');
|
||||||
|
}
|
||||||
|
|
||||||
|
// * METHODS
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the current date is between the calendar publication dates.
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function isPublished(): bool
|
||||||
|
{
|
||||||
|
return now()->betweenIncluded(
|
||||||
|
Carbon::parse($this->calendrier_startdate),
|
||||||
|
Carbon::parse($this->calendrier_enddate)->endOfDay()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,10 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App;
|
namespace App\Models;
|
||||||
|
|
||||||
use App\Enums\CampaignTypes;
|
use App\Enums\CampaignTypes;
|
||||||
use App\Models\PrintedWalls;
|
use App\Models\Basket;
|
||||||
|
use App\Models\PrintedCoupons;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
use Kwaadpepper\Enum\Traits\CastsEnums;
|
use Kwaadpepper\Enum\Traits\CastsEnums;
|
||||||
|
|
||||||
|
|
@ -12,6 +15,7 @@ class Campagne extends Model
|
||||||
{
|
{
|
||||||
use SoftDeletes;
|
use SoftDeletes;
|
||||||
use CastsEnums;
|
use CastsEnums;
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
public $enumCasts = [
|
public $enumCasts = [
|
||||||
'camp_type' => CampaignTypes::class
|
'camp_type' => CampaignTypes::class
|
||||||
|
|
@ -20,6 +24,7 @@ class Campagne extends Model
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'camp_siteId',
|
'camp_siteId',
|
||||||
'camp_name',
|
'camp_name',
|
||||||
|
|
@ -46,16 +51,19 @@ class Campagne extends Model
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected $table = 'campagne';
|
protected $table = 'campagne';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected $primaryKey = 'camp_id';
|
protected $primaryKey = 'camp_id';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected $dates = ['camp_deleted_at'];
|
protected $dates = ['camp_deleted_at'];
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -66,7 +74,7 @@ class Campagne extends Model
|
||||||
*/
|
*/
|
||||||
public function notifications()
|
public function notifications()
|
||||||
{
|
{
|
||||||
return $this->hasMany('App\Notification', 'notif_campId', 'camp_id');
|
return $this->hasMany(\App\Models\Notification::class, 'notif_campId', 'camp_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -75,7 +83,7 @@ class Campagne extends Model
|
||||||
*/
|
*/
|
||||||
public function murs()
|
public function murs()
|
||||||
{
|
{
|
||||||
return $this->hasMany('App\Mur', 'mur_campId', 'camp_id');
|
return $this->hasMany(\App\Models\Mur::class, 'mur_campId', 'camp_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -84,7 +92,7 @@ class Campagne extends Model
|
||||||
*/
|
*/
|
||||||
public function paniers()
|
public function paniers()
|
||||||
{
|
{
|
||||||
return $this->hasMany('App\Panier', 'panier_campId', 'camp_id');
|
return $this->hasMany(\App\Models\Panier::class, 'panier_campId', 'camp_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -93,7 +101,7 @@ class Campagne extends Model
|
||||||
*/
|
*/
|
||||||
public function site()
|
public function site()
|
||||||
{
|
{
|
||||||
return $this->belongsTo('App\Site', 'camp_siteId', 'site_id');
|
return $this->belongsTo(\App\Models\Site::class, 'camp_siteId', 'site_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -101,11 +109,24 @@ class Campagne extends Model
|
||||||
*/
|
*/
|
||||||
public function coupons()
|
public function coupons()
|
||||||
{
|
{
|
||||||
return $this->belongsToMany('App\Coupon', 'campagne_coupon', 'campagne_id', 'coup_id');
|
return $this->belongsToMany(\App\Models\Coupon::class, 'campagne_coupon', 'campagne_id', 'coup_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function printedWalls()
|
/**
|
||||||
|
* printedCoupons relation
|
||||||
|
* @return HasMany
|
||||||
|
*/
|
||||||
|
public function printedCoupons()
|
||||||
{
|
{
|
||||||
return $this->hasMany(PrintedWalls::class, 'camp_id');
|
return $this->hasMany(PrintedCoupons::class, 'camp_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Basket model relation
|
||||||
|
* @return HasMany
|
||||||
|
*/
|
||||||
|
public function baskets()
|
||||||
|
{
|
||||||
|
return $this->hasMany(Basket::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,11 +1,16 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Models\Log;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
|
||||||
class Contact extends Model
|
class Contact extends Model
|
||||||
{
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
|
|
@ -19,16 +24,19 @@ class Contact extends Model
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected $table = 'contact';
|
protected $table = 'contact';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected $primaryKey = 'contact_id';
|
protected $primaryKey = 'contact_id';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'contact_ref',
|
'contact_ref',
|
||||||
'contact_prenom',
|
'contact_prenom',
|
||||||
|
|
@ -45,7 +53,7 @@ class Contact extends Model
|
||||||
*/
|
*/
|
||||||
public function murs()
|
public function murs()
|
||||||
{
|
{
|
||||||
return $this->hasMany('App\Mur', 'mur_contactId', 'contact_id');
|
return $this->hasMany(\App\Models\Mur::class, 'mur_contactId', 'contact_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -54,7 +62,7 @@ class Contact extends Model
|
||||||
*/
|
*/
|
||||||
public function paniers()
|
public function paniers()
|
||||||
{
|
{
|
||||||
return $this->hasMany('App\Panier', 'panier_contactId', 'contact_id');
|
return $this->hasMany(\App\Models\Panier::class, 'panier_contactId', 'contact_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -63,48 +71,76 @@ class Contact extends Model
|
||||||
*/
|
*/
|
||||||
public function site()
|
public function site()
|
||||||
{
|
{
|
||||||
return $this->belongsTo('App\Site', 'contact_siteId');
|
return $this->belongsTo(\App\Models\Site::class, 'contact_siteId');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function scopeSearchName($query, $name)
|
/**
|
||||||
|
* @param \Illuminate\Database\Eloquent\Builder<static> $query
|
||||||
|
*/
|
||||||
|
protected function scopeSearchName($query, $name)
|
||||||
{
|
{
|
||||||
if ($name) {
|
if ($name) {
|
||||||
$query->where('contact_nom', 'like', '%' . $name . '%');
|
$query->where('contact_nom', 'like', '%' . $name . '%');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function scopeSearchFirstname($query, $firstname)
|
/**
|
||||||
|
* @param \Illuminate\Database\Eloquent\Builder<static> $query
|
||||||
|
*/
|
||||||
|
protected function scopeSearchFirstname($query, $firstname)
|
||||||
{
|
{
|
||||||
if ($firstname) {
|
if ($firstname) {
|
||||||
$query->where('contact_prenom', 'like', '%' . $firstname . '%');
|
$query->where('contact_prenom', 'like', '%' . $firstname . '%');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function scopeSearchEmail($query, $email)
|
/**
|
||||||
|
* @param \Illuminate\Database\Eloquent\Builder<static> $query
|
||||||
|
*/
|
||||||
|
protected function scopeSearchEmail($query, $email)
|
||||||
{
|
{
|
||||||
if ($email) {
|
if ($email) {
|
||||||
$query->where('contact_email', 'like', '%' . $email . '%');
|
$query->where('contact_email', 'like', '%' . $email . '%');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function scopeSearchVille($query, $ville)
|
/**
|
||||||
|
* @param \Illuminate\Database\Eloquent\Builder<static> $query
|
||||||
|
*/
|
||||||
|
protected function scopeSearchVille($query, $ville)
|
||||||
{
|
{
|
||||||
if ($ville) {
|
if ($ville) {
|
||||||
$query->where('contact_ville', 'like', '%' . $ville . '%');
|
$query->where('contact_ville', 'like', '%' . $ville . '%');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function scopeSearchCp($query, $cp)
|
/**
|
||||||
|
* @param \Illuminate\Database\Eloquent\Builder<static> $query
|
||||||
|
*/
|
||||||
|
protected function scopeSearchCp($query, $cp)
|
||||||
{
|
{
|
||||||
if ($cp) {
|
if ($cp) {
|
||||||
$query->where('contact_cp', 'like', '%' . $cp . '%');
|
$query->where('contact_cp', 'like', '%' . $cp . '%');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function scopeSearchCountry($query, $country)
|
/**
|
||||||
|
* @param \Illuminate\Database\Eloquent\Builder<static> $query
|
||||||
|
*/
|
||||||
|
protected function scopeSearchCountry($query, $country)
|
||||||
{
|
{
|
||||||
if ($country) {
|
if ($country) {
|
||||||
$query->where('contact_country', $country);
|
$query->where('contact_country', $country);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* log relation
|
||||||
|
*
|
||||||
|
* @return HasMany
|
||||||
|
*/
|
||||||
|
public function logs()
|
||||||
|
{
|
||||||
|
return $this->hasMany(Log::class, 'log_contactId', 'contact_id');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,13 +1,16 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Models\BasketContent;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
|
||||||
class Coupon extends Model
|
class Coupon extends Model
|
||||||
{
|
{
|
||||||
use SoftDeletes;
|
use SoftDeletes;
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
|
|
@ -27,69 +30,19 @@ class Coupon extends Model
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected $table = 'coupon';
|
protected $table = 'coupon';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected $primaryKey = 'coupon_id';
|
protected $primaryKey = 'coupon_id';
|
||||||
|
|
||||||
/**
|
|
||||||
* OneToMany
|
|
||||||
* Coupon -> Calendrier
|
|
||||||
*/
|
|
||||||
public function calendriers()
|
|
||||||
{
|
|
||||||
return $this->hasMany('App\Calendrier', 'calendrier_couponId', 'coupon_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* OneToMany
|
|
||||||
* Coupon -> PanierContent
|
|
||||||
*/
|
|
||||||
public function panierContents()
|
|
||||||
{
|
|
||||||
return $this->hasMany('App\PanierContent', 'panier_content_couponId', 'coupon_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* OneToMany
|
|
||||||
* Coupon -> Mur
|
|
||||||
*/
|
|
||||||
public function murs()
|
|
||||||
{
|
|
||||||
return $this->hasMany('App\Mur', 'mur_couponId', 'coupon_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* OneToMany
|
|
||||||
* Coupon -> Mouvement
|
|
||||||
*/
|
|
||||||
public function mouvements()
|
|
||||||
{
|
|
||||||
return $this->hasMany('App\Mouvement', 'mouvement_couponId', 'coupon_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ManyToOne
|
|
||||||
* Coupon -> Site
|
|
||||||
*/
|
|
||||||
public function site()
|
|
||||||
{
|
|
||||||
return $this->belongsTo('App\Site', 'coupon_siteId');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The campagnes that belong to the coupon.
|
|
||||||
*/
|
|
||||||
public function campagnes()
|
|
||||||
{
|
|
||||||
return $this->belongsToMany('App\Campagne', 'campagne_coupon', 'coup_id', 'campagne_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'coupon_code',
|
'coupon_code',
|
||||||
'coupon_norme',
|
'coupon_norme',
|
||||||
|
|
@ -120,4 +73,66 @@ class Coupon extends Model
|
||||||
'coupon_seuil_alert',
|
'coupon_seuil_alert',
|
||||||
'coupon_treatment_center'
|
'coupon_treatment_center'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OneToMany
|
||||||
|
* Coupon -> Calendrier
|
||||||
|
*/
|
||||||
|
public function calendriers()
|
||||||
|
{
|
||||||
|
return $this->hasMany(\App\Models\Calendrier::class, 'calendrier_couponId', 'coupon_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OneToMany
|
||||||
|
* Coupon -> PanierContent
|
||||||
|
*/
|
||||||
|
public function panierContents()
|
||||||
|
{
|
||||||
|
return $this->hasMany(\App\Models\PanierContent::class, 'panier_content_couponId', 'coupon_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OneToMany
|
||||||
|
* Coupon -> Mur
|
||||||
|
*/
|
||||||
|
public function murs()
|
||||||
|
{
|
||||||
|
return $this->hasMany(\App\Models\Mur::class, 'mur_couponId', 'coupon_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OneToMany
|
||||||
|
* Coupon -> Mouvement
|
||||||
|
*/
|
||||||
|
public function mouvements()
|
||||||
|
{
|
||||||
|
return $this->hasMany(\App\Models\Mouvement::class, 'mouvement_couponId', 'coupon_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ManyToOne
|
||||||
|
* Coupon -> Site
|
||||||
|
*/
|
||||||
|
public function site()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(\App\Models\Site::class, 'coupon_siteId');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The campagnes that belong to the coupon.
|
||||||
|
*/
|
||||||
|
public function campagnes()
|
||||||
|
{
|
||||||
|
return $this->belongsToMany(\App\Models\Campagne::class, 'campagne_coupon', 'coup_id', 'campagne_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BasketContent model relation
|
||||||
|
* @return HasMany
|
||||||
|
*/
|
||||||
|
public function basketContents()
|
||||||
|
{
|
||||||
|
return $this->hasMany(BasketContent::class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2,45 +2,92 @@
|
||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Models\Panier;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
|
||||||
class Customers extends Model
|
class Customers extends Model
|
||||||
{
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string $primaryKey
|
||||||
|
*/
|
||||||
|
|
||||||
protected $primaryKey = 'hashcode';
|
protected $primaryKey = 'hashcode';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string $keyType
|
||||||
|
*/
|
||||||
|
|
||||||
protected $keyType = 'string';
|
protected $keyType = 'string';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array $fillable
|
||||||
|
*/
|
||||||
|
|
||||||
protected $fillable = ['hashcode', 'email', 'country'];
|
protected $fillable = ['hashcode', 'email', 'country'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* booted method
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
protected static function booted()
|
protected static function booted()
|
||||||
{
|
{
|
||||||
static::creating(function ($customer) {
|
static::creating(function ($customer): void {
|
||||||
$customer->country = (new Customers())->getIsoCountry($customer->country);
|
$customer->country = new Customers()->getIsoCountry($customer->country);
|
||||||
});
|
});
|
||||||
|
|
||||||
static::updating(function ($customer) {
|
static::updating(function ($customer): void {
|
||||||
$customer->country = (new Customers())->getIsoCountry($customer->country);
|
$customer->country = new Customers()->getIsoCountry($customer->country);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getIsoCountry method
|
||||||
|
* Default is : France
|
||||||
|
*
|
||||||
|
* @param string $country
|
||||||
|
* @return integer
|
||||||
|
*/
|
||||||
private function getIsoCountry($country)
|
private function getIsoCountry($country)
|
||||||
{
|
{
|
||||||
$country = trim(ucfirst(strtolower($country)));
|
$country = trim(ucfirst(strtolower($country)));
|
||||||
switch ($country) {
|
$country = match ($country) {
|
||||||
case 'Belgique':
|
'Belgique' => 56,
|
||||||
return 56;
|
'Luxembourg' => 442,
|
||||||
break;
|
default => 250,
|
||||||
case 'Luxembourg':
|
};
|
||||||
return 442;
|
return $country;
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return 250; //France
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function printedWalls()
|
/**
|
||||||
|
* Printed Coupons Relation
|
||||||
|
*
|
||||||
|
* @return HasMany
|
||||||
|
*/
|
||||||
|
public function printedCoupons()
|
||||||
{
|
{
|
||||||
return $this->hasMany(PrintedWalls::class, 'customer_id');
|
return $this->hasMany(PrintedCoupons::class, 'customer_id', 'id');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Basket model relation
|
||||||
|
* @return HasMany
|
||||||
|
*/
|
||||||
|
public function baskets()
|
||||||
|
{
|
||||||
|
return $this->hasMany(Basket::class, 'customer_id', 'id');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Panier model relation
|
||||||
|
* @return HasMany
|
||||||
|
*/
|
||||||
|
public function paniers()
|
||||||
|
{
|
||||||
|
return $this->hasMany(Panier::class, 'panier_contactId', 'id');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App;
|
namespace App\Models;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
|
@ -12,11 +12,13 @@ class Log extends Model
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected $table = 'logs';
|
protected $table = 'logs';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected $primaryKey = 'id';
|
protected $primaryKey = 'id';
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
|
|
@ -24,8 +26,9 @@ class Log extends Model
|
||||||
const CREATED_AT = 'created_at';
|
const CREATED_AT = 'created_at';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'log_action',
|
'log_action',
|
||||||
'log_refsite',
|
'log_refsite',
|
||||||
|
|
@ -1,32 +1,36 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App;
|
namespace App\Models;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class Mouvement extends Model
|
class Mouvement extends Model
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected $table = 'mouvement';
|
protected $table = 'mouvement';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected $primaryKey = 'mouvement_id';
|
protected $primaryKey = 'mouvement_id';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var boolean
|
* @var boolean
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public $timestamps = false;
|
public $timestamps = false;
|
||||||
|
|
||||||
|
|
||||||
protected $dates = ['mouvement_created_at'];
|
protected $dates = ['mouvement_created_at'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'mouvement_nombre',
|
'mouvement_nombre',
|
||||||
'mouvement_created_at'
|
'mouvement_created_at'
|
||||||
|
|
@ -38,6 +42,6 @@ class Mouvement extends Model
|
||||||
*/
|
*/
|
||||||
public function coupon()
|
public function coupon()
|
||||||
{
|
{
|
||||||
return $this->belongsTo('App\Coupon', 'mouvement_couponId');
|
return $this->belongsTo(\App\Models\Coupon::class, 'mouvement_couponId');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,25 +1,27 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App;
|
namespace App\Models;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class Mur extends Model
|
class Mur extends Model
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected $table = 'mur';
|
protected $table = 'mur';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected $primaryKey = 'mur_id';
|
protected $primaryKey = 'mur_id';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var bool
|
* @var boolean
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public $timestamps = false;
|
public $timestamps = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -28,7 +30,7 @@ class Mur extends Model
|
||||||
*/
|
*/
|
||||||
public function campagne()
|
public function campagne()
|
||||||
{
|
{
|
||||||
return $this->belongsTo('App\Campagne', 'mur_campId');
|
return $this->belongsTo(\App\Models\Campagne::class, 'mur_campId');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -37,7 +39,7 @@ class Mur extends Model
|
||||||
*/
|
*/
|
||||||
public function contact()
|
public function contact()
|
||||||
{
|
{
|
||||||
return $this->belongsTo('App\Contact', 'mur_contactId');
|
return $this->belongsTo(\App\Models\Contact::class, 'mur_contactId');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -46,6 +48,6 @@ class Mur extends Model
|
||||||
*/
|
*/
|
||||||
public function coupon()
|
public function coupon()
|
||||||
{
|
{
|
||||||
return $this->belongsTo('App\Coupon', 'mur_couponId');
|
return $this->belongsTo(\App\Models\Coupon::class, 'mur_couponId');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,27 +1,30 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App;
|
namespace App\Models;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class Notification extends Model
|
class Notification extends Model
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected $table = 'notification';
|
protected $table = 'notification';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected $primaryKey = 'notif_id';
|
protected $primaryKey = 'notif_id';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var bool
|
* @var boolean
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public $timestamps = false;
|
public $timestamps = false;
|
||||||
|
|
||||||
|
|
||||||
protected $fillable = ['notif_name', 'notif_email', 'notif_campId'];
|
protected $fillable = ['notif_name', 'notif_email', 'notif_campId'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -30,6 +33,6 @@ class Notification extends Model
|
||||||
*/
|
*/
|
||||||
public function campagne()
|
public function campagne()
|
||||||
{
|
{
|
||||||
return $this->belongsTo('App\Campagne', 'notif_campId');
|
return $this->belongsTo(\App\Models\Campagne::class, 'notif_campId');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,35 +1,40 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class Panier extends Model
|
class Panier extends Model
|
||||||
{
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected $table = 'panier';
|
protected $table = 'panier';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected $primaryKey = 'panier_id';
|
protected $primaryKey = 'panier_id';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var bool
|
* @var boolean
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public $timestamps = false;
|
public $timestamps = false;
|
||||||
|
|
||||||
//protected $with = ['panierContents'];
|
// protected $with = ['panierContents'];
|
||||||
/**
|
/**
|
||||||
* OneToMany
|
* OneToMany
|
||||||
* Panier -> PanierContent
|
* Panier -> PanierContent
|
||||||
*/
|
*/
|
||||||
public function panierContents()
|
public function panierContents()
|
||||||
{
|
{
|
||||||
return $this->hasMany('App\PanierContent', 'panier_content_panierId', 'panier_id');
|
return $this->hasMany(\App\Models\PanierContent::class, 'panier_content_panierId', 'panier_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -38,7 +43,7 @@ class Panier extends Model
|
||||||
*/
|
*/
|
||||||
public function campagne()
|
public function campagne()
|
||||||
{
|
{
|
||||||
return $this->belongsTo('App\Campagne', 'panier_campId');
|
return $this->belongsTo(\App\Models\Campagne::class, 'panier_campId');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -47,6 +52,6 @@ class Panier extends Model
|
||||||
*/
|
*/
|
||||||
public function contact()
|
public function contact()
|
||||||
{
|
{
|
||||||
return $this->belongsTo('App\Contact', 'panier_contactId');
|
return $this->belongsTo(\App\Models\Contact::class, 'panier_contactId');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,25 +1,27 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App;
|
namespace App\Models;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class PanierContent extends Model
|
class PanierContent extends Model
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected $table = 'panier_content';
|
protected $table = 'panier_content';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected $primaryKey = 'panier_content_id';
|
protected $primaryKey = 'panier_content_id';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var bool
|
* @var boolean
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public $timestamps = false;
|
public $timestamps = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -28,7 +30,7 @@ class PanierContent extends Model
|
||||||
*/
|
*/
|
||||||
public function panier()
|
public function panier()
|
||||||
{
|
{
|
||||||
return $this->belongsTo('App\Panier', 'panier_content_panierId', 'panier_id');
|
return $this->belongsTo(\App\Models\Panier::class, 'panier_content_panierId', 'panier_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -37,12 +39,13 @@ class PanierContent extends Model
|
||||||
*/
|
*/
|
||||||
public function coupon()
|
public function coupon()
|
||||||
{
|
{
|
||||||
return $this->belongsTo('App\Coupon', 'panier_content_couponId');
|
return $this->belongsTo(\App\Models\Coupon::class, 'panier_content_couponId');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'panier_content_panierId',
|
'panier_content_panierId',
|
||||||
'panier_content_couponId',
|
'panier_content_couponId',
|
||||||
|
|
@ -5,7 +5,7 @@ namespace App\Models;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class PrintedWalls extends Model
|
class PrintedCoupons extends Model
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
}
|
}
|
||||||
|
|
@ -1,35 +1,42 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class Site extends Model
|
class Site extends Model
|
||||||
{
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected $table = 'site';
|
protected $table = 'site';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected $primaryKey = 'id';
|
protected $primaryKey = 'id';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected $keyType = 'string';
|
protected $keyType = 'string';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var bool
|
* @var boolean
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public $timestamps = false;
|
public $timestamps = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected $fillable = ['site_nom', 'site_logo', 'site_contact', 'site_rcs', 'site_libelle'];
|
protected $fillable = ['site_nom', 'site_logo', 'site_contact', 'site_rcs', 'site_libelle'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -38,7 +45,7 @@ class Site extends Model
|
||||||
*/
|
*/
|
||||||
public function campagnes()
|
public function campagnes()
|
||||||
{
|
{
|
||||||
return $this->hasMany('App\Campagne', 'camp_siteId', 'site_id');
|
return $this->hasMany(\App\Models\Campagne::class, 'camp_siteId', 'site_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -47,7 +54,7 @@ class Site extends Model
|
||||||
*/
|
*/
|
||||||
public function contacts()
|
public function contacts()
|
||||||
{
|
{
|
||||||
return $this->hasMany('App\Contact', 'contact_siteId', 'site_id');
|
return $this->hasMany(\App\Models\Contact::class, 'contact_siteId', 'site_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -55,22 +62,22 @@ class Site extends Model
|
||||||
*/
|
*/
|
||||||
public function users()
|
public function users()
|
||||||
{
|
{
|
||||||
return $this->belongsToMany('App\User', 'site_user', 'site_id', 'user_id');
|
return $this->belongsToMany(\App\Models\User::class, 'site_user', 'site_id', 'user_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OneToMany
|
* OneToMany
|
||||||
* Site -> Coupon
|
* Site -> Coupon
|
||||||
*/
|
*/
|
||||||
public function coupons()
|
public function coupons()
|
||||||
{
|
{
|
||||||
return $this->hasMany('App\Coupon', 'coupon_siteId', 'id');
|
return $this->hasMany(\App\Models\Coupon::class, 'coupon_siteId', 'id');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function __toString()
|
public function __toString(): string
|
||||||
{
|
{
|
||||||
return $this->site_id . " : " . $this->site_nom;
|
return $this->site_id . " : " . $this->site_nom;
|
||||||
}
|
}
|
||||||
78
app/Models/Statistique.php
Normal file
78
app/Models/Statistique.php
Normal file
|
|
@ -0,0 +1,78 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Statistique extends Model
|
||||||
|
{
|
||||||
|
|
||||||
|
public $timestamps = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected $table = 'statistiques';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
const CREATED_AT = 'created_at';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'stat_campId',
|
||||||
|
'stat_couponId',
|
||||||
|
'stat_couponPrinted',
|
||||||
|
'date'
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected $casts = [
|
||||||
|
'date' => 'date'
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform any actions required after the model boots.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected static function booted(): void
|
||||||
|
{
|
||||||
|
static::creating(function (self $model): void {
|
||||||
|
$model->date = now()->toDateString();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// * RELATIONS
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ArchiveCoupon model relation
|
||||||
|
* @return Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||||
|
*/
|
||||||
|
public function campaign()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Campagne::class, 'stat_campId', 'camp_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ArchiveCampaign model relation
|
||||||
|
* @return Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||||
|
*/
|
||||||
|
public function coupon()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Coupon::class, 'stat_couponId', 'coupon_id');
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue