- yarn.lock
This commit is contained in:
parent
3e51736020
commit
d1495826a4
3 changed files with 8081 additions and 6286 deletions
119
app/Console/Commands/CheckAlert.php
Normal file
119
app/Console/Commands/CheckAlert.php
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Campagne;
|
||||
use App\Mail\AlertBr;
|
||||
use App\Mail\AlertBrAdmin;
|
||||
use App\Notification;
|
||||
use App\Site;
|
||||
use App\User;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use App\Traits\CouponTrait;
|
||||
|
||||
class CheckAlert extends Command
|
||||
{
|
||||
use CouponTrait;
|
||||
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'check:alert';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Command description';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->info('Démarrage du traitement');
|
||||
|
||||
$sites = Site::all();
|
||||
$couponSeuilGlobal = array();
|
||||
$couponDiffusionGlobal = array();
|
||||
$sendGlobal = false;
|
||||
foreach ($sites as $site) { // ---- Pour chaque site
|
||||
$campagnes = Campagne::where(['camp_siteId' => $site->site_id])->get();
|
||||
foreach ($campagnes as $campagne) {
|
||||
$sendMail = false;
|
||||
$users = array();
|
||||
$couponSeuil = array();
|
||||
$couponDiffusion = array();
|
||||
$coupons = $campagne->coupons()->get();
|
||||
foreach ($coupons as $coupon) {
|
||||
$couponAlert = false;
|
||||
if ($coupon->coupon_published) {
|
||||
$coupon->coupon_left = $this->getFullQuantity($coupon) - $this->getUsedQuantity($coupon);
|
||||
if ($coupon->coupon_left < $coupon->coupon_seuil_alert) {
|
||||
array_push($couponSeuil, $coupon);
|
||||
array_push($couponSeuilGlobal, [$site->site_nom, $coupon]);
|
||||
$sendGlobal = true;
|
||||
$couponAlert = true;
|
||||
}
|
||||
|
||||
// --- Check MaxDateDiffusion
|
||||
if ($coupon->coupon_maxdatediffusion != null && strtotime($coupon->coupon_maxdatediffusion) < (time() + (30 * 24 * 60 * 60))) { //Fin de diffusion dans moins de 30jours
|
||||
array_push($couponDiffusion, $coupon);
|
||||
array_push($couponDiffusionGlobal, [$site->site_nom, $coupon]);
|
||||
$sendGlobal = true;
|
||||
$couponAlert = true;
|
||||
}
|
||||
|
||||
if ($couponAlert) {
|
||||
$notifications = Notification::where(['notif_campId' => $campagne->camp_id])->get();
|
||||
foreach ($notifications as $notification) {
|
||||
if (!array_key_exists($notification->notif_id, $users)) {
|
||||
$userObject = [];
|
||||
$userObject['email'] = $notification->notif_email;
|
||||
$userObject['name'] = $notification->notif_name;
|
||||
$users[$notification->notif_id] = (object)$userObject;
|
||||
}
|
||||
}
|
||||
$sendMail = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($sendMail) {
|
||||
Mail::to($users)->send(new AlertBr($couponSeuil, $couponDiffusion, $site->site_nom));
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($sendGlobal) {
|
||||
$this->line("Envoi mail superadmin");
|
||||
$superadmins = array();
|
||||
$admins = User::where(['roles' => 'superadmin'])->get();
|
||||
foreach ($admins as $admin) {
|
||||
$adminObject = [];
|
||||
$adminObject['email'] = $admin->email;
|
||||
$adminObject['name'] = $admin->name;
|
||||
array_push($superadmins, (object)$adminObject);
|
||||
}
|
||||
Mail::to($superadmins)->send(new AlertBrAdmin($couponSeuilGlobal, $couponDiffusionGlobal));
|
||||
}
|
||||
|
||||
$this->line("");
|
||||
$this->info('Fin du traitement');
|
||||
}
|
||||
}
|
||||
BIN
vendor.zip
Normal file
BIN
vendor.zip
Normal file
Binary file not shown.
Loading…
Add table
Reference in a new issue