49 lines
1.3 KiB
PHP
49 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs\Drip;
|
|
|
|
use App\Enums\DripEmailType;
|
|
use App\Mail\Drip\AiConsentFollowUpEmail;
|
|
use App\Models\User;
|
|
use App\Models\UserMailLog;
|
|
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\Mail;
|
|
|
|
class SendAiConsentFollowUpEmailJob implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
public function __construct(public User $user)
|
|
{
|
|
$this->onQueue('emails');
|
|
}
|
|
|
|
public function handle(): void
|
|
{
|
|
if (! $this->user->canReceiveEmails()) {
|
|
return;
|
|
}
|
|
|
|
if ($this->user->hasReceivedEmail(DripEmailType::AiConsentFollowUp)) {
|
|
return;
|
|
}
|
|
|
|
if (! $this->user->aiConsents()->active()->exists()) {
|
|
return;
|
|
}
|
|
|
|
Mail::to($this->user)->send(new AiConsentFollowUpEmail($this->user));
|
|
|
|
UserMailLog::create([
|
|
'user_id' => $this->user->id,
|
|
'email_type' => DripEmailType::AiConsentFollowUp,
|
|
'email_identifier' => DripEmailType::AiConsentFollowUp->value,
|
|
'sent_at' => now(),
|
|
]);
|
|
}
|
|
}
|