Compare commits
No commits in common. "main" and "master" have entirely different histories.
365 changed files with 74182 additions and 85 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
|
||||
15
.editorconfig
Normal file
15
.editorconfig
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[*.yml]
|
||||
indent_size = 2
|
||||
35
.env.example
Normal file
35
.env.example
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
APP_NAME=Laravel
|
||||
APP_ENV=local
|
||||
APP_KEY=
|
||||
APP_DEBUG=true
|
||||
APP_URL=http://localhost
|
||||
|
||||
LOG_CHANNEL=stack
|
||||
|
||||
DB_CONNECTION=mysql
|
||||
DB_HOST=dev-mysql
|
||||
DB_PORT=3306
|
||||
DB_DATABASE=homestead
|
||||
DB_USERNAME=homestead
|
||||
DB_PASSWORD=secret
|
||||
|
||||
BROADCAST_DRIVER=log
|
||||
CACHE_DRIVER=file
|
||||
QUEUE_CONNECTION=sync
|
||||
SESSION_DRIVER=file
|
||||
SESSION_LIFETIME=120
|
||||
|
||||
MAIL_DRIVER=smtp
|
||||
MAIL_HOST=dev-mailpit
|
||||
MAIL_PORT=1025
|
||||
MAIL_USERNAME=null
|
||||
MAIL_PASSWORD=null
|
||||
MAIL_ENCRYPTION=null
|
||||
MAIL_FROM_ADDRESS=
|
||||
MAIL_FROM_NAME=
|
||||
|
||||
# CRM
|
||||
CRM_ENDPOINT=
|
||||
|
||||
# Sentry
|
||||
SENTRY_LARAVEL_DSN=
|
||||
5
.gitattributes
vendored
Normal file
5
.gitattributes
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
* text=auto
|
||||
*.css linguist-vendored
|
||||
*.scss linguist-vendored
|
||||
*.js linguist-vendored
|
||||
CHANGELOG.md export-ignore
|
||||
37
.gitignore
vendored
Normal file
37
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
.env
|
||||
.env.backup
|
||||
.env.testing
|
||||
.env.production
|
||||
.phpunit.result.cache
|
||||
.stylelintcache
|
||||
/.fleet
|
||||
/.idea
|
||||
/.phpunit.cache
|
||||
/.vscode
|
||||
/node_modules
|
||||
/bootstrap
|
||||
/public/build
|
||||
/public/cache
|
||||
/public/hot
|
||||
/public/sitemap.xml
|
||||
/public/storage
|
||||
/public/export/*
|
||||
!/public/export/.gitkeep
|
||||
/storage/*.key
|
||||
/vendor
|
||||
auth.json
|
||||
docker-compose.override.yml
|
||||
Homestead.json
|
||||
Homestead.yaml
|
||||
npm-debug.log
|
||||
yarn-error.log
|
||||
.npmrc
|
||||
/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
|
||||
92
README.md
92
README.md
|
|
@ -1,92 +1,14 @@
|
|||
# MesBR
|
||||
|
||||
## Tests unitaires
|
||||
|
||||
```bash
|
||||
cp .env .env.testing
|
||||
|
||||
## Getting started
|
||||
// Update db vars
|
||||
|
||||
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
|
||||
|
||||
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
|
||||
|
||||
## Add your files
|
||||
|
||||
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
|
||||
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
|
||||
|
||||
```
|
||||
cd existing_repo
|
||||
git remote add origin https://lab.s-web.fr/ldc-web/projets/mesbr.git
|
||||
git branch -M main
|
||||
git push -uf origin main
|
||||
php artisan test
|
||||
```
|
||||
|
||||
## Integrate with your tools
|
||||
|
||||
- [ ] [Set up project integrations](https://lab.s-web.fr/ldc-web/projets/mesbr/-/settings/integrations)
|
||||
|
||||
## Collaborate with your team
|
||||
|
||||
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
|
||||
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
|
||||
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
|
||||
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
|
||||
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
|
||||
|
||||
## Test and Deploy
|
||||
|
||||
Use the built-in continuous integration in GitLab.
|
||||
|
||||
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
|
||||
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
|
||||
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
|
||||
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
|
||||
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
|
||||
|
||||
***
|
||||
|
||||
# Editing this README
|
||||
|
||||
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
|
||||
|
||||
## Suggestions for a good README
|
||||
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
|
||||
|
||||
## Name
|
||||
Choose a self-explaining name for your project.
|
||||
|
||||
## Description
|
||||
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
|
||||
|
||||
## Badges
|
||||
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
|
||||
|
||||
## Visuals
|
||||
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
|
||||
|
||||
## Installation
|
||||
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
|
||||
|
||||
## Usage
|
||||
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
|
||||
|
||||
## Support
|
||||
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
|
||||
|
||||
## Roadmap
|
||||
If you have ideas for releases in the future, it is a good idea to list them in the README.
|
||||
|
||||
## Contributing
|
||||
State if you are open to contributions and what your requirements are for accepting them.
|
||||
|
||||
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
|
||||
|
||||
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
|
||||
|
||||
## Authors and acknowledgment
|
||||
Show your appreciation to those who have contributed to the project.
|
||||
|
||||
## License
|
||||
For open source projects, say how it is licensed.
|
||||
|
||||
## Project status
|
||||
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
|
||||
## 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 👌');
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
115
app/Console/Kernel.php
Normal file
115
app/Console/Kernel.php
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
use App\Models\Site;
|
||||
use App\Models\Campagne;
|
||||
use App\Jobs\ArchiveStatsJob;
|
||||
use App\Jobs\CleanOldDatasJob;
|
||||
use App\Models\User;
|
||||
use App\Models\Notification;
|
||||
use App\Mail\AlertBr;
|
||||
use App\Mail\AlertBrAdmin;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use App\Traits\CouponTrait;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
use CouponTrait;
|
||||
|
||||
/**
|
||||
* The Artisan commands provided by your application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $commands = [
|
||||
\App\Console\Commands\CustomersClaims::class,
|
||||
\App\Console\Commands\ArchiveStatsCommand::class,
|
||||
\App\Console\Commands\RegenBRBase::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* Define the application's command schedule.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
||||
* @return void
|
||||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
// Archive stats every day at 2:00 AM (to prevent time difference between the server and the reality).
|
||||
$schedule->job(ArchiveStatsJob::class)->dailyAt('2:00');
|
||||
|
||||
// Clean datas older than 3 years every day at midnight.
|
||||
$schedule->job(CleanOldDatasJob::class)->daily();
|
||||
|
||||
// ---- 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();
|
||||
foreach ($campagnes as $campagne) {
|
||||
$sendMail = false;
|
||||
$users = [];
|
||||
$couponSeuil = [];
|
||||
$couponDiffusion = [];
|
||||
$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;
|
||||
}
|
||||
} //end if
|
||||
} //end foreach
|
||||
|
||||
if ($sendMail) {
|
||||
Mail::to($users)->send(new AlertBr($couponSeuil, $couponDiffusion, $site->site_nom));
|
||||
}
|
||||
} //end foreach
|
||||
} //end foreach
|
||||
if ($sendGlobal) {
|
||||
$superadmins = [];
|
||||
$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));
|
||||
}
|
||||
})->weekdays()->at('7:00');
|
||||
}
|
||||
}
|
||||
39
app/Enums/CampaignTypes.php
Normal file
39
app/Enums/CampaignTypes.php
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use Kwaadpepper\Enum\BaseEnum;
|
||||
|
||||
/**
|
||||
* @method static self mur()
|
||||
* value 0 Mur (POUR LES MURS)
|
||||
* @method static self panier()
|
||||
* value 1 Panier (POUR LES PANIERS)
|
||||
* @method static self murss()
|
||||
* value 2 Mur sans sélection (POUR LES MURS SANS SELECTION)
|
||||
* @method static self paniers()
|
||||
* value 3 Panier Sélectionnable (POUR LES PANIERS AVEC SELECTION)
|
||||
*/
|
||||
|
||||
class CampaignTypes extends BaseEnum
|
||||
{
|
||||
protected static function values(): array
|
||||
{
|
||||
return [
|
||||
'mur' => 0,
|
||||
'panier' => 1,
|
||||
'murss' => 2,
|
||||
'paniers' => 3,
|
||||
];
|
||||
}
|
||||
|
||||
protected static function labels(): array
|
||||
{
|
||||
return [
|
||||
'mur' => trans('Mur'),
|
||||
'panier' => trans('Panier'),
|
||||
'murss' => trans('Mur sans sélection'),
|
||||
'paniers' => trans('Panier Sélectionnable'),
|
||||
];
|
||||
}
|
||||
}
|
||||
32
app/Enums/Countries.php
Normal file
32
app/Enums/Countries.php
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use Kwaadpepper\Enum\BaseEnum;
|
||||
|
||||
/**
|
||||
* @method static self france()
|
||||
* @method static self belgique()
|
||||
* @method static self luxembourg()
|
||||
*/
|
||||
|
||||
class Countries extends BaseEnum
|
||||
{
|
||||
protected static function values(): array
|
||||
{
|
||||
return [
|
||||
'france' => 250,
|
||||
'belgique' => 56,
|
||||
'luxembourg' => 442,
|
||||
];
|
||||
}
|
||||
|
||||
protected static function labels(): array
|
||||
{
|
||||
return [
|
||||
'france' => 'France',
|
||||
'belgique' => 'Belgique',
|
||||
'luxembourg' => 'Luxembourg',
|
||||
];
|
||||
}
|
||||
}
|
||||
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',
|
||||
];
|
||||
}
|
||||
}
|
||||
32
app/Enums/UserRoles.php
Normal file
32
app/Enums/UserRoles.php
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use Kwaadpepper\Enum\BaseEnum;
|
||||
|
||||
/**
|
||||
* @method static self superadmin()
|
||||
* @method static self admin()
|
||||
* @method static self marketing()
|
||||
*/
|
||||
|
||||
class UserRoles extends BaseEnum
|
||||
{
|
||||
protected static function values(): array
|
||||
{
|
||||
return [
|
||||
'superadmin' => 'superadmin',
|
||||
'admin' => 'admin',
|
||||
'marketing' => 'marketing'
|
||||
];
|
||||
}
|
||||
|
||||
protected static function labels(): array
|
||||
{
|
||||
return [
|
||||
'superadmin' => trans('Super-Admin'),
|
||||
'admin' => trans('Admin'),
|
||||
'marketing' => trans('Marketing')
|
||||
];
|
||||
}
|
||||
}
|
||||
67
app/Exceptions/Handler.php
Normal file
67
app/Exceptions/Handler.php
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use App\Http\Resources\StatusResource;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Throwable;
|
||||
|
||||
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.
|
||||
*
|
||||
* @var array<int, class-string<\Throwable>>
|
||||
*/
|
||||
|
||||
protected $dontReport = [];
|
||||
|
||||
/**
|
||||
* A list of the inputs that are never flashed to the session on validation exceptions.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
|
||||
protected $dontFlash = [
|
||||
'current_password',
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
|
||||
/**
|
||||
* Register the exception handling callbacks for the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->reportable(function (Throwable $e): void {
|
||||
if (app()->bound('sentry')) {
|
||||
resolve('sentry')->captureException($e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an exception into an HTTP response.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Throwable $exception
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function render($request, Throwable $exception)
|
||||
{
|
||||
if ($request->wantsJson() && $exception instanceof ModelNotFoundException) {
|
||||
return response()->json(new StatusResource(['status' => 'KO', 'code' => 404, 'message' => 'Resource not found.']), 404);
|
||||
}
|
||||
return parent::render($request, $exception);
|
||||
}
|
||||
}
|
||||
302
app/Http/Controllers/AjaxController.php
Normal file
302
app/Http/Controllers/AjaxController.php
Normal file
|
|
@ -0,0 +1,302 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Campagne;
|
||||
use App\Models\Coupon;
|
||||
use App\Enums\CampaignTypes;
|
||||
use App\Models\PanierContent;
|
||||
use App\Models\Statistique;
|
||||
use App\Models\Mur;
|
||||
use App\Models\Log;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Traits\GenerateBR;
|
||||
use App\Traits\CouponTrait;
|
||||
|
||||
class AjaxController extends Controller
|
||||
{
|
||||
use GenerateBR;
|
||||
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
|
||||
public function unpublishCouponsAjax(Request $request)
|
||||
{
|
||||
$coupon_id = $request->input('couponid');
|
||||
$coupon = Coupon::find($coupon_id);
|
||||
$coupon->coupon_published = 0;
|
||||
$coupon->save();
|
||||
|
||||
return json_encode($coupon);
|
||||
}
|
||||
|
||||
// ---- Publie un coupon
|
||||
public function publishCouponsAjax(Request $request)
|
||||
{
|
||||
$coupon_id = $request->input('couponid');
|
||||
$coupon = Coupon::find($coupon_id);
|
||||
$coupon->coupon_published = 1;
|
||||
$coupon->save();
|
||||
|
||||
return json_encode($coupon);
|
||||
}
|
||||
|
||||
// ---- Impression des BR
|
||||
public function impressionAjax(Request $request)
|
||||
{
|
||||
|
||||
if ($request->session()->has('coupons')) {
|
||||
$couponsToPrint = $request->session()->get('coupons');
|
||||
}
|
||||
if ($request->session()->has('campagne')) {
|
||||
$campagne = $request->session()->get('campagne');
|
||||
} else {
|
||||
die();
|
||||
}
|
||||
if ($request->session()->has('contact')) {
|
||||
$contact = $request->session()->get('contact');
|
||||
} else {
|
||||
die();
|
||||
}
|
||||
if ($request->session()->has('panier')) {
|
||||
$panier = $request->session()->get('panier');
|
||||
}
|
||||
|
||||
if ($contact->contact_ref == "DEMO") {
|
||||
$source = 'ADMIN';
|
||||
} else {
|
||||
$source = 'API';
|
||||
}
|
||||
|
||||
// ---- INIT du log
|
||||
$log = new Log();
|
||||
$log->log_action = config('constants.impression');
|
||||
$log->log_source = $source;
|
||||
$log->log_contactId = $contact->contact_id;
|
||||
$log->log_refsite = $campagne->camp_siteId;
|
||||
$log->log_params = json_encode(['refcamp' => $campagne->camp_id]);
|
||||
|
||||
$couponsPrinted = [];
|
||||
|
||||
$coupons = '<TABLE width="100%" align="center" cellpadding="0" cellspacing="0" border="0">';
|
||||
$coupons .= '<TR><TD width="100%" align="center"><div>';
|
||||
|
||||
if ($campagne->camp_type->equals(CampaignTypes::mur())) {
|
||||
// ---- POUR LES MURS
|
||||
if (!isset($couponsToPrint)) {
|
||||
die();
|
||||
}
|
||||
$nbCoupon = 0;
|
||||
|
||||
foreach ($couponsToPrint as $coupon_code) {
|
||||
$cp = Coupon::where(['coupon_code' => $coupon_code])->first();
|
||||
|
||||
if ($this->isAvailable($cp, $campagne, $contact) && $this->isAvailableToPrint($cp, $campagne)) {
|
||||
array_push($couponsPrinted, ['cp_code' => $cp->coupon_code, 'qty' => 1]);
|
||||
|
||||
$imgCoupon = $this->printCp($cp, $contact);
|
||||
$coupons .= '<img src="' . $imgCoupon . '" border="0" style="display:block;width:165mm;"/>';
|
||||
$nbCoupon++;
|
||||
if ($nbCoupon % 3 == 0) {
|
||||
$coupons .= '</div><div>';
|
||||
}
|
||||
|
||||
// ----- mémorise l'impression
|
||||
$mur = new Mur();
|
||||
$mur->mur_campid = $campagne->camp_id;
|
||||
$mur->mur_contactId = $contact->contact_id;
|
||||
$mur->mur_couponId = $cp->coupon_id;
|
||||
$mur->save();
|
||||
|
||||
// Sauvegarde de stat
|
||||
$this->saveStat($campagne, $cp);
|
||||
}//end if
|
||||
}//end foreach
|
||||
} elseif ($campagne->camp_type->equals(CampaignTypes::panier())) {
|
||||
// ---- POUR LES PANIERS
|
||||
if (!isset($panier)) {
|
||||
die();
|
||||
}
|
||||
|
||||
$allPanierContent = $panier->panierContents()->get();
|
||||
if (count($allPanierContent) == 0) {
|
||||
die("error");
|
||||
}
|
||||
$nbCoupon = 0;
|
||||
|
||||
foreach ($allPanierContent as $panierContent) {
|
||||
$cp = Coupon::where(['coupon_id' => $panierContent->panier_content_couponId])->first();
|
||||
if ($cp && $this->isAvailableToPrint($cp, $campagne)) {
|
||||
$imgCoupon = $this->printCp($cp, $contact);
|
||||
// ---- Création du html du contenu à imprimer
|
||||
if ($campagne->camp_limitedPrinting == 0) {
|
||||
for ($i = 0; $i < $panierContent->panier_content_quantity; $i++) {
|
||||
$coupons .= '<img src="' . $imgCoupon . '" border="0" style="display:block;width:165mm;"/>';
|
||||
$nbCoupon++;
|
||||
if ($nbCoupon % 3 == 0) {
|
||||
$coupons .= '</div><div>';
|
||||
}
|
||||
}
|
||||
$newQtyAvailable = 0;
|
||||
$newQtyPrinted = $panierContent->panier_content_quantity + $panierContent->panier_content_printed;
|
||||
array_push($couponsPrinted, ['cp_code' => $cp->coupon_code, 'qty' => $panierContent->panier_content_quantity]);
|
||||
|
||||
// Sauvegarde de stat
|
||||
$this->saveStat($campagne, $cp);
|
||||
} else {
|
||||
if ($panierContent->panier_content_quantity > 0) {
|
||||
$coupons .= '<img src="' . $imgCoupon . '" border="0" style="display:block;width:165mm;"/>';
|
||||
$nbCoupon++;
|
||||
if ($nbCoupon % 3 == 0) {
|
||||
$coupons .= '</div><div>';
|
||||
}
|
||||
$newQtyAvailable = $panierContent->panier_content_quantity - 1;
|
||||
$newQtyPrinted = $panierContent->panier_content_printed + 1;
|
||||
array_push($couponsPrinted, ['cp_code' => $cp->coupon_code, 'qty' => 1]);
|
||||
|
||||
// Sauvegarde de stat
|
||||
$this->saveStat($campagne, $cp);
|
||||
}
|
||||
}//end if
|
||||
// ---- Mémorise l'impression
|
||||
$panierContent->panier_content_quantity = $newQtyAvailable;
|
||||
$panierContent->panier_content_printed = $newQtyPrinted;
|
||||
$panierContent->save();
|
||||
}//end if
|
||||
}//end foreach
|
||||
// ---- Update du status du panier
|
||||
$qty = $panier->panierContents()->sum('panier_content_quantity');
|
||||
if ($qty == 0) {
|
||||
$panier->panier_pending = 0;
|
||||
} else {
|
||||
$panier->panier_pending = 1;
|
||||
}
|
||||
$panier->save();
|
||||
} elseif ($campagne->camp_type->equals(CampaignTypes::murss())) {
|
||||
// ---- POUR LES MURS SANS SELECTION
|
||||
$nbCoupon = 0;
|
||||
$cps = $campagne->coupons()->get();
|
||||
|
||||
foreach ($cps as $cp) {
|
||||
// ---- Contrôle si le BR a déjà fait l'objet d'une impression
|
||||
if ($this->isAvailable($cp, $campagne, $contact) && $this->isAvailableToPrint($cp, $campagne)) {
|
||||
// ---- Génère l'image du BR à imprimer
|
||||
$imgCoupon = $this->printCp($cp, $contact);
|
||||
$coupons .= '<img src="' . $imgCoupon . '" border="0" style="display:block;width:165mm;"/>';
|
||||
$nbCoupon++;
|
||||
if ($nbCoupon % 3 == 0) {
|
||||
$coupons .= '</div><div>';
|
||||
}
|
||||
array_push($couponsPrinted, ['cp_code' => $cp->coupon_code, 'qty' => 1]);
|
||||
// ----- mémorise l'impression
|
||||
$mur = new Mur();
|
||||
$mur->mur_campid = $campagne->camp_id;
|
||||
$mur->mur_contactId = $contact->contact_id;
|
||||
$mur->mur_couponId = $cp->coupon_id;
|
||||
$mur->save();
|
||||
|
||||
// Sauvegarde de stat
|
||||
$this->saveStat($campagne, $cp);
|
||||
}//end if
|
||||
}//end foreach
|
||||
} elseif ($campagne->camp_type->equals(CampaignTypes::paniers())) {
|
||||
// ---- POUR LES PANIERS AVEC SELECTION
|
||||
if (!isset($couponsToPrint)) {
|
||||
die();
|
||||
}
|
||||
$nbCoupon = 0;
|
||||
if (!isset($panier)) {
|
||||
die();
|
||||
}
|
||||
foreach ($couponsToPrint as $coupon_code) {
|
||||
$cp = Coupon::where(['coupon_code' => $coupon_code])->first();
|
||||
|
||||
if ($this->isAvailable($cp, $campagne, $contact) && $this->isAvailableToPrint($cp, $campagne)) {
|
||||
$imgCoupon = $this->printCp($cp, $contact);
|
||||
$panierContent = PanierContent::where(['panier_content_couponId' => $cp->coupon_id, 'panier_content_panierId' => $panier->panier_id])->first();
|
||||
if ($panierContent->panier_content_quantity > 0) {
|
||||
$coupons .= '<img src="' . $imgCoupon . '" border="0" style="display:block;width:165mm;"/>';
|
||||
$nbCoupon++;
|
||||
if ($nbCoupon % 3 == 0) {
|
||||
$coupons .= '</div><div>';
|
||||
}
|
||||
$newQtyAvailable = $panierContent->panier_content_quantity - 1;
|
||||
$newQtyPrinted = $panierContent->panier_content_printed + 1;
|
||||
|
||||
// Sauvegarde de stat
|
||||
$this->saveStat($campagne, $cp);
|
||||
|
||||
// ---- Mémorise l'impression
|
||||
$panierContent->panier_content_quantity = $newQtyAvailable;
|
||||
$panierContent->panier_content_printed = $newQtyPrinted;
|
||||
$panierContent->save();
|
||||
}
|
||||
array_push($couponsPrinted, ['cp_code' => $cp->coupon_code, 'qty' => 1]);
|
||||
}//end if
|
||||
}//end foreach
|
||||
// ---- Update du status du panier
|
||||
$qty = $panier->panierContents()->sum('panier_content_quantity');
|
||||
if ($qty == 0) {
|
||||
$panier->panier_pending = 0;
|
||||
} else {
|
||||
$panier->panier_pending = 1;
|
||||
}
|
||||
$panier->save();
|
||||
}//end if
|
||||
|
||||
$coupons .= '</div></TD></TR>';
|
||||
$coupons .= '</TABLE>';
|
||||
|
||||
$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->save();
|
||||
|
||||
|
||||
return $coupons;
|
||||
}
|
||||
|
||||
// ---- Retour au bon index une fois l'impression faite
|
||||
public function backToIndex(Request $request)
|
||||
{
|
||||
|
||||
if ($request->session()->has('campagne')) {
|
||||
$campagne = $request->session()->get('campagne');
|
||||
} else {
|
||||
die();
|
||||
}
|
||||
|
||||
if ($campagne->camp_type->equals(CampaignTypes::panier()) || $campagne->camp_type->equals(CampaignTypes::paniers())) {
|
||||
if ($request->session()->has('panier')) {
|
||||
$panier = $request->session()->get('panier');
|
||||
} else {
|
||||
die();
|
||||
}
|
||||
return redirect(url('/') . '/?basketid=' . $panier->panier_ref);
|
||||
}
|
||||
}
|
||||
}
|
||||
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
|
||||
]);
|
||||
}
|
||||
}
|
||||
79
app/Http/Controllers/Api/v1/CouponsController.php
Normal file
79
app/Http/Controllers/Api/v1/CouponsController.php
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\v1;
|
||||
|
||||
use App\Models\Campagne;
|
||||
use App\Models\Coupon;
|
||||
use App\Enums\CampaignTypes;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Coupons\PrintRequest;
|
||||
use App\Http\Resources\StatusResource;
|
||||
use App\Models\Customers;
|
||||
use App\Traits\CouponTrait;
|
||||
use App\Traits\GenerateBR;
|
||||
use PDF;
|
||||
use LDC\LDCCRM\CrmApiV4;
|
||||
|
||||
class CouponsController extends Controller
|
||||
{
|
||||
use CouponTrait;
|
||||
use GenerateBR;
|
||||
|
||||
public function print(PrintRequest $request)
|
||||
{
|
||||
$datas = $request->validated();
|
||||
$campagne = Campagne::find($datas['refcamp']);
|
||||
$customer = Customers::find($datas['hashcode']);
|
||||
$couponsToPrint = explode(",", $datas['coupons']);
|
||||
$type = $request->validated()['type'] ?? 'stream';
|
||||
|
||||
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]);
|
||||
}
|
||||
|
||||
if ($campagne->site->crm_password === null) {
|
||||
return new StatusResource(['status' => 'KO', 'code' => 500, 'message' => 'CRM Password is missing for site_id : ' . $campagne->site->site_id]);
|
||||
}
|
||||
|
||||
if (empty($couponsToPrint)) {
|
||||
return new StatusResource(['status' => 'KO', 'code' => 422, 'message' => 'Coupons not found.']);
|
||||
}
|
||||
|
||||
$crm = new CrmApiV4(config('services.crm.endpoint'), $campagne->site->crm_token, $campagne->site->crm_password);
|
||||
|
||||
try {
|
||||
/**
|
||||
* @var \LDC\LDCCRM\Models\Customer
|
||||
*/
|
||||
$crmInfos = $crm->getCustomer($customer->hashcode);
|
||||
} catch (\Exception) {
|
||||
// TODO : Update error message
|
||||
return new StatusResource(['status' => 'KO', 'code' => 422, 'message' => 'Customer not found.']);
|
||||
}
|
||||
|
||||
if (is_null($crmInfos)) {
|
||||
return new StatusResource(['status' => 'KO', 'code' => 422, 'message' => 'Customer not found.']);
|
||||
}
|
||||
|
||||
// TODO : Vérifier si les coupons sont dans la campagne
|
||||
// TODO : Logs
|
||||
$coupons = [];
|
||||
if ($campagne->camp_type->equals(CampaignTypes::mur())) {
|
||||
// ---- POUR LES MURS
|
||||
foreach ($couponsToPrint as $coupon_code) {
|
||||
$cp = Coupon::where(['coupon_code' => $coupon_code])->first();
|
||||
|
||||
if (!$this->isUsed($cp, $campagne, $customer)) {
|
||||
$coupons[] = $this->printCoupon($cp, $customer, $crmInfos, $campagne);
|
||||
}
|
||||
}//end foreach
|
||||
}//end if
|
||||
|
||||
// $coupons contains all printed 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'))))]);
|
||||
}
|
||||
}
|
||||
250
app/Http/Controllers/Api/v1/CustomerController.php
Normal file
250
app/Http/Controllers/Api/v1/CustomerController.php
Normal file
|
|
@ -0,0 +1,250 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\v1;
|
||||
|
||||
use App\Models\Calendrier;
|
||||
use App\Models\Campagne;
|
||||
use App\Enums\CampaignTypes;
|
||||
use App\Http\Requests\Customers\StoreRequest;
|
||||
use App\Http\Resources\CustomersResource;
|
||||
use App\Http\Resources\StatusResource;
|
||||
use App\Models\Customers;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Customers\BasketRequest;
|
||||
use App\Http\Requests\Customers\MurRequest;
|
||||
use App\Http\Resources\CouponsResource;
|
||||
use App\Traits\CouponTrait;
|
||||
use App\Traits\GenerateBR;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
|
||||
class CustomerController extends Controller
|
||||
{
|
||||
use CouponTrait;
|
||||
use GenerateBR;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return StatusResource
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return new StatusResource(['status' => 'KO', 'code' => '501', 'message' => 'Not Implemented']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return StatusResource
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return new StatusResource(['status' => 'KO', 'code' => '501', 'message' => 'Not Implemented']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param StoreRequest $request
|
||||
* @return CustomersResource | StatusResource
|
||||
*/
|
||||
public function store(StoreRequest $request)
|
||||
{
|
||||
$datas = $request->validated();
|
||||
try {
|
||||
$customer = Customers::where([
|
||||
['hashcode', $datas['hashcode']],
|
||||
['email', $datas['email']]
|
||||
])->firstOrNew();
|
||||
$customer->fill($datas);
|
||||
$customer->saveOrFail();
|
||||
|
||||
return new CustomersResource($customer);
|
||||
} catch (\Throwable $e) {
|
||||
Log::critical($e->getMessage());
|
||||
return new StatusResource(['status' => 'KO', 'code' => '500', 'message' => 'Server Error.']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param integer $id
|
||||
* @return StatusResource
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
return new StatusResource(['status' => 'KO', 'code' => '501', 'message' => 'Not Implemented']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param integer $id
|
||||
* @return StatusResource
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
return new StatusResource(['status' => 'KO', 'code' => '501', 'message' => 'Not Implemented']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return StatusResource
|
||||
*/
|
||||
public function update(Request $request)
|
||||
{
|
||||
return new StatusResource(['status' => 'KO', 'code' => '501', 'message' => 'Not Implemented']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param integer $id
|
||||
* @return StatusResource
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
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)
|
||||
{
|
||||
$datas = $request->validated();
|
||||
|
||||
$customer = Customers::where('hashcode', $datas['hashcode'])->first();
|
||||
$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) {
|
||||
return new StatusResource(['status' => 'KO', 'code' => 404, 'message' => 'Campaign not found.']);
|
||||
}
|
||||
|
||||
$coupons = $campagne->coupons()->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())")->get();
|
||||
|
||||
$montantDispo = 0;
|
||||
$montantTotal = 0;
|
||||
|
||||
// TODO : Improve
|
||||
foreach ($coupons as $key => $coupon) {
|
||||
// ---- Contrôle des calendriers de diffusion
|
||||
$calendars = Calendrier::where(['calendrier_couponId' => $coupon->coupon_id])->get();
|
||||
if (!$calendars->isEmpty()) {
|
||||
$pub = false;
|
||||
foreach ($calendars as $calendar) {
|
||||
if ($calendar->isPublished()) {
|
||||
$pub = true;
|
||||
}
|
||||
}
|
||||
if (!$pub) {
|
||||
$coupons->forget($key);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Available for user
|
||||
$coupon->isUsed = $this->isUsed($coupon, $campagne, $customer);
|
||||
|
||||
$montantTotal += $coupon->coupon_value;
|
||||
if (!$coupon->isUsed) {
|
||||
$montantDispo += $coupon->coupon_value;
|
||||
}
|
||||
}//end foreach
|
||||
|
||||
return new StatusResource([
|
||||
'status' => "OK",
|
||||
'name' => $campagne->camp_name,
|
||||
'limited_printing' => $campagne->camp_limitedPrinting,
|
||||
'total' => count($coupons),
|
||||
'available_amount' => $montantDispo,
|
||||
'total_amount' => $montantTotal,
|
||||
'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
|
||||
]);
|
||||
}
|
||||
}
|
||||
68
app/Http/Controllers/Api/v1/MurController.php
Normal file
68
app/Http/Controllers/Api/v1/MurController.php
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\v1;
|
||||
|
||||
use App\Models\Calendrier;
|
||||
use App\Models\Campagne;
|
||||
use App\Enums\CampaignTypes;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Murs\MursShowRequest;
|
||||
use App\Http\Resources\CouponsResource;
|
||||
use App\Http\Resources\StatusResource;
|
||||
use App\Traits\CouponTrait;
|
||||
|
||||
class MurController extends Controller
|
||||
{
|
||||
use CouponTrait;
|
||||
|
||||
public function show(MursShowRequest $request)
|
||||
{
|
||||
$datas = $request->validated();
|
||||
|
||||
$campagne = Campagne::find($datas['refcamp']);
|
||||
if ($campagne->camp_published === 0) {
|
||||
return new StatusResource(['status' => 'KO', 'code' => 404, 'message' => 'Campaign not found.']);
|
||||
}
|
||||
if (!$campagne->camp_type->equals(CampaignTypes::mur())) {
|
||||
return new StatusResource(['status' => 'KO', 'code' => 403, 'message' => 'Campaign type error.']);
|
||||
}
|
||||
|
||||
$coupons = $campagne->coupons()->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())")->get();
|
||||
|
||||
$montantDispo = 0;
|
||||
$montantTotal = 0;
|
||||
|
||||
// TODO : Improve
|
||||
foreach ($coupons as $key => $coupon) {
|
||||
// ---- Contrôle des calendriers de diffusion
|
||||
$calendars = Calendrier::where(['calendrier_couponId' => $coupon->coupon_id])->get();
|
||||
if (!$calendars->isEmpty()) {
|
||||
$pub = false;
|
||||
foreach ($calendars as $calendar) {
|
||||
if ($calendar->isPublished()) {
|
||||
$pub = true;
|
||||
}
|
||||
}
|
||||
if (!$pub) {
|
||||
$coupons->forget($key);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$montantTotal += $coupon->coupon_value;
|
||||
if (!$coupon->isUsed) {
|
||||
$montantDispo += $coupon->coupon_value;
|
||||
}
|
||||
}//end foreach
|
||||
|
||||
return new StatusResource([
|
||||
'status' => "OK",
|
||||
'name' => $campagne->camp_name,
|
||||
'limited_printing' => $campagne->camp_limitedPrinting,
|
||||
'total' => count($coupons),
|
||||
'available_amount' => $montantDispo,
|
||||
'total_amount' => $montantTotal,
|
||||
'coupons' => CouponsResource::collection($coupons)
|
||||
]);
|
||||
}
|
||||
}
|
||||
49
app/Http/Controllers/Auth/LoginController.php
Normal file
49
app/Http/Controllers/Auth/LoginController.php
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
||||
|
||||
class LoginController extends Controller
|
||||
{
|
||||
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.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = '/';
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest')->except('logout');
|
||||
}
|
||||
|
||||
/**
|
||||
* The user has been authenticated.
|
||||
*
|
||||
* @return \Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
protected function authenticated()
|
||||
{
|
||||
return redirect('/');
|
||||
}
|
||||
}
|
||||
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');
|
||||
}
|
||||
}
|
||||
}
|
||||
22
app/Http/Controllers/BrandChangeController.php
Normal file
22
app/Http/Controllers/BrandChangeController.php
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\BrandChange\InvokeBrandChange;
|
||||
|
||||
class BrandChangeController extends Controller
|
||||
{
|
||||
/**
|
||||
* Handle the incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\InvokeBrandChange $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function __invoke(InvokeBrandChange $request)
|
||||
{
|
||||
// TODO : Revoir le passage du site
|
||||
$site = \App\Models\Site::find($request->site_id);
|
||||
session()->put('site', $site);
|
||||
return back();
|
||||
}
|
||||
}
|
||||
415
app/Http/Controllers/CampagneController.php
Normal file
415
app/Http/Controllers/CampagneController.php
Normal file
|
|
@ -0,0 +1,415 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Campagne;
|
||||
use App\Models\Site;
|
||||
use App\Models\Coupon;
|
||||
use App\Models\Contact;
|
||||
use App\Enums\CampaignTypes;
|
||||
use App\Http\Requests\Campaign\AddCouponsCampaign;
|
||||
use App\Http\Requests\Campaign\DeleteCampaign;
|
||||
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\StoreNotifCampaign;
|
||||
use App\Http\Requests\Campaign\UpdateCampaign;
|
||||
use App\Models\Mur;
|
||||
use App\Models\PanierContent;
|
||||
use App\Models\Notification;
|
||||
use App\Models\Panier;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use App\Traits\CouponTrait;
|
||||
|
||||
class CampagneController extends Controller
|
||||
{
|
||||
use CouponTrait;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
// TODO : Revoir le passage du site id ?
|
||||
$siteId = session()->get('site')->site_id;
|
||||
|
||||
$campagnes = Campagne::where('camp_siteId', $siteId)->get();
|
||||
return view('campagnes.index')->with('campagnes', $campagnes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('campagnes.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param StoreCampaign $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(StoreCampaign $request)
|
||||
{
|
||||
// TODO : Revoir le passage du site
|
||||
$site = session()->get('site');
|
||||
|
||||
$campagne = new Campagne();
|
||||
$campagne->fill(array_merge($request->validated(), ['camp_siteId' => $site->site_id]));
|
||||
$campagne->save();
|
||||
|
||||
if ($site->campagnes()->save($campagne)) {
|
||||
if ($campagne->camp_type->equals(CampaignTypes::mur())) {
|
||||
File::copyDirectory(resource_path('/views/template/mur'), public_path('/landings/' . $campagne->camp_id));
|
||||
} elseif ($campagne->camp_type->equals(CampaignTypes::panier())) {
|
||||
File::copyDirectory(resource_path('/views/template/panier'), public_path('/landings/' . $campagne->camp_id));
|
||||
} elseif ($campagne->camp_type->equals(CampaignTypes::murss())) {
|
||||
File::copyDirectory(resource_path('/views/template/murnoselection'), public_path('/landings/' . $campagne->camp_id));
|
||||
} elseif ($campagne->camp_type->equals(CampaignTypes::paniers())) {
|
||||
File::copyDirectory(resource_path('/views/template/panierselection'), public_path('/landings/' . $campagne->camp_id));
|
||||
}
|
||||
}
|
||||
|
||||
return redirect(route('campagne.edit', ['campagne' => $campagne]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\Campagne $campagne
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(Campagne $campagne)
|
||||
{
|
||||
// TODO : Revoir le passage du site id
|
||||
$siteId = session()->get('site')->id;
|
||||
|
||||
$couponsNotLinked = Coupon::whereDoesntHave('campagnes', function (\Illuminate\Contracts\Database\Query\Builder $q) use ($campagne): void {
|
||||
$q->where('campagne_id', $campagne->camp_id);
|
||||
})->where('coupon_siteId', $siteId)->where('coupon_published', 1)->get();
|
||||
|
||||
return view('campagnes.edit', ['campagne' => $campagne, 'coupons' => $couponsNotLinked]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param UpdateCampaign $request
|
||||
* @param \App\Models\Campagne $campagne
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(UpdateCampaign $request, Campagne $campagne)
|
||||
{
|
||||
$campagne->fill($request->validated());
|
||||
|
||||
if (!isset($request->camp_limitedPrinting)) {
|
||||
$campagne->camp_limitedPrinting = 0;
|
||||
}
|
||||
|
||||
if ($campagne->save()) {
|
||||
session()->flash('update_ok', __('La campagne a bien été modifiée'));
|
||||
} else {
|
||||
session()->flash('update_nok', __("Erreur lors de l'enregistrement"));
|
||||
}
|
||||
|
||||
return to_route('campagne.edit', ['campagne' => $campagne]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param DeleteCampaign $request
|
||||
* @param \App\Models\Campagne $campagne
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(DeleteCampaign $request, Campagne $campagne)
|
||||
{
|
||||
$campagne->camp_published = 0;
|
||||
$campagne->save();
|
||||
|
||||
if ($campagne->delete()) {
|
||||
return redirect(route('campagne.index'));
|
||||
} else {
|
||||
session()->flash('delete_nok', 'Erreur lors de la suppression');
|
||||
return view('campagnes.edit')->with('campagne', $campagne);
|
||||
}
|
||||
}
|
||||
|
||||
// ---- Ajoute des coupons à une campagne
|
||||
public function addCoupons(AddCouponsCampaign $request, Campagne $campaign)
|
||||
{
|
||||
$coupons = Coupon::find($request->ids);
|
||||
$campaign->coupons()->attach($coupons);
|
||||
return json_encode($coupons);
|
||||
}
|
||||
|
||||
// ---- Efface des coupons d'une campagne
|
||||
public function removeCoupon(RemoveCouponCampaign $request, Campagne $campaign, Coupon $coupon)
|
||||
{
|
||||
$campaign->coupons()->detach($coupon);
|
||||
return json_encode($coupon);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function saveNotification(StoreNotifCampaign $request, Campagne $campaign)
|
||||
{
|
||||
$notification = new Notification();
|
||||
$notification->fill(array_merge($request->validated(), ['notif_campId' => $campaign->camp_id]));
|
||||
$notification->save();
|
||||
|
||||
return back();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RemoveNotifCampaign $request
|
||||
* @param \App\Models\Notification $notification
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function deleteNotification(RemoveNotifCampaign $request, Notification $notification)
|
||||
{
|
||||
if ($notification->delete()) {
|
||||
return back();
|
||||
} else {
|
||||
session()->flash('delete_nok', 'Erreur lors de la suppression');
|
||||
return back();
|
||||
}
|
||||
}
|
||||
|
||||
// ---- Montre les campagnes avec un compte de démo
|
||||
public function showDemo(ShowDemoCampaign $request, Campagne $campaign)
|
||||
{
|
||||
$siteId = $campaign->camp_siteId;
|
||||
$demoContact = Contact::where(['contact_siteId' => $siteId, 'contact_ref' => 'DEMO'])->first();
|
||||
|
||||
if (!isset($demoContact)) {
|
||||
$req = new \Illuminate\Http\Request();
|
||||
$req->setMethod('POST');
|
||||
$req->request->add([
|
||||
'refsite' => $siteId,
|
||||
'refadherent' => 'DEMO',
|
||||
'prenom' => 'Compte',
|
||||
'nom' => 'Démonstration',
|
||||
'email' => 'demo@demo.fr',
|
||||
'code_postal' => '72000',
|
||||
'commune' => 'Le Mans',
|
||||
'pays' => 250
|
||||
]);
|
||||
|
||||
$contact = new \App\Http\Controllers\ContactController();
|
||||
$res = $contact->updateContact($req);
|
||||
$demoContact = Contact::where(['contact_siteId' => $siteId, 'contact_ref' => 'DEMO'])->first();
|
||||
}
|
||||
|
||||
if ($campaign->camp_type->equals(CampaignTypes::mur()) || $campaign->camp_type->equals(CampaignTypes::murss())) {
|
||||
// ---- DEMONSTRATION POUR LES MURS
|
||||
$myRequest = new \Illuminate\Http\Request();
|
||||
$myRequest->setMethod('POST');
|
||||
$myRequest->request->add(['refcamp' => $campaign->camp_id, 'refadherent' => 'DEMO', 'admin' => 1]);
|
||||
|
||||
// ---- EFFACER LES CONTROLES SI EXISTANT
|
||||
$mur = new \App\Http\Controllers\MurController();
|
||||
$res = $mur->deleteControlContact($myRequest);
|
||||
|
||||
// ---- RETOURNE l'URL
|
||||
$url = "/?refsite=" . $siteId . "&refcamp=" . $campaign->camp_id . "&hash=" . $demoContact->contact_hash;
|
||||
return json_encode($url);
|
||||
} else {
|
||||
// ---- DEMONSTRATION POUR LES PANIERS
|
||||
$panier = Panier::where(['panier_campId' => $campaign->camp_id, 'panier_contactId' => $demoContact->contact_id, 'panier_pending' => 1])->first();
|
||||
|
||||
if ($panier) {
|
||||
$url = "/?basketid=" . $panier->panier_ref;
|
||||
} else {
|
||||
// --- Pas de panier Création d'un nouveau
|
||||
// --- Récuperation des coupons de la campagne
|
||||
$coupons = $campaign->coupons()->get();
|
||||
|
||||
foreach ($coupons as $key => $coupon) {
|
||||
if (!$this->isAvailableToPrint($coupon, $campaign)) {
|
||||
$coupons->forget($key);
|
||||
}
|
||||
}
|
||||
|
||||
$couponsTotal = count($coupons);
|
||||
$couponsAdded = 0;
|
||||
$basketContent = "";
|
||||
|
||||
foreach ($coupons as $coupon) {
|
||||
$basketContent .= "(1)" . $coupon->coupon_code;
|
||||
$couponsAdded++;
|
||||
if ($couponsAdded != $couponsTotal) {
|
||||
$basketContent .= ",";
|
||||
}
|
||||
}
|
||||
// --- création de l'objet request
|
||||
$req = new \Illuminate\Http\Request();
|
||||
$req->setMethod('POST');
|
||||
$req->request->add([
|
||||
'refsite' => $siteId,
|
||||
'refcamp' => $campaign->camp_id,
|
||||
'refadherent' => $demoContact->contact_ref,
|
||||
'nom' => $demoContact->contact_nom,
|
||||
'prenom' => $demoContact->contact_prenom,
|
||||
'email' => $demoContact->contact_email,
|
||||
'code_postal' => $demoContact->contact_cp,
|
||||
'commune' => $demoContact->contact_ville,
|
||||
'pays' => $demoContact->contact_country,
|
||||
'panier' => $basketContent,
|
||||
'admin' => 1
|
||||
]);
|
||||
$panier = new \App\Http\Controllers\PanierController();
|
||||
$res = $panier->updateBasket($req);
|
||||
$url = "/?basketid=" . $res->original['Panier']->Panier;
|
||||
}
|
||||
return json_encode($url);
|
||||
}
|
||||
}
|
||||
|
||||
// ---- Dépublie une campagne
|
||||
public function togglePublish(Request $request, Campagne $campaign, int $state)
|
||||
{
|
||||
$campaign->camp_published = $state;
|
||||
$campaign->save();
|
||||
|
||||
return json_encode($campaign);
|
||||
}
|
||||
|
||||
public function getDetail(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 ($campagne->camp_siteId != $site->site_id) {
|
||||
return response()->json([
|
||||
'Statut' => 'KO',
|
||||
'Code' => 108,
|
||||
'Message' => 'Pas de campagne pour ce site'
|
||||
]);
|
||||
}
|
||||
|
||||
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'
|
||||
]);
|
||||
}
|
||||
|
||||
$enligne = ($campagne->camp_published == 1) ? "oui" : "non";
|
||||
switch ($campagne->camp_type) {
|
||||
case CampaignTypes::mur():
|
||||
$type = "mur";
|
||||
break;
|
||||
case CampaignTypes::panier():
|
||||
$type = "panier";
|
||||
break;
|
||||
case CampaignTypes::murss():
|
||||
$type = "mur sans sélection";
|
||||
break;
|
||||
case CampaignTypes::paniers():
|
||||
$type = "panier avec sélection";
|
||||
break;
|
||||
}
|
||||
$data = [
|
||||
'Site' => $site->site_nom,
|
||||
'Ref campagne' => $campagne->camp_id,
|
||||
'Nom campagne' => $campagne->camp_name,
|
||||
"En ligne" => $enligne,
|
||||
"Type" => $type,
|
||||
];
|
||||
|
||||
|
||||
$coupons = $campagne->coupons()->get();
|
||||
|
||||
if ($coupons->count() > 0) {
|
||||
foreach ($coupons as $coupon) {
|
||||
// ---- Calcul du nombre de BR consommé
|
||||
$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');
|
||||
$diffusePanier02 = PanierContent::where(['panier_content_couponId' => $coupon->coupon_id])->sum('panier_content_printed');
|
||||
$diffusePanier = $diffusePanier01 + $diffusePanier02;
|
||||
|
||||
if (!$diffusePanier) {
|
||||
$diffusePanier = 0;
|
||||
}
|
||||
$diffuse = $diffuseMur + $diffusePanier;
|
||||
|
||||
// ---- Calcul de la quantité restante
|
||||
$qRestante = $this->getFullQuantity($coupon) - $this->getUsedQuantity($coupon);
|
||||
// ---- En ligne oui/non
|
||||
$enligne = ($coupon->coupon_published == 1) ? "oui" : "non";
|
||||
|
||||
// ---- Calcul de la date de fin de diffusion
|
||||
$dateFinDiffusion = "n/c";
|
||||
if ($coupon->coupon_maxdatediffusion != null) {
|
||||
$dateFinDiffusion = date("d/m/Y", strtotime($coupon->coupon_maxdatediffusion));
|
||||
}
|
||||
|
||||
// ---- Calcul de la date de fin de validité
|
||||
$dateFinValidite = "n/c";
|
||||
if ($coupon->coupon_maxdatevalidity != null) {
|
||||
$dateFinValidite = date("d/m/Y", strtotime($coupon->coupon_maxdatevalidity));
|
||||
}
|
||||
|
||||
$codeTraitement = [
|
||||
"Code traitement" => $coupon->coupon_code,
|
||||
"Nom" => $coupon->coupon_name,
|
||||
"Nb à diffuser" => $this->getFullQuantity($coupon),
|
||||
"Nb diffusé" => $diffuse,
|
||||
"Quantité restante" => $qRestante,
|
||||
"Valeur faciale" => $coupon->coupon_value . "€",
|
||||
"En ligne" => $enligne,
|
||||
"Date de fin de diffusion" => $dateFinDiffusion,
|
||||
"Date de fin de validité" => $dateFinValidite,
|
||||
];
|
||||
$data['Coupons'][] = $codeTraitement;
|
||||
}//end foreach
|
||||
}//end if
|
||||
return response()->json([
|
||||
'Statut' => 'OK',
|
||||
'Détails Campagne' => $data
|
||||
]);
|
||||
}
|
||||
}
|
||||
15
app/Http/Controllers/Controller.php
Normal file
15
app/Http/Controllers/Controller.php
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests;
|
||||
use DispatchesJobs;
|
||||
use ValidatesRequests;
|
||||
}
|
||||
243
app/Http/Controllers/CouponController.php
Normal file
243
app/Http/Controllers/CouponController.php
Normal file
|
|
@ -0,0 +1,243 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Models\Coupon;
|
||||
use App\Models\Site;
|
||||
use App\Models\Campagne;
|
||||
use App\Models\Mouvement;
|
||||
use App\Models\Calendrier;
|
||||
use App\Http\Requests\Coupons\StoreCoupons;
|
||||
use App\Http\Requests\Coupons\UpdateCoupons;
|
||||
use App\Traits\GenerateBR;
|
||||
use App\Traits\CouponTrait;
|
||||
|
||||
class CouponController extends Controller
|
||||
{
|
||||
use GenerateBR;
|
||||
use CouponTrait;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
// TODO : Revoir le passage du site
|
||||
$site = session()->get('site');
|
||||
$coupons = Coupon::where('coupon_siteId', $site->id)->get();
|
||||
foreach ($coupons as $coupon) {
|
||||
// ---- Calcul de la quantité mise à disposition grace aux fonctions dans CouponTrait.php
|
||||
$coupon->coupon_quantity = $this->getFullQuantity($coupon);
|
||||
// ---- Calcul de la quantité restante toutes campagnes comprises grace aux fonctions dans CouponTrait.php
|
||||
$coupon->coupon_left = 0;
|
||||
// $coupon->coupon_quantity - $this->getUsedQuantity($coupon);
|
||||
}
|
||||
return view('coupon.index', ['coupons' => $coupons]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
// TODO : Revoir le passage du site
|
||||
$site = session()->get('site');
|
||||
|
||||
$campagnes = Campagne::where('camp_siteId', session()->get('site')->site_id)->get()
|
||||
->pluck('camp_name', 'camp_id');
|
||||
|
||||
$site = Site::findOrFail($site->id);
|
||||
return view('coupon.create')->with('campagnes', $campagnes)->with('site', $site);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param StoreCoupons $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(StoreCoupons $request)
|
||||
{
|
||||
$site_id = $request->site_id;
|
||||
|
||||
$datas = $this->saveImg($request);
|
||||
|
||||
$coupon = new Coupon();
|
||||
$coupon->fill($datas);
|
||||
|
||||
// TODO : A revoir au moment ou on enlevera les images mobiles
|
||||
if (isset($datas['coupon_thumbnail1'])) {
|
||||
$coupon->coupon_thumbnail1 = $datas['coupon_thumbnail1'];
|
||||
}
|
||||
if (isset($datas['coupon_thumbnail2'])) {
|
||||
$coupon->coupon_thumbnail2 = $datas['coupon_thumbnail2'];
|
||||
}
|
||||
if (isset($datas['coupon_thumbnail3'])) {
|
||||
$coupon->coupon_thumbnail3 = $datas['coupon_thumbnail3'];
|
||||
}
|
||||
if (isset($datas['coupon_thumbnail4'])) {
|
||||
$coupon->coupon_thumbnail4 = $datas['coupon_thumbnail4'];
|
||||
}
|
||||
if (isset($datas['coupon_image'])) {
|
||||
$coupon->coupon_image = $datas['coupon_image'];
|
||||
}
|
||||
|
||||
//TODO : Voir si on peut mettre le set a 0 dans la request
|
||||
if (!isset($datas['coupon_published'])) {
|
||||
$coupon->coupon_published = 0;
|
||||
}
|
||||
if (!isset($datas['coupon_legal_mentions_splitted'])) {
|
||||
$coupon->coupon_legal_mentions_splitted = 0;
|
||||
}
|
||||
|
||||
$br_path = $this->generateBase($request, $coupon);
|
||||
$coupon->coupon_image = $br_path;
|
||||
$coupon->coupon_siteId = $site_id;
|
||||
$coupon->save();
|
||||
|
||||
$site = Site::findOrFail($site_id);
|
||||
|
||||
$site->coupons()->save($coupon);
|
||||
|
||||
if (isset($datas['initial_quantity'])) {
|
||||
$mouvement = new Mouvement();
|
||||
$mouvement->mouvement_nombre = $datas['initial_quantity'];
|
||||
$coupon->mouvements()->save($mouvement);
|
||||
}
|
||||
|
||||
if (isset($datas['startdate'])) {
|
||||
foreach ($datas['startdate'] as $key => $value) {
|
||||
$calendar = new Calendrier();
|
||||
$calendar->calendrier_startdate = $value;
|
||||
$calendar->calendrier_enddate = $datas['enddate'][$key];
|
||||
$coupon->calendriers()->save($calendar);
|
||||
}
|
||||
}
|
||||
|
||||
return to_route('coupon.edit', ['coupon' => $coupon]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\Coupon $coupon
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(Coupon $coupon)
|
||||
{
|
||||
return view('coupon.edit', ['coupon' => $coupon]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param UpdateCoupons $request
|
||||
* @param \App\Models\Coupon $coupon
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(UpdateCoupons $request, Coupon $coupon)
|
||||
{
|
||||
//TODO : Voir si on peut mettre le set a 0 dans la request
|
||||
if (!isset($request->coupon_enablelimitquantity)) {
|
||||
$coupon->coupon_enablelimitquantity = 0;
|
||||
}
|
||||
if (!isset($request->coupon_enablelimitperiod)) {
|
||||
$coupon->coupon_enablelimitperiod = 0;
|
||||
}
|
||||
if (!isset($request->coupon_norme)) {
|
||||
$coupon->coupon_norme = 0;
|
||||
}
|
||||
if (!isset($request->coupon_published)) {
|
||||
$coupon->coupon_published = 0;
|
||||
}
|
||||
if (!isset($request->coupon_legal_mentions_splitted)) {
|
||||
$coupon->coupon_legal_mentions_splitted = 0;
|
||||
}
|
||||
|
||||
$datas = $this->saveImg($request);
|
||||
// On sauvegarde les informations
|
||||
if ($coupon->update($datas)) {
|
||||
// Si l'update est OK on met à jour l'image du BR
|
||||
$br_path = $this->generateBase($request, $coupon);
|
||||
$coupon->coupon_image = $br_path;
|
||||
$coupon->save();
|
||||
|
||||
// Si on ajoute des BR
|
||||
// TODO : Gestion de l'erreur si on ajoute une ligne vide
|
||||
if (isset($datas['mouvementNbre'])) {
|
||||
foreach ($datas['mouvementNbre'] as $key => $value) {
|
||||
$mouvement = new Mouvement();
|
||||
$mouvement->mouvement_nombre = $value;
|
||||
$mouvement->mouvement_created_at = $datas['mouvementDate'][$key];
|
||||
$coupon->mouvements()->save($mouvement);
|
||||
}
|
||||
}
|
||||
// Si on ajoute une plage de diffusion
|
||||
// TODO : Gestion de l'erreur si on ajoute une ligne vide
|
||||
if (isset($datas['startdate'])) {
|
||||
$coupon->calendriers()->delete();
|
||||
foreach ($datas['startdate'] as $key => $value) {
|
||||
$calendar = new Calendrier();
|
||||
$calendar->calendrier_startdate = $value;
|
||||
$calendar->calendrier_enddate = $datas['enddate'][$key];
|
||||
$coupon->calendriers()->save($calendar);
|
||||
}
|
||||
}
|
||||
session()->flash('update_ok', 'Mise à jour du coupon réussie !');
|
||||
|
||||
return to_route('coupon.edit', ['coupon' => $coupon]);
|
||||
} else {
|
||||
return view('holder');
|
||||
} //end if
|
||||
|
||||
return to_route('coupon.edit', ['coupon' => $coupon]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\Coupon $coupon
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(Coupon $coupon)
|
||||
{
|
||||
$coupon->coupon_published = 0;
|
||||
$coupon->save();
|
||||
if ($coupon->delete()) {
|
||||
return to_route('coupon.index');
|
||||
} else {
|
||||
session()->flash('delete_nok', 'Erreur lors de la suppression');
|
||||
return back();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function saveImg(Request $request)
|
||||
{
|
||||
$datas = collect($request->all());
|
||||
|
||||
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 (isset($item)) {
|
||||
/** @var \Illuminate\Http\UploadedFile $item */
|
||||
$path = $item->store('modelfiles/coupons', 'public');
|
||||
$path = Str::start($path, 'storage/');
|
||||
$datas->put($key, $path);
|
||||
} else {
|
||||
$datas->put($key, $request->input($key . '_hidden'));
|
||||
}
|
||||
}
|
||||
}
|
||||
return $datas->toArray();
|
||||
}
|
||||
}
|
||||
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')));
|
||||
}
|
||||
}
|
||||
160
app/Http/Controllers/PanierController.php
Normal file
160
app/Http/Controllers/PanierController.php
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Panier;
|
||||
use App\Models\Campagne;
|
||||
use App\Models\Coupon;
|
||||
use App\Models\Contact;
|
||||
use App\Enums\CampaignTypes;
|
||||
use App\Traits\CouponTrait;
|
||||
use App\Traits\ThanksTrait;
|
||||
|
||||
class PanierController extends Controller
|
||||
{
|
||||
use ThanksTrait;
|
||||
use CouponTrait;
|
||||
|
||||
public function showTemplate(Request $request)
|
||||
{
|
||||
// $panier = Panier::find($request->query('basketid'));
|
||||
$panier = Panier::where(['panier_ref' => $request->basketid])->first();
|
||||
abort_unless($panier, 404);
|
||||
session()->put('panier', $panier);
|
||||
$panierCouponsCount = $this->getCountCouponsPanierPublished($panier);
|
||||
$contact = Contact::where(['contact_id' => $panier->panier_contactId])->first();
|
||||
abort_unless($contact, 404);
|
||||
session()->put('contact', $contact);
|
||||
|
||||
$campagne = Campagne::where(['camp_id' => $panier->panier_campId, 'camp_published' => 1])->first();
|
||||
abort_unless($campagne, 404);
|
||||
session()->put('campagne', $campagne);
|
||||
|
||||
if ($campagne->camp_type->equals(CampaignTypes::panier())) {
|
||||
$coupons = $this->getCouponsPublished($campagne);
|
||||
} else {
|
||||
$panierContents = $this->getPanierContentPublished($panier);
|
||||
$coupons = [];
|
||||
foreach ($panierContents as $panierContent) {
|
||||
$cp = Coupon::where(['coupon_id' => $panierContent->panier_content_couponId])->first();
|
||||
$qty = $panierContent->panier_content_quantity;
|
||||
for ($i = 0; $i < $qty; $i++) {
|
||||
$coupons[] = $cp;
|
||||
}
|
||||
}
|
||||
}
|
||||
session()->put('coupons', $coupons);
|
||||
return view('landings::' . $panier->panier_campId . '.index')
|
||||
->with(['ref' => $panier->panier_campId, 'coupons' => $coupons, 'contact' => $contact, 'nb' => $panierCouponsCount]);
|
||||
}
|
||||
|
||||
public function printPanierSelect(Request $request)
|
||||
{
|
||||
if (isset($request->coupons)) {
|
||||
session()->put('coupons', $request->coupons);
|
||||
}
|
||||
|
||||
$coupons = session('coupons', []);
|
||||
|
||||
abort_unless($request->session()->has('campagne'), 404);
|
||||
|
||||
$campagne = $request->session()->get('campagne');
|
||||
|
||||
$ref = $campagne->camp_id;
|
||||
|
||||
return view('landings::' . $ref . '.imprimer')
|
||||
->with(['ref' => $ref, 'coupons' => $coupons, 'contact' => $request->session()->get('contact')]);
|
||||
}
|
||||
|
||||
public function showBasket(Request $request)
|
||||
{
|
||||
// ---- Contrôle des paramètres
|
||||
if (isset($request->basketid) && $request->basketid != "") {
|
||||
$basketid = $request->basketid;
|
||||
} else {
|
||||
return response()->json([
|
||||
'Statut' => 'KO',
|
||||
'Code' => 106,
|
||||
'Message' => 'Le panier n\'existe pas'
|
||||
]);
|
||||
}
|
||||
|
||||
$panier = Panier::where('panier_ref', $basketid)->first();
|
||||
if (!$panier) {
|
||||
return response()->json([
|
||||
'Statut' => 'KO',
|
||||
'Code' => 106,
|
||||
'Message' => 'Le panier n\'existe pas'
|
||||
]);
|
||||
}
|
||||
|
||||
if ($panier->panier_pending == 1) {
|
||||
$encours = "oui";
|
||||
} else {
|
||||
$encours = "non";
|
||||
}
|
||||
|
||||
$contact = $panier->contact()->where(['contact_id' => $panier->panier_contactId])->first();
|
||||
if (!$contact) {
|
||||
return response()->json([
|
||||
'Statut' => 'KO',
|
||||
'Code' => 104,
|
||||
'Message' => 'Le contact n\'existe pas'
|
||||
]);
|
||||
}
|
||||
|
||||
$campagne = $panier->campagne()->where(['camp_id' => $panier->panier_campId])->first();
|
||||
if (!$campagne) {
|
||||
return response()->json([
|
||||
'Statut' => 'KO',
|
||||
'Code' => 103,
|
||||
'Message' => 'La campagne n\'existe pas'
|
||||
]);
|
||||
}
|
||||
|
||||
$site = $campagne->site()->first();
|
||||
if ($site === null) {
|
||||
return response()->json([
|
||||
'Statut' => 'KO',
|
||||
'Code' => 102,
|
||||
'Message' => 'Le site n\'existe pas'
|
||||
]);
|
||||
}
|
||||
|
||||
$allPanierContent = $panier->panierContents()->get();
|
||||
if ($allPanierContent->count() == 0) {
|
||||
return response()->json([
|
||||
'Statut' => 'KO',
|
||||
'Code' => 108,
|
||||
'Message' => 'Le panier n\'a pas de coupons liés'
|
||||
]);
|
||||
}
|
||||
|
||||
$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;
|
||||
$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',
|
||||
'Informations Panier' => $response
|
||||
]);
|
||||
}
|
||||
}
|
||||
26
app/Http/Controllers/RedirectController.php
Normal file
26
app/Http/Controllers/RedirectController.php
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class RedirectController extends Controller
|
||||
{
|
||||
/**
|
||||
* Handle the incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function __invoke(Request $request)
|
||||
{
|
||||
$panier = new Controllers\PanierController();
|
||||
|
||||
if (isset($request->basketid)) {
|
||||
return $panier->showTemplate($request);
|
||||
} else {
|
||||
return to_route('login');
|
||||
}
|
||||
}
|
||||
}
|
||||
125
app/Http/Controllers/SiteController.php
Normal file
125
app/Http/Controllers/SiteController.php
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Site;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class SiteController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$sites = Site::all();
|
||||
|
||||
return view('site.index')->with('sites', $sites);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('site.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'site_id' => 'required|unique:site',
|
||||
'site_nom' => 'required',
|
||||
'site_contact' => 'required',
|
||||
'site_logo' => 'required|image|mimes:png',
|
||||
'site_rcs' => 'required',
|
||||
'site_libelle' => 'required'
|
||||
]);
|
||||
|
||||
$site = new Site();
|
||||
$datas = $this->saveImg($request);
|
||||
$site->site_id = $datas['site_id'];
|
||||
$site->site_nom = $datas['site_nom'];
|
||||
$site->site_contact = $datas['site_contact'];
|
||||
$site->site_logo = $datas['site_logo'];
|
||||
$site->site_rcs = $datas['site_rcs'];
|
||||
$site->site_libelle = $datas['site_libelle'];
|
||||
|
||||
$site->save();
|
||||
|
||||
// --- ADD all new sites to all SuperAdmin
|
||||
$admins = User::where(['roles' => 'superadmin'])->get();
|
||||
foreach ($admins as $admin) {
|
||||
$admin->sites()->save($site);
|
||||
}
|
||||
// --- MAJ Selecteur marques
|
||||
$marques = Auth::user()->sites;
|
||||
$submarques = $marques->map(fn($marque) => $marque->only(['id', 'site_nom', 'site_id', 'site_logo']));
|
||||
|
||||
session()->put('marques', $submarques);
|
||||
|
||||
return view('site.edit', ['site' => $site]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\Site $site
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(Site $site)
|
||||
{
|
||||
return view('site.edit')->with('site', $site);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Models\Site $site
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, Site $site)
|
||||
{
|
||||
if ($site->update($this->saveImg($request))) {
|
||||
session()->flash('update_ok', 'Le site a bien été modifié');
|
||||
} else {
|
||||
session()->flash('update_nok', 'Erreur lors de l\'enregistrement');
|
||||
}
|
||||
|
||||
return to_route('site.edit', ['site' => $site]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function saveImg(Request $request)
|
||||
{
|
||||
$datas = collect($request->all());
|
||||
|
||||
// Enregistrer le fichiersi il a changé
|
||||
if ($request->site_logo) {
|
||||
$path = $request->site_logo->store('images/logos');
|
||||
$path = str_replace('public/', '', $path);
|
||||
$datas->put('site_logo', $path);
|
||||
} else {
|
||||
$datas->put('site_logo', $request->input('site_logo_hidden'));
|
||||
}
|
||||
|
||||
return $datas->toArray();
|
||||
}
|
||||
}
|
||||
81
app/Http/Kernel.php
Normal file
81
app/Http/Kernel.php
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http;
|
||||
|
||||
use Illuminate\Foundation\Http\Kernel as HttpKernel;
|
||||
|
||||
class Kernel extends HttpKernel
|
||||
{
|
||||
/**
|
||||
* The application's global HTTP middleware stack.
|
||||
*
|
||||
* These middleware are run during every request to your application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $middleware = [
|
||||
\App\Http\Middleware\CheckForMaintenanceMode::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
||||
\App\Http\Middleware\TrimStrings::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
|
||||
\App\Http\Middleware\TrustProxies::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* The application's route middleware groups.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $middlewareGroups = [
|
||||
'web' => [
|
||||
\App\Http\Middleware\EncryptCookies::class,
|
||||
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
// \Illuminate\Session\Middleware\AuthenticateSession::class,
|
||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||
\App\Http\Middleware\VerifyCsrfToken::class,
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class
|
||||
],
|
||||
|
||||
'api' => [
|
||||
'throttle:60,1',
|
||||
'bindings',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* The application's route middleware.
|
||||
*
|
||||
* These middleware may be assigned to groups or used individually.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $middlewareAliases = [
|
||||
'auth' => \App\Http\Middleware\Authenticate::class,
|
||||
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
|
||||
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
|
||||
'can' => \Illuminate\Auth\Middleware\Authorize::class,
|
||||
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
||||
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
|
||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
|
||||
'saveroute' => \App\Http\Middleware\SaveCurrentRoute::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* The priority-sorted list of middleware.
|
||||
*
|
||||
* This forces the listed middleware to always be in the given order.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $middlewarePriority = [
|
||||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||
\App\Http\Middleware\Authenticate::class,
|
||||
\Illuminate\Session\Middleware\AuthenticateSession::class,
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
\Illuminate\Auth\Middleware\Authorize::class,
|
||||
];
|
||||
}
|
||||
19
app/Http/Middleware/Authenticate.php
Normal file
19
app/Http/Middleware/Authenticate.php
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Auth\Middleware\Authenticate as Middleware;
|
||||
|
||||
class Authenticate extends Middleware
|
||||
{
|
||||
/**
|
||||
* Get the path the user should be redirected to when they are not authenticated.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return string
|
||||
*/
|
||||
protected function redirectTo($request)
|
||||
{
|
||||
return route('login');
|
||||
}
|
||||
}
|
||||
17
app/Http/Middleware/CheckForMaintenanceMode.php
Normal file
17
app/Http/Middleware/CheckForMaintenanceMode.php
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode as Middleware;
|
||||
|
||||
class CheckForMaintenanceMode extends Middleware
|
||||
{
|
||||
/**
|
||||
* The URIs that should be reachable while maintenance mode is enabled.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
|
||||
protected $except = [
|
||||
];
|
||||
}
|
||||
17
app/Http/Middleware/EncryptCookies.php
Normal file
17
app/Http/Middleware/EncryptCookies.php
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
|
||||
|
||||
class EncryptCookies extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the cookies that should not be encrypted.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
|
||||
protected $except = [
|
||||
];
|
||||
}
|
||||
26
app/Http/Middleware/RedirectIfAuthenticated.php
Normal file
26
app/Http/Middleware/RedirectIfAuthenticated.php
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class RedirectIfAuthenticated
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null $guard
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next, $guard = null)
|
||||
{
|
||||
if (Auth::guard($guard)->check()) {
|
||||
return to_route('campagne.index');
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
38
app/Http/Middleware/SaveCurrentRoute.php
Normal file
38
app/Http/Middleware/SaveCurrentRoute.php
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class SaveCurrentRoute
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
$site = session()->get('site');
|
||||
$siteId = session()->get('marques');
|
||||
|
||||
if (!$site) {
|
||||
$site = Auth::user()->sites->first();
|
||||
session()->put('site', $site);
|
||||
}
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
19
app/Http/Middleware/TrimStrings.php
Normal file
19
app/Http/Middleware/TrimStrings.php
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;
|
||||
|
||||
class TrimStrings extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the attributes that should not be trimmed.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
|
||||
protected $except = [
|
||||
'password',
|
||||
'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'),
|
||||
];
|
||||
}
|
||||
}
|
||||
28
app/Http/Middleware/TrustProxies.php
Normal file
28
app/Http/Middleware/TrustProxies.php
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Middleware\TrustProxies as Middleware;
|
||||
|
||||
class TrustProxies extends Middleware
|
||||
{
|
||||
/**
|
||||
* The trusted proxies for this application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $proxies = ['*'];
|
||||
|
||||
/**
|
||||
* The headers that should be used to detect proxies.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
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;
|
||||
}
|
||||
28
app/Http/Middleware/VerifyCsrfToken.php
Normal file
28
app/Http/Middleware/VerifyCsrfToken.php
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
|
||||
|
||||
class VerifyCsrfToken extends \Illuminate\Foundation\Http\Middleware\PreventRequestForgery
|
||||
{
|
||||
/**
|
||||
* Indicates whether the XSRF-TOKEN cookie should be set on the response.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
|
||||
protected $addHttpCookie = true;
|
||||
|
||||
/**
|
||||
* The URIs that should be excluded from CSRF verification.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
|
||||
protected $except = [
|
||||
'updatecontact',
|
||||
'updatebasket',
|
||||
'showbasket',
|
||||
];
|
||||
}
|
||||
31
app/Http/Requests/Bo/Users/DestroyUserRequest.php
Normal file
31
app/Http/Requests/Bo/Users/DestroyUserRequest.php
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo\Users;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class DestroyUserRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return Auth::check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
35
app/Http/Requests/Bo/Users/StoreUserRequest.php
Normal file
35
app/Http/Requests/Bo/Users/StoreUserRequest.php
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo\Users;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class StoreUserRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return Auth::check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'email' => 'required|unique:users|email',
|
||||
'name' => 'required',
|
||||
'password' => 'min:8|required',
|
||||
'site' => 'required',
|
||||
'roles' => 'required'
|
||||
];
|
||||
}
|
||||
}
|
||||
38
app/Http/Requests/Bo/Users/UpdateUserRequest.php
Normal file
38
app/Http/Requests/Bo/Users/UpdateUserRequest.php
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Bo\Users;
|
||||
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class UpdateUserRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return Auth::check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'email' => [
|
||||
'required',
|
||||
Rule::unique('users')->ignore($this->user->id)
|
||||
],
|
||||
'name' => 'required',
|
||||
'site' => 'required',
|
||||
'roles' => 'required'
|
||||
];
|
||||
}
|
||||
}
|
||||
32
app/Http/Requests/BrandChange/InvokeBrandChange.php
Normal file
32
app/Http/Requests/BrandChange/InvokeBrandChange.php
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\BrandChange;
|
||||
|
||||
use App\Enums\UserRoles;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class InvokeBrandChange 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 [
|
||||
'site_id' => 'exists:site,id|required'
|
||||
];
|
||||
}
|
||||
}
|
||||
32
app/Http/Requests/Campaign/AddCouponsCampaign.php
Normal file
32
app/Http/Requests/Campaign/AddCouponsCampaign.php
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Campaign;
|
||||
|
||||
use App\Enums\UserRoles;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class AddCouponsCampaign 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 [
|
||||
'ids' => 'required'
|
||||
];
|
||||
}
|
||||
}
|
||||
32
app/Http/Requests/Campaign/DeleteCampaign.php
Normal file
32
app/Http/Requests/Campaign/DeleteCampaign.php
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Campaign;
|
||||
|
||||
use App\Enums\UserRoles;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class DeleteCampaign 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 [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
32
app/Http/Requests/Campaign/RemoveCouponCampaign.php
Normal file
32
app/Http/Requests/Campaign/RemoveCouponCampaign.php
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Campaign;
|
||||
|
||||
use App\Enums\UserRoles;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class RemoveCouponCampaign 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 [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
32
app/Http/Requests/Campaign/RemoveNotifCampaign.php
Normal file
32
app/Http/Requests/Campaign/RemoveNotifCampaign.php
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Campaign;
|
||||
|
||||
use App\Enums\UserRoles;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class RemoveNotifCampaign 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 [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
32
app/Http/Requests/Campaign/ShowDemoCampaign.php
Normal file
32
app/Http/Requests/Campaign/ShowDemoCampaign.php
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Campaign;
|
||||
|
||||
use App\Enums\UserRoles;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class ShowDemoCampaign 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 [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
35
app/Http/Requests/Campaign/StoreCampaign.php
Normal file
35
app/Http/Requests/Campaign/StoreCampaign.php
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Campaign;
|
||||
|
||||
use App\Enums\UserRoles;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class StoreCampaign 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 [
|
||||
'camp_name' => 'min:5|required',
|
||||
'camp_type' => 'integer|required',
|
||||
'camp_published' => 'integer|required',
|
||||
'camp_limitedPrinting' => 'sometimes|integer|required'
|
||||
];
|
||||
}
|
||||
}
|
||||
37
app/Http/Requests/Campaign/StoreNotifCampaign.php
Normal file
37
app/Http/Requests/Campaign/StoreNotifCampaign.php
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Campaign;
|
||||
|
||||
use App\Enums\UserRoles;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class StoreNotifCampaign 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 [
|
||||
'notif_name' => 'min:5|required',
|
||||
'notif_email' => [
|
||||
'required',
|
||||
Rule::unique('notification')->where(fn($query) => $query->where('notif_campId', $this->campaign->camp_id)),
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
35
app/Http/Requests/Campaign/UpdateCampaign.php
Normal file
35
app/Http/Requests/Campaign/UpdateCampaign.php
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Campaign;
|
||||
|
||||
use App\Enums\UserRoles;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class UpdateCampaign 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 [
|
||||
'camp_name' => 'min:5|required',
|
||||
'camp_type' => 'integer|required',
|
||||
'camp_published' => 'integer|required',
|
||||
'camp_limitedPrinting' => 'sometimes|integer|required'
|
||||
];
|
||||
}
|
||||
}
|
||||
48
app/Http/Requests/Coupons/PrintRequest.php
Normal file
48
app/Http/Requests/Coupons/PrintRequest.php
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Coupons;
|
||||
|
||||
use App\Http\Resources\StatusResource;
|
||||
use Illuminate\Contracts\Validation\Validator;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Http\Exceptions\HttpResponseException;
|
||||
|
||||
class PrintRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
// TODO : Validate coupons formats
|
||||
return [
|
||||
'refcamp' => 'string|exists:campagne,camp_id|required',
|
||||
'hashcode' => 'string|exists:customers,hashcode|required',
|
||||
'coupons' => 'required',
|
||||
'type' => 'nullable|in:stream,dl'
|
||||
];
|
||||
}
|
||||
|
||||
protected function failedValidation(Validator $validator)
|
||||
{
|
||||
if ($this->wantsJson()) {
|
||||
throw new HttpResponseException(response()->json(new StatusResource([
|
||||
'status' => 'KO',
|
||||
'code' => 422,
|
||||
'message' => $validator->errors()->messages()
|
||||
]), 422));
|
||||
}
|
||||
}
|
||||
}
|
||||
69
app/Http/Requests/Coupons/StoreCoupons.php
Normal file
69
app/Http/Requests/Coupons/StoreCoupons.php
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Coupons;
|
||||
|
||||
use App\Enums\UserRoles;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class StoreCoupons 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 [
|
||||
'coupon_code' => [
|
||||
'required',
|
||||
Rule::unique('coupon', 'coupon_code')
|
||||
],
|
||||
'coupon_name' => 'string|required',
|
||||
'coupon_value' => 'numeric|required',
|
||||
'coupon_validity_text' => 'required',
|
||||
'coupon_legal_mentions' => 'required',
|
||||
'coupon_decoration_image' => 'required|image|mimes:jpeg,png',
|
||||
'coupon_logo_image' => 'required|image|mimes:jpeg,png',
|
||||
'coupon_rcs' => 'required',
|
||||
'coupon_site_contact' => 'required',
|
||||
'coupon_seuil_alert' => 'integer|required',
|
||||
|
||||
'coupon_enablelimitperiod' => 'sometimes|integer|required',
|
||||
'coupon_enablelimitquantity' => 'sometimes|integer|required',
|
||||
'coupon_mindatediffusion' => 'nullable',
|
||||
'coupon_maxdatediffusion' => 'nullable',
|
||||
'coupon_validity' => 'integer|required',
|
||||
'coupon_maxdatevalidity' => 'nullable',
|
||||
|
||||
'coupon_legal_mentions_splitted' => 'sometimes|integer|required',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the validator instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Validation\Validator $validator
|
||||
* @return void
|
||||
*/
|
||||
public function withValidator($validator)
|
||||
{
|
||||
$validator->sometimes('coupon_gs1code', 'required|image|mimes:jpeg', fn($input) => isset($input->coupon_norme));
|
||||
|
||||
$validator->sometimes('coupon_limitquantity', 'integer|required', fn($input) => !is_null($input->coupon_enablelimitquantity));
|
||||
|
||||
$validator->sometimes('coupon_limitperiod', 'integer|required', fn($input) => !is_null($input->coupon_enablelimitperiod));
|
||||
}
|
||||
}
|
||||
78
app/Http/Requests/Coupons/UpdateCoupons.php
Normal file
78
app/Http/Requests/Coupons/UpdateCoupons.php
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Coupons;
|
||||
|
||||
use App\Enums\UserRoles;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class UpdateCoupons 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 [
|
||||
'coupon_code' => [
|
||||
'required',
|
||||
Rule::unique('coupon', 'coupon_code')->ignore($this->coupon->coupon_id, 'coupon_id')
|
||||
],
|
||||
'coupon_name' => 'string|required',
|
||||
'coupon_value' => 'numeric|required',
|
||||
'coupon_seuil_alert' => 'integer|required',
|
||||
'coupon_enablelimitperiod' => 'sometimes|integer|required',
|
||||
'coupon_enablelimitquantity' => 'sometimes|integer|required',
|
||||
'coupon_mindatediffusion' => 'nullable',
|
||||
'coupon_maxdatediffusion' => 'nullable',
|
||||
'coupon_validity' => 'integer|required',
|
||||
'coupon_maxdatevalidity' => 'nullable',
|
||||
|
||||
'coupon_treatment_center' => 'integer|required',
|
||||
'coupon_validity_text' => 'required',
|
||||
'coupon_legal_mentions' => 'required',
|
||||
|
||||
'coupon_rcs' => 'required',
|
||||
'coupon_site_contact' => 'email|required',
|
||||
|
||||
'coupon_norme' => 'sometimes|integer|required',
|
||||
'coupon_published' => 'sometimes|integer|required',
|
||||
'coupon_legal_mentions_splitted' => 'sometimes|integer|required',
|
||||
'coupon_decoration_image' => 'image|mimes:jpeg,png',
|
||||
'coupon_logo_image' => 'image|mimes:jpeg,png',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the validator instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Validation\Validator $validator
|
||||
* @return void
|
||||
*/
|
||||
public function withValidator($validator)
|
||||
{
|
||||
$validator->sometimes('coupon_gs1code', 'required|image|mimes:jpeg', function ($input) {
|
||||
if (isset($input->coupon_gs1code_image_hidden)) {
|
||||
return false;
|
||||
}
|
||||
return isset($input->coupon_norme);
|
||||
});
|
||||
|
||||
$validator->sometimes('coupon_limitquantity', 'integer|required', fn($input) => !is_null($input->coupon_enablelimitquantity));
|
||||
|
||||
$validator->sometimes('coupon_limitperiod', 'integer|required', fn($input) => !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));
|
||||
}
|
||||
}
|
||||
}
|
||||
45
app/Http/Requests/Customers/MurRequest.php
Normal file
45
app/Http/Requests/Customers/MurRequest.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 MurRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
33
app/Http/Requests/Customers/SearchCustomers.php
Normal file
33
app/Http/Requests/Customers/SearchCustomers.php
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Customers;
|
||||
|
||||
use App\Enums\UserRoles;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class SearchCustomers extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return Auth::check()
|
||||
&& in_array(Auth::user()->roles, [UserRoles::superadmin()->value, UserRoles::admin()->value]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'email' => 'sometimes|email|required'
|
||||
];
|
||||
}
|
||||
}
|
||||
46
app/Http/Requests/Customers/StoreRequest.php
Normal file
46
app/Http/Requests/Customers/StoreRequest.php
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
<?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 StoreRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'hashcode' => 'string|required',
|
||||
'email' => 'email|required',
|
||||
'country' => 'string|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));
|
||||
}
|
||||
}
|
||||
}
|
||||
34
app/Http/Requests/Export/PDFExport.php
Normal file
34
app/Http/Requests/Export/PDFExport.php
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Export;
|
||||
|
||||
use App\Enums\UserRoles;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class PDFExport 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 [
|
||||
'ids' => 'required',
|
||||
'startdate' => 'date|required',
|
||||
'enddate' => 'date|required'
|
||||
];
|
||||
}
|
||||
}
|
||||
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 [];
|
||||
}
|
||||
}
|
||||
44
app/Http/Requests/Murs/MursShowRequest.php
Normal file
44
app/Http/Requests/Murs/MursShowRequest.php
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Murs;
|
||||
|
||||
use App\Http\Resources\StatusResource;
|
||||
use Illuminate\Contracts\Validation\Validator;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Http\Exceptions\HttpResponseException;
|
||||
|
||||
class MursShowRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'refcamp' => 'exists:campagne,camp_id|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));
|
||||
}
|
||||
}
|
||||
}
|
||||
41
app/Http/Resources/CouponsResource.php
Normal file
41
app/Http/Resources/CouponsResource.php
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class CouponsResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource collection into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
$coupon = [
|
||||
'code' => $this->coupon_code,
|
||||
'name' => $this->coupon_name,
|
||||
'value' => $this->coupon_value,
|
||||
'used' => $this->isUsed ?? false,
|
||||
'desktop_image_available' => $this->returnUrl($this->coupon_thumbnail1),
|
||||
'desktop_image_unavailable' => $this->returnUrl($this->coupon_thumbnail2),
|
||||
'mobile_image_available' => $this->returnUrl($this->coupon_thumbnail3),
|
||||
'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)
|
||||
{
|
||||
return !empty($assets) ? config('app.url') . "/$assets" : null;
|
||||
}
|
||||
}
|
||||
22
app/Http/Resources/CustomersResource.php
Normal file
22
app/Http/Resources/CustomersResource.php
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class CustomersResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return StatusResource
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return new StatusResource([
|
||||
'status' => 'OK',
|
||||
'customer' => parent::toArray($request)
|
||||
]);
|
||||
}
|
||||
}
|
||||
19
app/Http/Resources/StatusResource.php
Normal file
19
app/Http/Resources/StatusResource.php
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class StatusResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return parent::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();
|
||||
}
|
||||
}
|
||||
37
app/Mail/AlertBr.php
Normal file
37
app/Mail/AlertBr.php
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class AlertBr extends Mailable
|
||||
{
|
||||
use Queueable;
|
||||
use SerializesModels;
|
||||
|
||||
|
||||
public $subject;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(public $couponSeuil, public $couponDiffusion, $sitename)
|
||||
{
|
||||
$this->subject = 'Notification mes BR : ' . $sitename;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the message.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
return $this->subject($this->subject)->view('mail.alert')->with(['couponSeuil' => $this->couponSeuil, 'couponDiffusion' => $this->couponDiffusion]);
|
||||
}
|
||||
}
|
||||
37
app/Mail/AlertBrAdmin.php
Normal file
37
app/Mail/AlertBrAdmin.php
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class AlertBrAdmin extends Mailable
|
||||
{
|
||||
use Queueable;
|
||||
use SerializesModels;
|
||||
|
||||
|
||||
public $subject;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(public $couponSeuil, public $couponDiffusion)
|
||||
{
|
||||
$this->subject = 'Notification mes BR : Récapitulatif global';
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the message.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
return $this->subject($this->subject)->view('mail.alertadmin')->with(['couponSeuil' => $this->couponSeuil, 'couponDiffusion' => $this->couponDiffusion]);
|
||||
}
|
||||
}
|
||||
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');
|
||||
}
|
||||
}
|
||||
63
app/Models/Calendrier.php
Normal file
63
app/Models/Calendrier.php
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Calendrier extends Model
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
||||
protected $table = 'calendrier';
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
||||
protected $primaryKey = 'calendrier_id';
|
||||
|
||||
|
||||
protected $dates = ['calendrier_startdate', 'calendrier_enddate'];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
|
||||
protected $fillable = [
|
||||
'calendrier_startdate',
|
||||
'calendrier_enddate'
|
||||
];
|
||||
|
||||
/**
|
||||
* ManyToOne
|
||||
* Calendrier -> Coupon
|
||||
*/
|
||||
public function coupon()
|
||||
{
|
||||
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()
|
||||
);
|
||||
}
|
||||
}
|
||||
132
app/Models/Campagne.php
Normal file
132
app/Models/Campagne.php
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\CampaignTypes;
|
||||
use App\Models\Basket;
|
||||
use App\Models\PrintedCoupons;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Kwaadpepper\Enum\Traits\CastsEnums;
|
||||
|
||||
class Campagne extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
use CastsEnums;
|
||||
use HasFactory;
|
||||
|
||||
public $enumCasts = [
|
||||
'camp_type' => CampaignTypes::class
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
|
||||
protected $fillable = [
|
||||
'camp_siteId',
|
||||
'camp_name',
|
||||
'camp_type',
|
||||
'camp_limitedPrinting',
|
||||
'camp_published'
|
||||
];
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const CREATED_AT = 'camp_createdate';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const UPDATED_AT = 'camp_updatedate';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const DELETED_AT = 'camp_deleted_at';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
||||
protected $table = 'campagne';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
||||
protected $primaryKey = 'camp_id';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
|
||||
protected $dates = ['camp_deleted_at'];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* OneToMany
|
||||
* Campagne -> Notification
|
||||
*/
|
||||
public function notifications()
|
||||
{
|
||||
return $this->hasMany(\App\Models\Notification::class, 'notif_campId', 'camp_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* OneToMany
|
||||
* Campagne -> Mur
|
||||
*/
|
||||
public function murs()
|
||||
{
|
||||
return $this->hasMany(\App\Models\Mur::class, 'mur_campId', 'camp_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* OneToMany
|
||||
* Campagne -> Panier
|
||||
*/
|
||||
public function paniers()
|
||||
{
|
||||
return $this->hasMany(\App\Models\Panier::class, 'panier_campId', 'camp_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* ManyToOne
|
||||
* Campagne -> Site
|
||||
*/
|
||||
public function site()
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Site::class, 'camp_siteId', 'site_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* The coupons that belong to the campagne.
|
||||
*/
|
||||
public function coupons()
|
||||
{
|
||||
return $this->belongsToMany(\App\Models\Coupon::class, 'campagne_coupon', 'campagne_id', 'coup_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* printedCoupons relation
|
||||
* @return HasMany
|
||||
*/
|
||||
public function printedCoupons()
|
||||
{
|
||||
return $this->hasMany(PrintedCoupons::class, 'camp_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Basket model relation
|
||||
* @return HasMany
|
||||
*/
|
||||
public function baskets()
|
||||
{
|
||||
return $this->hasMany(Basket::class);
|
||||
}
|
||||
}
|
||||
146
app/Models/Contact.php
Normal file
146
app/Models/Contact.php
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Log;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Contact extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const CREATED_AT = 'contact_createdate';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const UPDATED_AT = 'contact_updatedate';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
||||
protected $table = 'contact';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
||||
protected $primaryKey = 'contact_id';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
|
||||
protected $fillable = [
|
||||
'contact_ref',
|
||||
'contact_prenom',
|
||||
'contact_nom',
|
||||
'contact_email',
|
||||
'contact_cp',
|
||||
'contact_ville',
|
||||
'contact_country',
|
||||
];
|
||||
|
||||
/**
|
||||
* OneToMany
|
||||
* Contact -> Mur
|
||||
*/
|
||||
public function murs()
|
||||
{
|
||||
return $this->hasMany(\App\Models\Mur::class, 'mur_contactId', 'contact_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* OneToMany
|
||||
* Contact -> Panier
|
||||
*/
|
||||
public function paniers()
|
||||
{
|
||||
return $this->hasMany(\App\Models\Panier::class, 'panier_contactId', 'contact_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* ManyToOne
|
||||
* Contact -> Site
|
||||
*/
|
||||
public function site()
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Site::class, 'contact_siteId');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Database\Eloquent\Builder<static> $query
|
||||
*/
|
||||
protected function scopeSearchName($query, $name)
|
||||
{
|
||||
if ($name) {
|
||||
$query->where('contact_nom', 'like', '%' . $name . '%');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Database\Eloquent\Builder<static> $query
|
||||
*/
|
||||
protected function scopeSearchFirstname($query, $firstname)
|
||||
{
|
||||
if ($firstname) {
|
||||
$query->where('contact_prenom', 'like', '%' . $firstname . '%');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Database\Eloquent\Builder<static> $query
|
||||
*/
|
||||
protected function scopeSearchEmail($query, $email)
|
||||
{
|
||||
if ($email) {
|
||||
$query->where('contact_email', 'like', '%' . $email . '%');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Database\Eloquent\Builder<static> $query
|
||||
*/
|
||||
protected function scopeSearchVille($query, $ville)
|
||||
{
|
||||
if ($ville) {
|
||||
$query->where('contact_ville', 'like', '%' . $ville . '%');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Database\Eloquent\Builder<static> $query
|
||||
*/
|
||||
protected function scopeSearchCp($query, $cp)
|
||||
{
|
||||
if ($cp) {
|
||||
$query->where('contact_cp', 'like', '%' . $cp . '%');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Database\Eloquent\Builder<static> $query
|
||||
*/
|
||||
protected function scopeSearchCountry($query, $country)
|
||||
{
|
||||
if ($country) {
|
||||
$query->where('contact_country', $country);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* log relation
|
||||
*
|
||||
* @return HasMany
|
||||
*/
|
||||
public function logs()
|
||||
{
|
||||
return $this->hasMany(Log::class, 'log_contactId', 'contact_id');
|
||||
}
|
||||
}
|
||||
138
app/Models/Coupon.php
Normal file
138
app/Models/Coupon.php
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\BasketContent;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Coupon extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const CREATED_AT = 'coupon_createdate';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const UPDATED_AT = 'coupon_updatedate';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const DELETED_AT = 'coupon_deleted_at';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
||||
protected $table = 'coupon';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
||||
protected $primaryKey = 'coupon_id';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
|
||||
protected $fillable = [
|
||||
'coupon_code',
|
||||
'coupon_norme',
|
||||
'coupon_gs1code',
|
||||
'coupon_name',
|
||||
'coupon_value',
|
||||
'coupon_enablelimitquantity',
|
||||
'coupon_limitquantity',
|
||||
'coupon_enablelimitperiod',
|
||||
'coupon_limitperiod',
|
||||
'coupon_validity',
|
||||
'coupon_mindatediffusion',
|
||||
'coupon_maxdatediffusion',
|
||||
'coupon_maxdatevalidity',
|
||||
'coupon_thumbnail1',
|
||||
'coupon_thumbnail2',
|
||||
'coupon_thumbnail3',
|
||||
'coupon_thumbnail4',
|
||||
'coupon_image',
|
||||
'coupon_published',
|
||||
'coupon_logo_image',
|
||||
'coupon_rcs',
|
||||
'coupon_decoration_image',
|
||||
'coupon_validity_text',
|
||||
'coupon_site_contact',
|
||||
'coupon_legal_mentions',
|
||||
'coupon_legal_mentions_splitted',
|
||||
'coupon_seuil_alert',
|
||||
'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);
|
||||
}
|
||||
}
|
||||
93
app/Models/Customers.php
Normal file
93
app/Models/Customers.php
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Panier;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Customers extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* @var string $primaryKey
|
||||
*/
|
||||
|
||||
protected $primaryKey = 'hashcode';
|
||||
|
||||
/**
|
||||
* @var string $keyType
|
||||
*/
|
||||
|
||||
protected $keyType = 'string';
|
||||
|
||||
/**
|
||||
* @var array $fillable
|
||||
*/
|
||||
|
||||
protected $fillable = ['hashcode', 'email', 'country'];
|
||||
|
||||
/**
|
||||
* booted method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function booted()
|
||||
{
|
||||
static::creating(function ($customer): void {
|
||||
$customer->country = new Customers()->getIsoCountry($customer->country);
|
||||
});
|
||||
|
||||
static::updating(function ($customer): void {
|
||||
$customer->country = new Customers()->getIsoCountry($customer->country);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* getIsoCountry method
|
||||
* Default is : France
|
||||
*
|
||||
* @param string $country
|
||||
* @return integer
|
||||
*/
|
||||
private function getIsoCountry($country)
|
||||
{
|
||||
$country = trim(ucfirst(strtolower($country)));
|
||||
$country = match ($country) {
|
||||
'Belgique' => 56,
|
||||
'Luxembourg' => 442,
|
||||
default => 250,
|
||||
};
|
||||
return $country;
|
||||
}
|
||||
|
||||
/**
|
||||
* Printed Coupons Relation
|
||||
*
|
||||
* @return HasMany
|
||||
*/
|
||||
public function printedCoupons()
|
||||
{
|
||||
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');
|
||||
}
|
||||
}
|
||||
41
app/Models/Log.php
Normal file
41
app/Models/Log.php
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Log extends Model
|
||||
{
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
||||
protected $table = 'logs';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
||||
protected $primaryKey = 'id';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const CREATED_AT = 'created_at';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
|
||||
protected $fillable = [
|
||||
'log_action',
|
||||
'log_refsite',
|
||||
'log_contactId',
|
||||
'log_source',
|
||||
'log_params',
|
||||
'log_statut',
|
||||
'log_message',
|
||||
];
|
||||
}
|
||||
47
app/Models/Mouvement.php
Normal file
47
app/Models/Mouvement.php
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Mouvement extends Model
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
||||
protected $table = 'mouvement';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
||||
protected $primaryKey = 'mouvement_id';
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
|
||||
protected $dates = ['mouvement_created_at'];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
|
||||
protected $fillable = [
|
||||
'mouvement_nombre',
|
||||
'mouvement_created_at'
|
||||
];
|
||||
|
||||
/**
|
||||
* ManyToOne
|
||||
* Mouvement -> Coupon
|
||||
*/
|
||||
public function coupon()
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Coupon::class, 'mouvement_couponId');
|
||||
}
|
||||
}
|
||||
53
app/Models/Mur.php
Normal file
53
app/Models/Mur.php
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Mur extends Model
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
||||
protected $table = 'mur';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
||||
protected $primaryKey = 'mur_id';
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* ManyToOne
|
||||
* Mur -> Campagne
|
||||
*/
|
||||
public function campagne()
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Campagne::class, 'mur_campId');
|
||||
}
|
||||
|
||||
/**
|
||||
* ManyToOne
|
||||
* Mur -> Contact
|
||||
*/
|
||||
public function contact()
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Contact::class, 'mur_contactId');
|
||||
}
|
||||
|
||||
/**
|
||||
* ManyToOne
|
||||
* Mur -> Coupon
|
||||
*/
|
||||
public function coupon()
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Coupon::class, 'mur_couponId');
|
||||
}
|
||||
}
|
||||
38
app/Models/Notification.php
Normal file
38
app/Models/Notification.php
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Notification extends Model
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
||||
protected $table = 'notification';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
||||
protected $primaryKey = 'notif_id';
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
|
||||
protected $fillable = ['notif_name', 'notif_email', 'notif_campId'];
|
||||
|
||||
/**
|
||||
* ManyToOne
|
||||
* Notification -> Campagne
|
||||
*/
|
||||
public function campagne()
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Campagne::class, 'notif_campId');
|
||||
}
|
||||
}
|
||||
57
app/Models/Panier.php
Normal file
57
app/Models/Panier.php
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Panier extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
||||
protected $table = 'panier';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
||||
protected $primaryKey = 'panier_id';
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
// protected $with = ['panierContents'];
|
||||
/**
|
||||
* OneToMany
|
||||
* Panier -> PanierContent
|
||||
*/
|
||||
public function panierContents()
|
||||
{
|
||||
return $this->hasMany(\App\Models\PanierContent::class, 'panier_content_panierId', 'panier_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* ManyToOne
|
||||
* Panier -> Campagne
|
||||
*/
|
||||
public function campagne()
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Campagne::class, 'panier_campId');
|
||||
}
|
||||
|
||||
/**
|
||||
* ManyToOne
|
||||
* Panier -> Contact
|
||||
*/
|
||||
public function contact()
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Contact::class, 'panier_contactId');
|
||||
}
|
||||
}
|
||||
55
app/Models/PanierContent.php
Normal file
55
app/Models/PanierContent.php
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PanierContent extends Model
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
||||
protected $table = 'panier_content';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
||||
protected $primaryKey = 'panier_content_id';
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* ManyToOne
|
||||
* PanierContent -> Panier
|
||||
*/
|
||||
public function panier()
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Panier::class, 'panier_content_panierId', 'panier_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* ManyToOne
|
||||
* PanierContent -> Coupon
|
||||
*/
|
||||
public function coupon()
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Coupon::class, 'panier_content_couponId');
|
||||
}
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
|
||||
protected $fillable = [
|
||||
'panier_content_panierId',
|
||||
'panier_content_couponId',
|
||||
'panier_content_quantity',
|
||||
'panier_content_printed'
|
||||
];
|
||||
}
|
||||
11
app/Models/PrintedCoupons.php
Normal file
11
app/Models/PrintedCoupons.php
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PrintedCoupons extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
}
|
||||
84
app/Models/Site.php
Normal file
84
app/Models/Site.php
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Site extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
||||
protected $table = 'site';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
||||
protected $keyType = 'string';
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
|
||||
protected $fillable = ['site_nom', 'site_logo', 'site_contact', 'site_rcs', 'site_libelle'];
|
||||
|
||||
/**
|
||||
* OneToMany
|
||||
* Site -> Campagne
|
||||
*/
|
||||
public function campagnes()
|
||||
{
|
||||
return $this->hasMany(\App\Models\Campagne::class, 'camp_siteId', 'site_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* OneToMany
|
||||
* Site -> Contact
|
||||
*/
|
||||
public function contacts()
|
||||
{
|
||||
return $this->hasMany(\App\Models\Contact::class, 'contact_siteId', 'site_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* The users that belong to the site.
|
||||
*/
|
||||
public function users()
|
||||
{
|
||||
return $this->belongsToMany(\App\Models\User::class, 'site_user', 'site_id', 'user_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* OneToMany
|
||||
* Site -> Coupon
|
||||
*/
|
||||
public function coupons()
|
||||
{
|
||||
return $this->hasMany(\App\Models\Coupon::class, 'coupon_siteId', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function __toString(): string
|
||||
{
|
||||
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');
|
||||
}
|
||||
}
|
||||
68
app/Models/User.php
Normal file
68
app/Models/User.php
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use App\Models\Notifications\ResetPassword;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use Notifiable;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const CREATED_AT = 'created_at';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const UPDATED_AT = 'updated_at';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
||||
protected $table = 'users';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
|
||||
protected $fillable = [
|
||||
'name', 'email', 'password', 'roles',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for arrays.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
|
||||
protected $hidden = [
|
||||
'password', 'remember_token',
|
||||
];
|
||||
|
||||
/**
|
||||
* The sites that belong to the user.
|
||||
*/
|
||||
public function sites()
|
||||
{
|
||||
return $this->belongsToMany(\App\Models\Site::class, 'site_user', 'user_id', 'site_id');
|
||||
}
|
||||
|
||||
|
||||
public function sendPasswordResetNotification($token)
|
||||
{
|
||||
$this->notify(new ResetPassword($token));
|
||||
}
|
||||
}
|
||||
51
app/Notifications/ResetPassword.php
Normal file
51
app/Notifications/ResetPassword.php
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Auth\Notifications\ResetPassword as ResetPasswordNotification;
|
||||
|
||||
class ResetPassword extends ResetPasswordNotification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function via($notifiable)
|
||||
{
|
||||
return ['mail'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return \Illuminate\Notifications\Messages\MailMessage
|
||||
*/
|
||||
public function toMail($notifiable)
|
||||
{
|
||||
return new MailMessage()
|
||||
->subject('MesBR - Réinitialisation du mot de passe')
|
||||
->line('Vous recevez cet email car nous avons reçu une requête de réinitialisation de mot de passe pour votre compte.')
|
||||
->action('Réinitialiser votre mot de passe', url(config('app.url') . route('password.reset', $this->token, false)))
|
||||
->line('Si vous n\'avez pas fait cette demande, aucune action de votre part est nécessaire.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($notifiable)
|
||||
{
|
||||
return [
|
||||
];
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue