Merge branch 'fixJobDeleteCustomers' into 'develop'
Fix Job delete unconfirmed users See merge request service-web-lab/crm!1
This commit is contained in:
commit
ed1aa3fda5
1 changed files with 11 additions and 8 deletions
|
|
@ -2,12 +2,13 @@
|
|||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\CustomerInfo;
|
||||
use App\Models\Customer;
|
||||
use App\Models\CustomerLogin;
|
||||
use App\Models\CustomerOptInHistory;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
|
|
@ -37,20 +38,22 @@ class DeleteUnconfirmedCustomers extends Command
|
|||
public function handle()
|
||||
{
|
||||
/** @var \Illuminate\Database\Eloquent\Collection $customersLogins */
|
||||
$customersLogins = CustomerLogin::whereStatus(false)->where('created_at', '<', Carbon::now()->subDay(1))->get();
|
||||
$customersLogins = CustomerLogin::whereStatus(false)
|
||||
->where('created_at', '<', Carbon::now()->subDay(1))
|
||||
->with(['brand', 'customer'])
|
||||
->get();
|
||||
$customersLogins->map(function (CustomerLogin $customerLogin) {
|
||||
Log::info($customerLogin->customer_id);
|
||||
DB::transaction(function () use ($customerLogin) {
|
||||
/** @var \App\Models\Customer $customer */
|
||||
$customer = $customerLogin->customer;
|
||||
|
||||
// * Si non activé et créer il y a plus d'un jour : Suppression.
|
||||
$customerLogin->customer->infos()->where('brand_id', $customerLogin->brand_id)
|
||||
->get()->map(function (CustomerInfo $customerInfo) {
|
||||
$customerInfo->deleteOrFail();
|
||||
});
|
||||
/** @var \App\Models\Brand */
|
||||
$brand = $customerLogin->brand;
|
||||
|
||||
// * Suppression de ses infos de login pour la marque.
|
||||
$customerLogin->deleteOrFail();
|
||||
$customer->info($brand, Customer::FIRST_OR_FAIL)->deleteOrFail();
|
||||
$customer->login($brand, Customer::FIRST_OR_FAIL)->deleteOrFail();
|
||||
|
||||
// * Si le customer n'a plus d'info il n'a donc plus besoin de compte en crm.
|
||||
if (!$customer->infos()->count()) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue