2021-08-23 21:56:12 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Jobs;
|
|
|
|
|
|
|
|
|
|
use App\Models\Customer;
|
|
|
|
|
use App\Models\CustomerLogin;
|
|
|
|
|
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\Carbon;
|
|
|
|
|
|
2021-12-19 15:57:24 +01:00
|
|
|
/**
|
|
|
|
|
* @codeCoverageIgnore
|
|
|
|
|
*/
|
2021-08-23 21:56:12 +02:00
|
|
|
class UpdateCustomerLastConnection implements ShouldQueue
|
|
|
|
|
{
|
|
|
|
|
use Dispatchable;
|
|
|
|
|
use InteractsWithQueue;
|
|
|
|
|
use Queueable;
|
|
|
|
|
use SerializesModels;
|
|
|
|
|
|
|
|
|
|
/** @var \Illuminate\Support\Carbon */
|
|
|
|
|
protected $date = null;
|
|
|
|
|
|
|
|
|
|
/** @var \App\Models\Customer */
|
|
|
|
|
protected $customer = null;
|
|
|
|
|
|
|
|
|
|
/** @var \App\Models\CustomerLogin */
|
|
|
|
|
protected $customerLogin = null;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new job instance.
|
|
|
|
|
*
|
2021-12-19 15:57:24 +01:00
|
|
|
* @param Customer $customer
|
|
|
|
|
* @param CustomerLogin $customerLogin
|
|
|
|
|
* @param Carbon $date
|
2021-08-23 21:56:12 +02:00
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(
|
|
|
|
|
Customer $customer,
|
|
|
|
|
CustomerLogin $customerLogin,
|
|
|
|
|
Carbon $date
|
|
|
|
|
) {
|
|
|
|
|
$this->date = $date;
|
|
|
|
|
$this->customer = $customer;
|
|
|
|
|
$this->customerLogin = $customerLogin;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Execute the job.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function handle()
|
|
|
|
|
{
|
|
|
|
|
if ($this->customerLogin->last_connection < $this->date) {
|
|
|
|
|
$this->customerLogin->last_connection = $this->date;
|
|
|
|
|
$this->customer->logins()->save($this->customerLogin);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|