Compare commits
121 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7ad039c584 | ||
|
|
cca776dbeb | ||
|
|
a0160bfa8f | ||
|
|
d11e6e1928 | ||
|
|
6444525a49 | ||
|
|
54bdd099bb | ||
|
|
f80c95479c | ||
|
|
53fb12f20f | ||
|
|
56d3a35d0e | ||
|
|
937b516242 | ||
|
|
89854cba4d | ||
|
|
3b50f284e8 | ||
|
|
ec7fc6d719 | ||
|
|
f55f4bb628 | ||
|
|
933cfa48ad | ||
|
|
eb09b6c0e7 | ||
|
|
0dba81c214 | ||
|
|
7c8708496a | ||
|
|
5b2da5859b | ||
|
|
44e3a646a3 | ||
|
|
5bb8063999 | ||
|
|
3af10943e9 | ||
|
|
620e4ef44c | ||
|
|
8d974b5161 | ||
|
|
3251e53fa3 | ||
|
|
6d932429c4 | ||
|
|
b1b7857ddc | ||
|
|
d75f132ee1 | ||
|
|
c3a3d1cb83 | ||
|
|
6addc3a4fa | ||
|
|
5c6c1b1222 | ||
|
|
e4a0ad5b73 | ||
|
|
5a3815579d | ||
|
|
34273a2fd3 | ||
|
|
cbd5a56e48 | ||
|
|
a21415269c | ||
|
|
680c71ea87 | ||
|
|
fdbde84728 | ||
|
|
4d3c778d17 | ||
|
|
0b7da69567 | ||
|
|
5a59a92546 | ||
|
|
a2d211814b | ||
|
|
678487aa07 | ||
|
|
871ceade05 | ||
|
|
a9147e27c7 | ||
|
|
567a5cd48e | ||
|
|
028f0a675d | ||
|
|
237e2c62be | ||
|
|
7136ce9ee6 | ||
|
|
7265d2fa5f | ||
|
|
f45bb119e0 | ||
|
|
02dfb42056 | ||
|
|
18551d8bdb | ||
|
|
aec9e6a575 | ||
|
|
ca312020cd | ||
|
|
44c65cf9f6 | ||
|
|
2c693d9045 | ||
|
|
69faddcd08 | ||
|
|
29c6428aaf | ||
|
|
65e834a06e | ||
|
|
f2fb5d8a23 | ||
|
|
611bf375ab | ||
|
|
973c833fac | ||
|
|
d10b91fe48 | ||
|
|
e15a372e59 | ||
|
|
c773e9de4e | ||
|
|
6d7aecbd1d | ||
|
|
59e4dbf2ee | ||
|
|
a58d604814 | ||
|
|
eae4193713 | ||
|
|
19afb9f636 | ||
|
|
e5e64d69be | ||
|
|
01b4a049b2 | ||
|
|
50eb40841f | ||
|
|
7312d3a192 | ||
|
|
895b535f76 | ||
|
|
41a73edd97 | ||
|
|
5b872045c5 | ||
|
|
063e3b79fb | ||
|
|
2f17cd6a9a | ||
|
|
1891359e65 | ||
|
|
6a24dd7e8a | ||
|
|
9c5c3eaf64 | ||
|
|
c0801988fc | ||
|
|
46ae192d88 | ||
|
|
269ff25f0f | ||
|
|
00a33f1b7e | ||
|
|
f71a39547f | ||
|
|
b4d45ec716 | ||
|
|
dbcaa60dce | ||
|
|
5767011375 | ||
|
|
cdec541f92 | ||
|
|
680bc59d91 | ||
|
|
0f39559ff9 | ||
|
|
32a9a83b5b | ||
| 43c04a118f | |||
|
|
5882658b97 | ||
| 69904bcc52 | |||
| 6a76b4f072 | |||
| c85379b50e | |||
| 3951d7fc95 | |||
| 1576848aa1 | |||
| 741c7418ad | |||
| ec42ef9969 | |||
| 0ebeafeaf1 | |||
| c28ce7c488 | |||
| ba51a5c312 | |||
| 4d922eb4db | |||
| 039557f95e | |||
| 0a6db01cbb | |||
| 20824db73a | |||
| 121459f3c0 | |||
| f01990be88 | |||
| ec6c1cf9f0 | |||
| d1a4f83feb | |||
|
|
c79fe7d20b | ||
|
|
9b4a1934ff | ||
|
|
9e47118b3c | ||
|
|
22de814132 | ||
|
|
27cdac86cb | ||
|
|
06cdc3e7ca |
643 changed files with 18846 additions and 71520 deletions
|
|
@ -1,12 +0,0 @@
|
||||||
.git
|
|
||||||
*.md
|
|
||||||
node_modules/
|
|
||||||
npm-debug.log
|
|
||||||
.npmrc
|
|
||||||
tests/
|
|
||||||
Dockerfile*
|
|
||||||
.dockerignore
|
|
||||||
.gitignore
|
|
||||||
LICENSE
|
|
||||||
.vscode
|
|
||||||
auth.json
|
|
||||||
|
|
@ -3,13 +3,30 @@ root = true
|
||||||
[*]
|
[*]
|
||||||
charset = utf-8
|
charset = utf-8
|
||||||
end_of_line = lf
|
end_of_line = lf
|
||||||
insert_final_newline = true
|
indent_size = 2
|
||||||
indent_style = space
|
indent_style = space
|
||||||
indent_size = 4
|
insert_final_newline = true
|
||||||
trim_trailing_whitespace = true
|
trim_trailing_whitespace = true
|
||||||
|
|
||||||
[*.md]
|
[*.md]
|
||||||
trim_trailing_whitespace = false
|
trim_trailing_whitespace = false
|
||||||
|
|
||||||
[*.yml]
|
[*.{php,json}]
|
||||||
|
indent_size = 4
|
||||||
|
|
||||||
|
[*.blade.php]
|
||||||
indent_size = 2
|
indent_size = 2
|
||||||
|
|
||||||
|
[*.{yml,yaml}]
|
||||||
|
indent_size = 2
|
||||||
|
|
||||||
|
[{compose,docker-compose}.{yml,yaml}]
|
||||||
|
indent_size = 2
|
||||||
|
|
||||||
|
[*.scss]
|
||||||
|
indent_size = 2
|
||||||
|
quote_type = single
|
||||||
|
|
||||||
|
[*.css]
|
||||||
|
indent_size = 2
|
||||||
|
quote_type = single
|
||||||
|
|
|
||||||
35
.env.example
35
.env.example
|
|
@ -1,35 +0,0 @@
|
||||||
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=
|
|
||||||
12
.gitattributes
vendored
12
.gitattributes
vendored
|
|
@ -1,5 +1,7 @@
|
||||||
* text=auto
|
* text=auto eol=lf
|
||||||
*.css linguist-vendored
|
|
||||||
*.scss linguist-vendored
|
*.blade.php diff=html
|
||||||
*.js linguist-vendored
|
*.css diff=css
|
||||||
CHANGELOG.md export-ignore
|
*.html diff=html
|
||||||
|
*.md diff=markdown
|
||||||
|
*.php diff=php
|
||||||
|
|
|
||||||
35
.gitignore
vendored
35
.gitignore
vendored
|
|
@ -1,6 +1,6 @@
|
||||||
.env
|
.env
|
||||||
.env.backup
|
|
||||||
.env.testing
|
.env.testing
|
||||||
|
.env.backup
|
||||||
.env.production
|
.env.production
|
||||||
.phpunit.result.cache
|
.phpunit.result.cache
|
||||||
.stylelintcache
|
.stylelintcache
|
||||||
|
|
@ -9,16 +9,15 @@
|
||||||
/.phpunit.cache
|
/.phpunit.cache
|
||||||
/.vscode
|
/.vscode
|
||||||
/node_modules
|
/node_modules
|
||||||
/bootstrap
|
/bootstrap/cache
|
||||||
/public/build
|
/public/build
|
||||||
/public/cache
|
/public/cache
|
||||||
/public/hot
|
/public/hot
|
||||||
/public/sitemap.xml
|
/public/sitemap.xml
|
||||||
/public/storage
|
/public/storage
|
||||||
/public/export/*
|
|
||||||
!/public/export/.gitkeep
|
|
||||||
/storage/*.key
|
/storage/*.key
|
||||||
/vendor
|
/vendor
|
||||||
|
coverage/
|
||||||
auth.json
|
auth.json
|
||||||
docker-compose.override.yml
|
docker-compose.override.yml
|
||||||
Homestead.json
|
Homestead.json
|
||||||
|
|
@ -26,12 +25,30 @@ Homestead.yaml
|
||||||
npm-debug.log
|
npm-debug.log
|
||||||
yarn-error.log
|
yarn-error.log
|
||||||
.npmrc
|
.npmrc
|
||||||
/tests/coverage
|
js.save
|
||||||
|
phpstan-report.xml
|
||||||
|
|
||||||
|
# Ignore public favicon
|
||||||
|
/public/android-chrome-192x192.png
|
||||||
|
/public/android-chrome-512x512.png
|
||||||
|
/public/apple-touch-icon.png
|
||||||
|
/public/browserconfig.xml
|
||||||
|
/public/browserconfig.xml
|
||||||
|
/public/favicon-16x16.png
|
||||||
|
/public/favicon-32x32.png
|
||||||
|
/public/favicon.ico
|
||||||
|
/public/mstile-150x150.png
|
||||||
|
/public/safari-pinned-tab.svg
|
||||||
|
/public/site.webmanifest
|
||||||
|
/public/files
|
||||||
|
|
||||||
|
develop
|
||||||
|
_ide_helper.php
|
||||||
|
.phpstorm.meta.php
|
||||||
|
phpstan-report.xml
|
||||||
|
|
||||||
|
// Ignore PHPUnit cache files
|
||||||
|
cache
|
||||||
|
|
||||||
/.npm
|
# Coverage reports
|
||||||
.zshrc
|
coverage-report/
|
||||||
/.composer
|
|
||||||
/public/images/
|
|
||||||
|
|
|
||||||
162
.gitlab-ci.yml
162
.gitlab-ci.yml
|
|
@ -1,23 +1,153 @@
|
||||||
include:
|
include:
|
||||||
- project: "ldc-web/shared-ci"
|
- project: "ldc-web/shared-ci"
|
||||||
ref: "main"
|
ref: "main"
|
||||||
file: "lint/lint7.3.yml"
|
file: "security/security.yml"
|
||||||
- project: "ldc-web/shared-ci"
|
- template: Security/Secret-Detection.gitlab-ci.yml
|
||||||
ref: "main"
|
- template: Security/Container-Scanning.gitlab-ci.yml
|
||||||
file: "security/security7.3.yml"
|
|
||||||
- project: "ldc-web/shared-ci"
|
|
||||||
ref: "main"
|
|
||||||
file: "build/build7.3.yml"
|
|
||||||
- project: "ldc-web/shared-ci"
|
|
||||||
ref: "main"
|
|
||||||
file: "test/test.yml"
|
|
||||||
- project: "ldc-web/shared-ci"
|
|
||||||
ref: "main"
|
|
||||||
file: "deploy/deploy.yml"
|
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
|
- deps
|
||||||
- lint
|
- lint
|
||||||
- security
|
|
||||||
- build
|
|
||||||
- test
|
- test
|
||||||
- deploy
|
- security
|
||||||
|
|
||||||
|
workflow:
|
||||||
|
rules:
|
||||||
|
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
|
||||||
|
- if: "$CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS"
|
||||||
|
when: never
|
||||||
|
- if: "$CI_COMMIT_BRANCH"
|
||||||
|
|
||||||
|
variables:
|
||||||
|
PHP_CI_IMAGE: "$CI_REGISTRY/ldc-web/projets/ldc-web-images-docker/uwil-ci-8.5:latest"
|
||||||
|
|
||||||
|
# ---------------------------------------------------------
|
||||||
|
# DEPENDENCIES
|
||||||
|
# ---------------------------------------------------------
|
||||||
|
composer_vendor_dev:
|
||||||
|
stage: deps
|
||||||
|
image: $PHP_CI_IMAGE
|
||||||
|
cache:
|
||||||
|
key:
|
||||||
|
files:
|
||||||
|
- composer.lock
|
||||||
|
paths:
|
||||||
|
- vendor/
|
||||||
|
before_script:
|
||||||
|
- composer config gitlab-token.lab.s-web.fr "${CI_DEPLOY_USER}" "${CI_DEPLOY_PASSWORD}"
|
||||||
|
script:
|
||||||
|
- composer install --no-interaction --no-scripts --no-progress --prefer-dist
|
||||||
|
artifacts:
|
||||||
|
paths:
|
||||||
|
- vendor/
|
||||||
|
expire_in: 2h
|
||||||
|
rules:
|
||||||
|
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
|
||||||
|
- if: "$CI_COMMIT_BRANCH"
|
||||||
|
|
||||||
|
# ---------------------------------------------------------
|
||||||
|
# BASE TEMPLATE
|
||||||
|
# ---------------------------------------------------------
|
||||||
|
.php-base: &php-base
|
||||||
|
image: $PHP_CI_IMAGE
|
||||||
|
needs:
|
||||||
|
- job: composer_vendor_dev
|
||||||
|
artifacts: true
|
||||||
|
rules:
|
||||||
|
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
|
||||||
|
- if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"
|
||||||
|
|
||||||
|
# ---------------------------------------------------------
|
||||||
|
# LINT & STATIC ANALYSIS
|
||||||
|
# ---------------------------------------------------------
|
||||||
|
phplint:
|
||||||
|
<<: *php-base
|
||||||
|
stage: lint
|
||||||
|
variables:
|
||||||
|
TEXT_REPORT: php-l-report.txt
|
||||||
|
script:
|
||||||
|
- vendor/bin/parallel-lint --exclude vendor --exclude storage --exclude bootstrap --exclude node_modules --exclude .intellipest . > "$TEXT_REPORT" 2>&1; status=$?
|
||||||
|
- cat "$TEXT_REPORT"
|
||||||
|
- exit $status
|
||||||
|
artifacts:
|
||||||
|
when: always
|
||||||
|
expose_as: "php-l report"
|
||||||
|
paths:
|
||||||
|
- php-l-report.txt
|
||||||
|
|
||||||
|
pint:
|
||||||
|
<<: *php-base
|
||||||
|
stage: lint
|
||||||
|
variables:
|
||||||
|
PINT_REPORT: pint-report.txt
|
||||||
|
script:
|
||||||
|
- vendor/bin/pint --test > "$PINT_REPORT" 2>&1; status=$?
|
||||||
|
- cat "$PINT_REPORT"
|
||||||
|
- exit $status
|
||||||
|
artifacts:
|
||||||
|
when: always
|
||||||
|
expose_as: "pint report"
|
||||||
|
paths:
|
||||||
|
- pint-report.txt
|
||||||
|
|
||||||
|
phpcs:
|
||||||
|
<<: *php-base
|
||||||
|
stage: lint
|
||||||
|
variables:
|
||||||
|
PHPCS_REPORT: phpcs-report.txt
|
||||||
|
PHPCS_JUNIT: phpcs-junit.xml
|
||||||
|
script:
|
||||||
|
- vendor/bin/phpcs -q --report=full --report-junit="$PHPCS_JUNIT" --standard=phpcs.xml --extensions=php --ignore=vendor/*,storage/*,bootstrap/*,node_modules/*,.intellipest/* . > "$PHPCS_REPORT" 2>&1; status=$?
|
||||||
|
- cat "$PHPCS_REPORT"
|
||||||
|
- exit $status
|
||||||
|
artifacts:
|
||||||
|
when: always
|
||||||
|
expose_as: "phpcs report"
|
||||||
|
paths:
|
||||||
|
- "$PHPCS_REPORT"
|
||||||
|
- "$PHPCS_JUNIT"
|
||||||
|
reports:
|
||||||
|
junit: "$PHPCS_JUNIT"
|
||||||
|
|
||||||
|
phpstan:
|
||||||
|
<<: *php-base
|
||||||
|
stage: lint
|
||||||
|
variables:
|
||||||
|
PHPSTAN_REPORT: phpstan-report.txt
|
||||||
|
PHPSTAN_JUNIT: phpstan-junit.xml
|
||||||
|
script:
|
||||||
|
- vendor/bin/phpstan analyse --error-format=junit --no-progress > "$PHPSTAN_JUNIT" 2> "$PHPSTAN_REPORT"; status=$?
|
||||||
|
- if [ ! -s "$PHPSTAN_JUNIT" ] || ! head -n 1 "$PHPSTAN_JUNIT" | grep -q '^<'; then rm -f "$PHPSTAN_JUNIT"; fi
|
||||||
|
- exit $status
|
||||||
|
artifacts:
|
||||||
|
when: always
|
||||||
|
expose_as: "phpstan report"
|
||||||
|
paths:
|
||||||
|
- "$PHPSTAN_JUNIT"
|
||||||
|
reports:
|
||||||
|
junit: "$PHPSTAN_JUNIT"
|
||||||
|
|
||||||
|
# ---------------------------------------------------------
|
||||||
|
# TESTS
|
||||||
|
# ---------------------------------------------------------
|
||||||
|
pest:
|
||||||
|
<<: *php-base
|
||||||
|
stage: test
|
||||||
|
variables:
|
||||||
|
JUNIT_REPORT: junit.xml
|
||||||
|
TEXT_REPORT: test-output.txt
|
||||||
|
COVERAGE_REPORT: coverage.xml
|
||||||
|
script:
|
||||||
|
- rm -f "$JUNIT_REPORT" "$COVERAGE_REPORT"
|
||||||
|
- composer run-script tests:coverage -- --min=85 --log-junit="$JUNIT_REPORT" --coverage-clover="$COVERAGE_REPORT" > "$TEXT_REPORT" 2>&1; status=$?
|
||||||
|
- cat "$TEXT_REPORT"
|
||||||
|
- exit $status
|
||||||
|
artifacts:
|
||||||
|
when: always
|
||||||
|
expose_as: "pest report"
|
||||||
|
paths:
|
||||||
|
- junit.xml
|
||||||
|
- test-output.txt
|
||||||
|
- coverage.xml
|
||||||
|
reports:
|
||||||
|
junit: junit.xml
|
||||||
|
|
|
||||||
55
.intellipest/_pest-helper.php
Normal file
55
.intellipest/_pest-helper.php
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs the given closure after each test in the current file.
|
||||||
|
*
|
||||||
|
* @param-closure-this \Tests\TestCase $closure
|
||||||
|
*/
|
||||||
|
function afterEach(?Closure $closure = null): \Pest\PendingCalls\AfterEachCall {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs the given closure before each test in the current file.
|
||||||
|
*
|
||||||
|
* @param-closure-this \Tests\TestCase $closure
|
||||||
|
*/
|
||||||
|
function beforeEach(?Closure $closure = null): \Pest\PendingCalls\BeforeEachCall {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the given closure as a test. The first argument
|
||||||
|
* is the test description; the second argument is
|
||||||
|
* a closure that contains the test expectations.
|
||||||
|
*
|
||||||
|
* @param-closure-this \Tests\TestCase $closure
|
||||||
|
*
|
||||||
|
* @return ($description is string ? TestCall : HigherOrderTapProxy|TestCall)
|
||||||
|
*/
|
||||||
|
function test(?string $description = null, ?Closure $closure = null): \Pest\Support\HigherOrderTapProxy|\Pest\PendingCalls\TestCall {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the given closure as a test. The first argument
|
||||||
|
* is the test description; the second argument is
|
||||||
|
* a closure that contains the test expectations.
|
||||||
|
*
|
||||||
|
* @param-closure-this \Tests\TestCase $closure
|
||||||
|
*/
|
||||||
|
function it(string $description, ?Closure $closure = null): \Pest\PendingCalls\TestCall {}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Pest {
|
||||||
|
|
||||||
|
class Expectation {
|
||||||
|
public function toBeOne(): self {}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Pest\Expectations {
|
||||||
|
|
||||||
|
class OppositeExpectation {
|
||||||
|
public function toBeOne(): self {}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
15
Dockerfile
15
Dockerfile
|
|
@ -1,5 +1,10 @@
|
||||||
FROM registry.s-web.fr/ldc-web/projets/ldc-web-images-docker/ldcweb-production-7.3:060825-070701
|
ARG PHP_8_5_TAG=latest
|
||||||
COPY --chown=www-data:www-data . /app/srcs
|
FROM registry.s-web.fr/ldc-web/projets/ldc-web-images-docker/uwil-production-8.5:${PHP_8_5_TAG}
|
||||||
USER root
|
|
||||||
RUN chmod -R 755 /app/srcs/storage
|
ARG USER=www-data
|
||||||
USER www-data
|
|
||||||
|
COPY --chown=${USER}:${USER} . /app/srcs
|
||||||
|
# FROM CI
|
||||||
|
COPY --chown=${USER}:${USER} vendor/ /app/srcs/vendor/
|
||||||
|
COPY --chown=${USER}:${USER} public/build/ /app/srcs/public/build/
|
||||||
|
# END FROM CI
|
||||||
14
README.md
14
README.md
|
|
@ -1,14 +0,0 @@
|
||||||
# MesBR
|
|
||||||
|
|
||||||
## Tests unitaires
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cp .env .env.testing
|
|
||||||
|
|
||||||
// Update db vars
|
|
||||||
|
|
||||||
php artisan test
|
|
||||||
```
|
|
||||||
|
|
||||||
## Gestion du Legacy
|
|
||||||
Au moment de la suppression du legacy, ne pas oublier de refaire les factory au propre pour les models
|
|
||||||
|
|
@ -1,49 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Console\Commands;
|
|
||||||
|
|
||||||
use App\Jobs\ArchiveStatsJob;
|
|
||||||
use App\Models\ArchiveSite;
|
|
||||||
use App\Models\ArchiveStat;
|
|
||||||
use App\Models\Statistique;
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
|
|
||||||
class ArchiveStatsCommand extends Command
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The name and signature of the console command.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $signature = 'uwil:stats:archive';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The console command description.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $description = 'Archives mesbr stats';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the console command.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle(): void
|
|
||||||
{
|
|
||||||
$baseArchiveStatCount = ArchiveStat::count();
|
|
||||||
$baseStatCount = Statistique::count();
|
|
||||||
|
|
||||||
(new ArchiveStatsJob())->handle();
|
|
||||||
|
|
||||||
$this->info(sprintf(
|
|
||||||
'%s archive(s) created',
|
|
||||||
ArchiveStat::count() - $baseArchiveStatCount
|
|
||||||
));
|
|
||||||
$this->info(sprintf(
|
|
||||||
'%s stat(s) deleted',
|
|
||||||
$baseStatCount - Statistique::count()
|
|
||||||
));
|
|
||||||
$this->info('Stats archived 👌');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,133 +0,0 @@
|
||||||
<?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(function () {
|
|
||||||
return $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(function () {
|
|
||||||
return $this->ask('Enter customer email');
|
|
||||||
}, 'required|email|min:1|max:255');
|
|
||||||
|
|
||||||
$crmHashcode = $this->validateInput(function () {
|
|
||||||
return $this->ask('Enter customer hashcode');
|
|
||||||
}, 'required|string|min:1|max:36');
|
|
||||||
|
|
||||||
$crmCountry = $this->validateInput(function () {
|
|
||||||
return $this->ask('Enter customer country ISO code');
|
|
||||||
}, 'required|numeric|in:56,250,442');
|
|
||||||
|
|
||||||
$date = $this->validateInput(function () {
|
|
||||||
return $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 = Carbon::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(function () use ($toAdd) {
|
|
||||||
return $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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,56 +0,0 @@
|
||||||
<?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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,115 +0,0 @@
|
||||||
<?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 () {
|
|
||||||
$sites = Site::all();
|
|
||||||
$couponSeuilGlobal = array();
|
|
||||||
$couponDiffusionGlobal = array();
|
|
||||||
$sendGlobal = false;
|
|
||||||
foreach ($sites as $site) {
|
|
||||||
// ---- Pour chaque site
|
|
||||||
$campagnes = Campagne::where(['camp_siteId' => $site->site_id])->get();
|
|
||||||
foreach ($campagnes as $campagne) {
|
|
||||||
$sendMail = false;
|
|
||||||
$users = array();
|
|
||||||
$couponSeuil = array();
|
|
||||||
$couponDiffusion = array();
|
|
||||||
$coupons = $campagne->coupons()->get();
|
|
||||||
foreach ($coupons as $coupon) {
|
|
||||||
$couponAlert = false;
|
|
||||||
if ($coupon->coupon_published) {
|
|
||||||
$coupon->coupon_left = $this->getFullQuantity($coupon) - $this->getUsedQuantity($coupon);
|
|
||||||
if ($coupon->coupon_left < $coupon->coupon_seuil_alert) {
|
|
||||||
array_push($couponSeuil, $coupon);
|
|
||||||
array_push($couponSeuilGlobal, [$site->site_nom, $coupon]);
|
|
||||||
$sendGlobal = true;
|
|
||||||
$couponAlert = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- Check MaxDateDiffusion
|
|
||||||
if ($coupon->coupon_maxdatediffusion != null && strtotime($coupon->coupon_maxdatediffusion) < (time() + (30 * 24 * 60 * 60))) {
|
|
||||||
// Fin de diffusion dans moins de 30jours
|
|
||||||
array_push($couponDiffusion, $coupon);
|
|
||||||
array_push($couponDiffusionGlobal, [$site->site_nom, $coupon]);
|
|
||||||
$sendGlobal = true;
|
|
||||||
$couponAlert = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($couponAlert) {
|
|
||||||
$notifications = Notification::where(['notif_campId' => $campagne->camp_id])->get();
|
|
||||||
foreach ($notifications as $notification) {
|
|
||||||
if (!array_key_exists($notification->notif_id, $users)) {
|
|
||||||
$userObject = [];
|
|
||||||
$userObject['email'] = $notification->notif_email;
|
|
||||||
$userObject['name'] = $notification->notif_name;
|
|
||||||
$users[$notification->notif_id] = (object)$userObject;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$sendMail = true;
|
|
||||||
}
|
|
||||||
} //end if
|
|
||||||
} //end foreach
|
|
||||||
|
|
||||||
if ($sendMail) {
|
|
||||||
Mail::to($users)->send(new AlertBr($couponSeuil, $couponDiffusion, $site->site_nom));
|
|
||||||
}
|
|
||||||
} //end foreach
|
|
||||||
} //end foreach
|
|
||||||
if ($sendGlobal) {
|
|
||||||
$superadmins = array();
|
|
||||||
$admins = User::where(['roles' => 'superadmin'])->get();
|
|
||||||
foreach ($admins as $admin) {
|
|
||||||
$adminObject = [];
|
|
||||||
$adminObject['email'] = $admin->email;
|
|
||||||
$adminObject['name'] = $admin->name;
|
|
||||||
array_push($superadmins, (object)$adminObject);
|
|
||||||
}
|
|
||||||
Mail::to($superadmins)->send(new AlertBrAdmin($couponSeuilGlobal, $couponDiffusionGlobal));
|
|
||||||
}
|
|
||||||
})->weekdays()->at('7:00');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
<?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'),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
<?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',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
<?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',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
<?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')
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,65 +0,0 @@
|
||||||
<?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) {
|
|
||||||
if (app()->bound('sentry')) {
|
|
||||||
app('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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,301 +0,0 @@
|
||||||
<?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 = array();
|
|
||||||
|
|
||||||
$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 $key => $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 $key => $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);
|
|
||||||
}
|
|
||||||
array_push($couponsPrinted, ['cp_code' => $cp->coupon_code, 'qty' => 1]);
|
|
||||||
// ---- 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();
|
|
||||||
}//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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,114 +0,0 @@
|
||||||
<?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'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,509 +0,0 @@
|
||||||
<?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 = array();
|
|
||||||
foreach ($panierTab as $panier) {
|
|
||||||
$pos = strpos($panier, ")");
|
|
||||||
if ($pos === false || substr_count($panier, ")") != 1) {
|
|
||||||
$log->log_params = json_encode(['basketid' => $basketid, 'panier' => $panier]);
|
|
||||||
$log->log_statut = 'NOK';
|
|
||||||
$log->log_message = "Des paramètres de la requête sont mal renseignés ou non présents";
|
|
||||||
$log->save();
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'KO',
|
|
||||||
'Code' => 101,
|
|
||||||
'Message' => 'Des paramètres de la requête sont mal renseignés ou non présents'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
$quantity = substr($panier, 0, $pos);
|
|
||||||
$quantity = str_replace("(", "", $quantity);
|
|
||||||
$couponCode = substr($panier, $pos + 1);
|
|
||||||
|
|
||||||
if (is_numeric($quantity) && is_numeric($couponCode)) {
|
|
||||||
if (isset($coupons[$couponCode])) {
|
|
||||||
$coupons[$couponCode] = $coupons[$couponCode] + $quantity;
|
|
||||||
} else {
|
|
||||||
$coupons[$couponCode] = $quantity;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$log->log_params = json_encode(['basketid' => $basketid, 'panier' => $panier]);
|
|
||||||
$log->log_statut = 'NOK';
|
|
||||||
$log->log_message = "Des paramètres de la requête sont mal renseignés ou non présents";
|
|
||||||
$log->save();
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'KO',
|
|
||||||
'Code' => 101,
|
|
||||||
'Message' => 'Des paramètres de la requête sont mal renseignés ou non présents'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}//end foreach
|
|
||||||
// ---- Préparation message de log avec coupons
|
|
||||||
$panierCoupons = array();
|
|
||||||
foreach ($coupons as $code => $qty) {
|
|
||||||
array_push($panierCoupons, ['cp_code' => $code, 'qty' => $qty]);
|
|
||||||
}
|
|
||||||
if (count($coupons) == 0) {
|
|
||||||
die();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$log->log_params = json_encode(['basketid' => $basketid, 'panier' => $panier]);
|
|
||||||
$log->log_statut = 'NOK';
|
|
||||||
$log->log_message = "Des paramètres de la requête sont mal renseignés ou non présents";
|
|
||||||
$log->save();
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'KO',
|
|
||||||
'Code' => 101,
|
|
||||||
'Message' => 'Des paramètres de la requête sont mal renseignés ou non présents'
|
|
||||||
]);
|
|
||||||
}//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 = array();
|
|
||||||
foreach ($panierTab as $panier) {
|
|
||||||
$pos = strpos($panier, ")");
|
|
||||||
if ($pos === false) {
|
|
||||||
$error = true;
|
|
||||||
}
|
|
||||||
$quantity = substr($panier, 0, $pos);
|
|
||||||
$quantity = str_replace("(", "", $quantity);
|
|
||||||
$couponCode = substr($panier, $pos + 1);
|
|
||||||
|
|
||||||
if (is_numeric($quantity) && is_numeric($couponCode) && $quantity > 0) {
|
|
||||||
if (isset($coupons[$couponCode])) {
|
|
||||||
$coupons[$couponCode] = $coupons[$couponCode] + $quantity;
|
|
||||||
} else {
|
|
||||||
$coupons[$couponCode] = $quantity;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (count($coupons) == 0) {
|
|
||||||
die();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$error = true;
|
|
||||||
}//end if
|
|
||||||
|
|
||||||
// ---- Préparation message de log avec coupons
|
|
||||||
if (isset($coupons)) {
|
|
||||||
$panierCoupons = array();
|
|
||||||
foreach ($coupons as $code => $qty) {
|
|
||||||
array_push($panierCoupons, ['cp_code' => $code, 'qty' => $qty]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if ($error) {
|
|
||||||
$log->log_params = json_encode(['refcamp' => $request->refcamp, 'refadherent' => $request->refadherent, 'refsite' => $request->refsite, 'nom' => $request->nom, 'prenom' => $request->prenom, 'email' => $request->email, 'code postal' => $request->code_postal, 'commune' => $request->commune, 'panier' => $request->panier]);
|
|
||||||
$log->log_statut = 'NOK';
|
|
||||||
$log->log_message = "Des paramètres de la requête sont mal renseignés ou non présents";
|
|
||||||
$log->save();
|
|
||||||
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'KO',
|
|
||||||
'Code' => 101,
|
|
||||||
'Message' => 'Des paramètres de la requête sont mal renseignés ou non présents'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---- Ajout/MAJ du contact
|
|
||||||
$contact = Contact::where(['contact_siteId' => $refsite, 'contact_ref' => $refadherent])->first();
|
|
||||||
if ($contact) {
|
|
||||||
// ---- Mise à jour du contact
|
|
||||||
$contact->contact_prenom = $prenom;
|
|
||||||
$contact->contact_nom = $nom;
|
|
||||||
$contact->contact_email = $email;
|
|
||||||
$contact->contact_cp = $code_postal;
|
|
||||||
$contact->contact_ville = $commune;
|
|
||||||
$contact->contact_country = $pays;
|
|
||||||
$contact->contact_updatedate = date('Y-m-d H:i:s');
|
|
||||||
} else {
|
|
||||||
// ---- Création du contact
|
|
||||||
$site = Site::where('site_id', $refsite)->first();
|
|
||||||
|
|
||||||
if ($site) {
|
|
||||||
$contact = new Contact();
|
|
||||||
$contact->contact_nom = $nom;
|
|
||||||
$contact->contact_prenom = $prenom;
|
|
||||||
$contact->contact_ref = $refadherent;
|
|
||||||
$contact->contact_email = $email;
|
|
||||||
$contact->contact_cp = $code_postal;
|
|
||||||
$contact->contact_ville = $commune;
|
|
||||||
$contact->contact_country = $pays;
|
|
||||||
$contact->contact_siteId = $refsite;
|
|
||||||
$contact->contact_hash = strtoupper(md5(uniqid(time(), true)));
|
|
||||||
} else {
|
|
||||||
$log->log_params = json_encode(['refcamp' => $request->refcamp, 'refadherent' => $request->refadherent, 'refsite' => $request->refsite, 'nom' => $request->nom, 'prenom' => $request->prenom, 'email' => $request->email, 'code postal' => $request->code_postal, 'commune' => $request->commune, 'panier' => $request->panier]);
|
|
||||||
$log->log_statut = 'NOK';
|
|
||||||
$log->log_message = "Le site spécifié n'existe pas";
|
|
||||||
$log->save();
|
|
||||||
|
|
||||||
return response()->json([
|
|
||||||
'Statut' => 'KO',
|
|
||||||
'Code' => 102,
|
|
||||||
'Message' => 'Le site spécifié n\'existe pas'
|
|
||||||
]);
|
|
||||||
}//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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,146 +0,0 @@
|
||||||
<?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 = false;
|
|
||||||
foreach ($requiredParams as $param) {
|
|
||||||
if (empty($request->{$param})) {
|
|
||||||
$error = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,79 +0,0 @@
|
||||||
<?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\CrmApiV2;
|
|
||||||
|
|
||||||
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 CrmApiV2(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 $e) {
|
|
||||||
// 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 $key => $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'))))]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,250 +0,0 @@
|
||||||
<?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
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,68 +0,0 @@
|
||||||
<?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)
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,49 +0,0 @@
|
||||||
<?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('/');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
<?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', '>=', Carbon::now()->subMonths(5)->startOfMonth())
|
|
||||||
->groupBy('month')
|
|
||||||
->orderBy('month', 'asc')
|
|
||||||
->get();
|
|
||||||
|
|
||||||
$logs = $datas->toArray();
|
|
||||||
|
|
||||||
return view('bo.maintenance.index', compact('logs'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,76 +0,0 @@
|
||||||
<?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 redirect()->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(function ($marque) {
|
|
||||||
return $marque->only(['id', 'site_nom', 'site_id', 'site_logo']);
|
|
||||||
});
|
|
||||||
session()->put('marques', $submarques);
|
|
||||||
|
|
||||||
return redirect()->route('bo.users.edit', $user);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function destroy(DestroyUserRequest $request, User $user)
|
|
||||||
{
|
|
||||||
if ($user->delete()) {
|
|
||||||
return redirect()->route('bo.users.index');
|
|
||||||
} else {
|
|
||||||
session()->flash('delete_nok', 'Erreur lors de la suppression');
|
|
||||||
return view('bo.user.index');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
<?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 redirect()->back();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,415 +0,0 @@
|
||||||
<?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 ($q) use ($campagne) {
|
|
||||||
$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 redirect()->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 redirect()->back();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param RemoveNotifCampaign $request
|
|
||||||
* @param \App\Models\Notification $notification
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function deleteNotification(RemoveNotifCampaign $request, Notification $notification)
|
|
||||||
{
|
|
||||||
if ($notification->delete()) {
|
|
||||||
return redirect()->back();
|
|
||||||
} else {
|
|
||||||
session()->flash('delete_nok', 'Erreur lors de la suppression');
|
|
||||||
return redirect()->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 = array (
|
|
||||||
'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 = array (
|
|
||||||
"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
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
<?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;
|
|
||||||
}
|
|
||||||
|
|
@ -1,243 +0,0 @@
|
||||||
<?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 redirect()->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 redirect()->route('coupon.edit', ['coupon' => $coupon]);
|
|
||||||
} else {
|
|
||||||
return view('holder');
|
|
||||||
} //end if
|
|
||||||
|
|
||||||
return redirect()->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 redirect()->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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,93 +0,0 @@
|
||||||
<?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\CrmApiV2;
|
|
||||||
|
|
||||||
class BasketController extends Controller
|
|
||||||
{
|
|
||||||
use GenerateBR;
|
|
||||||
|
|
||||||
// FIXME: Docblock
|
|
||||||
public function show(Request $request, Basket $basket)
|
|
||||||
{
|
|
||||||
$totalQuantity = $basket->contents->sum(function ($content) {
|
|
||||||
return $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;
|
|
||||||
|
|
||||||
// FIXME: Bump to CrmApiV4
|
|
||||||
$crm = new CrmApiV2(config('services.crm.endpoint'), $campagne->site->crm_token, $campagne->site->crm_password);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \LDC\LDCCRM\Models\Customer
|
|
||||||
*/
|
|
||||||
$crmInfos = $crm->getCustomer($basket->customer->hashcode);
|
|
||||||
|
|
||||||
if (is_null($crmInfos)) {
|
|
||||||
throw new \Exception('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 redirect()->route('fo.basket.show', $basket);
|
|
||||||
}
|
|
||||||
|
|
||||||
// $coupons contains all printed coupons
|
|
||||||
$pdf = PDF::loadView('pdf.coupons', ['coupons' => $coupons]);
|
|
||||||
return $pdf->download(sprintf("coupons_%s_%s_%s.pdf", $crmInfos->firstname, $crmInfos->lastname, date('d-m-Y_H-i-s')));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,165 +0,0 @@
|
||||||
<?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();
|
|
||||||
if (!$panier) {
|
|
||||||
abort(404);
|
|
||||||
}
|
|
||||||
session()->put('panier', $panier);
|
|
||||||
$panierCouponsCount = $this->getCountCouponsPanierPublished($panier);
|
|
||||||
$contact = Contact::where(['contact_id' => $panier->panier_contactId])->first();
|
|
||||||
if (!$contact) {
|
|
||||||
abort(404);
|
|
||||||
}
|
|
||||||
session()->put('contact', $contact);
|
|
||||||
|
|
||||||
$campagne = Campagne::where(['camp_id' => $panier->panier_campId, 'camp_published' => 1])->first();
|
|
||||||
if (!$campagne) {
|
|
||||||
abort(404);
|
|
||||||
}
|
|
||||||
session()->put('campagne', $campagne);
|
|
||||||
|
|
||||||
if ($campagne->camp_type->equals(CampaignTypes::panier())) {
|
|
||||||
$coupons = $this->getCouponsPublished($campagne);
|
|
||||||
} else {
|
|
||||||
$panierContents = $this->getPanierContentPublished($panier);
|
|
||||||
$coupons = array();
|
|
||||||
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 = $request->coupons;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request->session()->has('campagne')) {
|
|
||||||
$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
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
<?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 redirect()->route('login');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,127 +0,0 @@
|
||||||
<?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(function ($marque) {
|
|
||||||
return $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 redirect()->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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,81 +0,0 @@
|
||||||
<?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 $routeMiddleware = [
|
|
||||||
'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,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
<?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');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
<?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 = [
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
<?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 = [
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
<?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 redirect()->route('campagne.index');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $next($request);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,40 +0,0 @@
|
||||||
<?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(function ($marque) {
|
|
||||||
return $marque->only(['id', 'site_nom', 'site_id', 'site_logo']);
|
|
||||||
});
|
|
||||||
session()->put('marques', $submarques);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $next($request);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
<?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',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Middleware;
|
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Fideloper\Proxy\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_ALL;
|
|
||||||
}
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Middleware;
|
|
||||||
|
|
||||||
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
|
|
||||||
|
|
||||||
class VerifyCsrfToken extends Middleware
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* 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',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
<?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 [
|
|
||||||
//
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
<?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'
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
<?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'
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
<?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'
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
<?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'
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
<?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 [
|
|
||||||
//
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
<?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 [
|
|
||||||
//
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
<?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 [
|
|
||||||
//
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
<?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 [
|
|
||||||
//
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
<?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'
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
<?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(function ($query) {
|
|
||||||
return $query->where('notif_campId', $this->campaign->camp_id);
|
|
||||||
}),
|
|
||||||
]
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
<?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'
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,48 +0,0 @@
|
||||||
<?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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,75 +0,0 @@
|
||||||
<?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\Validation\Validator $validator
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function withValidator($validator)
|
|
||||||
{
|
|
||||||
$validator->sometimes('coupon_gs1code', 'required|image|mimes:jpeg', function ($input) {
|
|
||||||
return isset($input->coupon_norme);
|
|
||||||
});
|
|
||||||
|
|
||||||
$validator->sometimes('coupon_limitquantity', 'integer|required', function ($input) {
|
|
||||||
return !is_null($input->coupon_enablelimitquantity);
|
|
||||||
});
|
|
||||||
|
|
||||||
$validator->sometimes('coupon_limitperiod', 'integer|required', function ($input) {
|
|
||||||
return !is_null($input->coupon_enablelimitperiod);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,82 +0,0 @@
|
||||||
<?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\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', function ($input) {
|
|
||||||
return !is_null($input->coupon_enablelimitquantity);
|
|
||||||
});
|
|
||||||
|
|
||||||
$validator->sometimes('coupon_limitperiod', 'integer|required', function ($input) {
|
|
||||||
return !is_null($input->coupon_enablelimitperiod);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,45 +0,0 @@
|
||||||
<?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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,45 +0,0 @@
|
||||||
<?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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,33 +0,0 @@
|
||||||
<?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'
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,46 +0,0 @@
|
||||||
<?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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
<?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'
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,49 +0,0 @@
|
||||||
<?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;
|
|
||||||
|
|
||||||
if (!$campagne->camp_type->equals(CampaignTypes::panier())) {
|
|
||||||
throw new \Exception('Campaign is not basket.');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($campagne->camp_published === 0) {
|
|
||||||
throw new \Exception('Campaign is not published.');
|
|
||||||
}
|
|
||||||
if ($campagne->site->crm_token === null) {
|
|
||||||
throw new \Exception('CRM Token is missing.');
|
|
||||||
}
|
|
||||||
if ($campagne->site->crm_password === null) {
|
|
||||||
throw new \Exception('CRM Password is missing.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the validation rules that apply to the request.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function rules()
|
|
||||||
{
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,44 +0,0 @@
|
||||||
<?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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
||||||
<?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' => isset($this->isUsed) ? $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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
<?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)
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
<?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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,67 +0,0 @@
|
||||||
<?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 () {
|
|
||||||
Statistique::query()
|
|
||||||
->where('date', '<', now())
|
|
||||||
->each(function ($stat) {
|
|
||||||
$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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,81 +0,0 @@
|
||||||
<?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 () {
|
|
||||||
// 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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,108 +0,0 @@
|
||||||
<?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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array $customer
|
|
||||||
*/
|
|
||||||
private $customer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*
|
|
||||||
* @param array $customer
|
|
||||||
*/
|
|
||||||
public function __construct($customer)
|
|
||||||
{
|
|
||||||
$this->onConnection('rabbitmq');
|
|
||||||
$this->customer = $customer;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
$hashchode = $this->customer['hashcode'];
|
|
||||||
$email = $this->customer['email'];
|
|
||||||
|
|
||||||
try {
|
|
||||||
DB::transaction(function () use ($hashchode, $email) {
|
|
||||||
// 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'], ';');
|
|
||||||
\fclose($logFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
$logFile = fopen($csvPath, 'a');
|
|
||||||
\fputcsv(
|
|
||||||
$logFile,
|
|
||||||
[
|
|
||||||
\now()->toAtomString(),
|
|
||||||
$this->customer['hashcode'],
|
|
||||||
$this->customer['email'],
|
|
||||||
$message
|
|
||||||
],
|
|
||||||
';'
|
|
||||||
);
|
|
||||||
\fclose($logFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,190 +0,0 @@
|
||||||
<?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]);
|
|
||||||
switch ($type) {
|
|
||||||
case 'object':
|
|
||||||
$traceArgs .= sprintf('Object(%s)', \get_class($stack['args'][$i]));
|
|
||||||
break;
|
|
||||||
case 'array':
|
|
||||||
$traceArgs .= sprintf('Array(%d)', \count($stack['args'][$i]));
|
|
||||||
break;
|
|
||||||
case 'string':
|
|
||||||
$traceArgs .= sprintf('String(%d)', \strlen($stack['args'][$i]));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$traceArgs .= \gettype($stack['args'][$i]);
|
|
||||||
}
|
|
||||||
$traceArgs .= ($i !== ($argsCount - 1) ? ',' : '');
|
|
||||||
}
|
|
||||||
return $traceArgs;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,104 +0,0 @@
|
||||||
<?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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,42 +0,0 @@
|
||||||
<?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 $couponSeuil;
|
|
||||||
|
|
||||||
public $couponDiffusion;
|
|
||||||
|
|
||||||
public $subject;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new message instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct($couponSeuil, $couponDiffusion, $sitename)
|
|
||||||
{
|
|
||||||
$this->couponSeuil = $couponSeuil;
|
|
||||||
$this->couponDiffusion = $couponDiffusion;
|
|
||||||
$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]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,42 +0,0 @@
|
||||||
<?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 $couponSeuil;
|
|
||||||
|
|
||||||
public $couponDiffusion;
|
|
||||||
|
|
||||||
public $subject;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new message instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct($couponSeuil, $couponDiffusion)
|
|
||||||
{
|
|
||||||
$this->couponSeuil = $couponSeuil;
|
|
||||||
$this->couponDiffusion = $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]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,82 +0,0 @@
|
||||||
<?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) {
|
|
||||||
$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 () {
|
|
||||||
throw new \RuntimeException('Updating an archived campaign is not authorized');
|
|
||||||
});
|
|
||||||
static::deleting(function () {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,60 +0,0 @@
|
||||||
<?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) {
|
|
||||||
$model->assertFieldIsUnique('coupon_code', $model->coupon_code);
|
|
||||||
});
|
|
||||||
static::updating(function () {
|
|
||||||
throw new \RuntimeException('Updating an archived coupon is not authorized');
|
|
||||||
});
|
|
||||||
static::deleting(function () {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,60 +0,0 @@
|
||||||
<?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) {
|
|
||||||
$model->assertFieldIsUnique('site_id', $model->site_id);
|
|
||||||
});
|
|
||||||
static::updating(function (self $model) {
|
|
||||||
throw new \RuntimeException('Updating an archived site is not authorized');
|
|
||||||
});
|
|
||||||
static::deleting(function () {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,91 +0,0 @@
|
||||||
<?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) {
|
|
||||||
$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 () {
|
|
||||||
throw new \RuntimeException('Upating an archived stat is not authorized');
|
|
||||||
});
|
|
||||||
static::deleting(function () {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,82 +0,0 @@
|
||||||
<?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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
<?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) {
|
|
||||||
$model->printed = 0;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Basket model relation
|
|
||||||
* @return HasOne
|
|
||||||
*/
|
|
||||||
public function basket()
|
|
||||||
{
|
|
||||||
return $this->hasOne(Basket::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Coupon model relation
|
|
||||||
* @return HasOne
|
|
||||||
*/
|
|
||||||
public function coupon()
|
|
||||||
{
|
|
||||||
return $this->hasOne(Coupon::class, 'coupon_id', 'coupon_id');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,54 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
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', 'calendrier_couponId');
|
|
||||||
}
|
|
||||||
|
|
||||||
// * METHODS
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the current date is between the calendar publication dates.
|
|
||||||
*
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public function isPublished(): bool
|
|
||||||
{
|
|
||||||
return now()->betweenIncluded($this->calendrier_startdate, $this->calendrier_enddate->endOfDay());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,128 +0,0 @@
|
||||||
<?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', 'notif_campId', 'camp_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* OneToMany
|
|
||||||
* Campagne -> Mur
|
|
||||||
*/
|
|
||||||
public function murs()
|
|
||||||
{
|
|
||||||
return $this->hasMany('App\Models\Mur', 'mur_campId', 'camp_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* OneToMany
|
|
||||||
* Campagne -> Panier
|
|
||||||
*/
|
|
||||||
public function paniers()
|
|
||||||
{
|
|
||||||
return $this->hasMany('App\Models\Panier', 'panier_campId', 'camp_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ManyToOne
|
|
||||||
* Campagne -> Site
|
|
||||||
*/
|
|
||||||
public function site()
|
|
||||||
{
|
|
||||||
return $this->belongsTo('App\Models\Site', 'camp_siteId', 'site_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The coupons that belong to the campagne.
|
|
||||||
*/
|
|
||||||
public function coupons()
|
|
||||||
{
|
|
||||||
return $this->belongsToMany('App\Models\Coupon', '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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,125 +0,0 @@
|
||||||
<?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', 'mur_contactId', 'contact_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* OneToMany
|
|
||||||
* Contact -> Panier
|
|
||||||
*/
|
|
||||||
public function paniers()
|
|
||||||
{
|
|
||||||
return $this->hasMany('App\Models\Panier', 'panier_contactId', 'contact_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ManyToOne
|
|
||||||
* Contact -> Site
|
|
||||||
*/
|
|
||||||
public function site()
|
|
||||||
{
|
|
||||||
return $this->belongsTo('App\Models\Site', 'contact_siteId');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function scopeSearchName($query, $name)
|
|
||||||
{
|
|
||||||
if ($name) {
|
|
||||||
$query->where('contact_nom', 'like', '%' . $name . '%');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function scopeSearchFirstname($query, $firstname)
|
|
||||||
{
|
|
||||||
if ($firstname) {
|
|
||||||
$query->where('contact_prenom', 'like', '%' . $firstname . '%');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function scopeSearchEmail($query, $email)
|
|
||||||
{
|
|
||||||
if ($email) {
|
|
||||||
$query->where('contact_email', 'like', '%' . $email . '%');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function scopeSearchVille($query, $ville)
|
|
||||||
{
|
|
||||||
if ($ville) {
|
|
||||||
$query->where('contact_ville', 'like', '%' . $ville . '%');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function scopeSearchCp($query, $cp)
|
|
||||||
{
|
|
||||||
if ($cp) {
|
|
||||||
$query->where('contact_cp', 'like', '%' . $cp . '%');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public 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');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,135 +0,0 @@
|
||||||
<?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', 'calendrier_couponId', 'coupon_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* OneToMany
|
|
||||||
* Coupon -> PanierContent
|
|
||||||
*/
|
|
||||||
public function panierContents()
|
|
||||||
{
|
|
||||||
return $this->hasMany('App\Models\PanierContent', 'panier_content_couponId', 'coupon_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* OneToMany
|
|
||||||
* Coupon -> Mur
|
|
||||||
*/
|
|
||||||
public function murs()
|
|
||||||
{
|
|
||||||
return $this->hasMany('App\Models\Mur', 'mur_couponId', 'coupon_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* OneToMany
|
|
||||||
* Coupon -> Mouvement
|
|
||||||
*/
|
|
||||||
public function mouvements()
|
|
||||||
{
|
|
||||||
return $this->hasMany('App\Models\Mouvement', 'mouvement_couponId', 'coupon_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ManyToOne
|
|
||||||
* Coupon -> Site
|
|
||||||
*/
|
|
||||||
public function site()
|
|
||||||
{
|
|
||||||
return $this->belongsTo('App\Models\Site', 'coupon_siteId');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The campagnes that belong to the coupon.
|
|
||||||
*/
|
|
||||||
public function campagnes()
|
|
||||||
{
|
|
||||||
return $this->belongsToMany('App\Models\Campagne', 'campagne_coupon', 'coup_id', 'campagne_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* BasketContent model relation
|
|
||||||
* @return HasMany
|
|
||||||
*/
|
|
||||||
public function basketContents()
|
|
||||||
{
|
|
||||||
return $this->hasMany(BasketContent::class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,95 +0,0 @@
|
||||||
<?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) {
|
|
||||||
$customer->country = (new Customers())->getIsoCountry($customer->country);
|
|
||||||
});
|
|
||||||
|
|
||||||
static::updating(function ($customer) {
|
|
||||||
$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)));
|
|
||||||
switch ($country) {
|
|
||||||
case 'Belgique':
|
|
||||||
$country = 56;
|
|
||||||
break;
|
|
||||||
case 'Luxembourg':
|
|
||||||
$country = 442;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$country = 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');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,37 +0,0 @@
|
||||||
<?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',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
@ -1,42 +0,0 @@
|
||||||
<?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', 'mouvement_couponId');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,50 +0,0 @@
|
||||||
<?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', 'mur_campId');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ManyToOne
|
|
||||||
* Mur -> Contact
|
|
||||||
*/
|
|
||||||
public function contact()
|
|
||||||
{
|
|
||||||
return $this->belongsTo('App\Models\Contact', 'mur_contactId');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ManyToOne
|
|
||||||
* Mur -> Coupon
|
|
||||||
*/
|
|
||||||
public function coupon()
|
|
||||||
{
|
|
||||||
return $this->belongsTo('App\Models\Coupon', 'mur_couponId');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
<?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', 'notif_campId');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,54 +0,0 @@
|
||||||
<?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', 'panier_content_panierId', 'panier_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ManyToOne
|
|
||||||
* Panier -> Campagne
|
|
||||||
*/
|
|
||||||
public function campagne()
|
|
||||||
{
|
|
||||||
return $this->belongsTo('App\Models\Campagne', 'panier_campId');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ManyToOne
|
|
||||||
* Panier -> Contact
|
|
||||||
*/
|
|
||||||
public function contact()
|
|
||||||
{
|
|
||||||
return $this->belongsTo('App\Models\Contact', 'panier_contactId');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,51 +0,0 @@
|
||||||
<?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', 'panier_content_panierId', 'panier_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ManyToOne
|
|
||||||
* PanierContent -> Coupon
|
|
||||||
*/
|
|
||||||
public function coupon()
|
|
||||||
{
|
|
||||||
return $this->belongsTo('App\Models\Coupon', 'panier_content_couponId');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $fillable = [
|
|
||||||
'panier_content_panierId',
|
|
||||||
'panier_content_couponId',
|
|
||||||
'panier_content_quantity',
|
|
||||||
'panier_content_printed'
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
|
|
||||||
class PrintedCoupons extends Model
|
|
||||||
{
|
|
||||||
use HasFactory;
|
|
||||||
}
|
|
||||||
|
|
@ -1,79 +0,0 @@
|
||||||
<?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', 'camp_siteId', 'site_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* OneToMany
|
|
||||||
* Site -> Contact
|
|
||||||
*/
|
|
||||||
public function contacts()
|
|
||||||
{
|
|
||||||
return $this->hasMany('App\Models\Contact', 'contact_siteId', 'site_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The users that belong to the site.
|
|
||||||
*/
|
|
||||||
public function users()
|
|
||||||
{
|
|
||||||
return $this->belongsToMany('App\Models\User', 'site_user', 'site_id', 'user_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* OneToMany
|
|
||||||
* Site -> Coupon
|
|
||||||
*/
|
|
||||||
public function coupons()
|
|
||||||
{
|
|
||||||
return $this->hasMany('App\Models\Coupon', 'coupon_siteId', 'id');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function __toString()
|
|
||||||
{
|
|
||||||
return $this->site_id . " : " . $this->site_nom;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,73 +0,0 @@
|
||||||
<?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) {
|
|
||||||
$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');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,64 +0,0 @@
|
||||||
<?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', 'site_user', 'user_id', 'site_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function sendPasswordResetNotification($token)
|
|
||||||
{
|
|
||||||
$this->notify(new ResetPassword($token));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,51 +0,0 @@
|
||||||
<?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 [
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Providers;
|
|
||||||
|
|
||||||
use Illuminate\Http\Resources\Json\JsonResource;
|
|
||||||
use Illuminate\Support\Facades\URL;
|
|
||||||
use Illuminate\Support\ServiceProvider;
|
|
||||||
|
|
||||||
class AppServiceProvider extends ServiceProvider
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Bootstrap any application services.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function boot()
|
|
||||||
{
|
|
||||||
URL::forceScheme('https');
|
|
||||||
$this->loadViewsFrom(storage_path('app/public/landings'), 'landings');
|
|
||||||
|
|
||||||
JsonResource::withoutWrapping();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register any application services.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function register()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue