89 lines
2.4 KiB
PHP
89 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\Contact;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Console\Command;
|
|
|
|
class CustomersClaims extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'customers:claims';
|
|
|
|
/**
|
|
* 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()
|
|
{
|
|
$siteId = 'LGL89';
|
|
$claims = [
|
|
'natacha.larche@orange.fr' => '01/10/2025',
|
|
'delphine.byon@hotmail.fr' => '30/09/2025',
|
|
'aurel_del@hotmail.fr' => '27/09/2025',
|
|
'katy.lancelot@orange.fr' => '26/09/2025'
|
|
];
|
|
|
|
$emails = array_keys($claims);
|
|
|
|
// On récupère les contact dont l'identifiant est un ID de CRM
|
|
$contacts = Contact::whereIn('contact_email', $emails)
|
|
->where('contact_siteId', '=', $siteId)
|
|
->get();
|
|
|
|
$toAdd = [];
|
|
|
|
// Pour chaque contact
|
|
foreach ($contacts as $contact) {
|
|
|
|
$claimDate = Carbon::createFromFormat('d/m/Y', $claims[$contact->contact_email])->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) {
|
|
$contactEmail = $contact->contact_email;
|
|
$campId = $panier->panier_campId;
|
|
$couponId = $content->panier_content_couponId;
|
|
|
|
if (!isset($toAdd[$contactEmail][$campId])) {
|
|
$toAdd[$contactEmail][$campId] = [];
|
|
}
|
|
if (!isset($toAdd[$contactEmail][$campId][$couponId])) {
|
|
$toAdd[$contactEmail][$campId][$couponId] = 0;
|
|
}
|
|
|
|
$toAdd[$contactEmail][$campId][$couponId] += $content->panier_content_printed;
|
|
}
|
|
}
|
|
}
|
|
|
|
dd($toAdd);
|
|
|
|
return 0;
|
|
}
|
|
}
|