79 lines
1.9 KiB
PHP
79 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\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\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'];
|
|
|
|
// For baskets and old walls.
|
|
$contact = Contact::where('contact_ref', $hashchode)->first();
|
|
if ($contact) {
|
|
$contact->murs()->delete();
|
|
$contact->paniers()->delete();
|
|
$contact->logs()->delete();
|
|
$contact->delete();
|
|
|
|
Log::channel('crm')->info(
|
|
sprintf(
|
|
"Hashcode : %s - Email : %s - Contact deleted.",
|
|
$hashchode,
|
|
$email
|
|
)
|
|
);
|
|
}
|
|
|
|
// For walls.
|
|
$customer = Customers::where('hashcode', $hashchode)->first();
|
|
if ($customer) {
|
|
$customer->printedWalls()->delete();
|
|
$customer->delete();
|
|
|
|
Log::channel('crm')->info(
|
|
sprintf(
|
|
"Hashcode : %s - Email : %s - Customer deleted.",
|
|
$hashchode,
|
|
$email
|
|
)
|
|
);
|
|
}
|
|
}
|
|
}
|