2021-11-26 07:28:58 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Listeners;
|
|
|
|
|
|
|
|
use App\Events\ExampleEvent;
|
|
|
|
use App\Events\InsuranceEvent;
|
|
|
|
use App\Events\InsuredConsultation;
|
|
|
|
use App\Traits\Helper;
|
|
|
|
use GuzzleHttp\Client;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
use stdClass;
|
|
|
|
use Throwable;
|
|
|
|
|
|
|
|
class InsuredConsultationNotification
|
|
|
|
{
|
|
|
|
use Helper;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create the event listener.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the event.
|
|
|
|
*
|
|
|
|
* @param InsuredConsultation $event
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function handle(InsuredConsultation $event)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
try {
|
|
|
|
$client = new Client([
|
|
|
|
'base_uri' => config('services.notification_service.base_uri'),
|
|
|
|
]);
|
|
|
|
$headers = [
|
|
|
|
'Authorization' => config('services.notification_service.key'),
|
|
|
|
];
|
|
|
|
$body = new stdClass();
|
|
|
|
$body->title = $event->mailTitle;
|
|
|
|
$body->message = $event->mailMessage;
|
|
|
|
$body->email = $event->healthCareSheet->user->email;
|
|
|
|
|
|
|
|
$client->request('POST', '/send-mail', ['json' => $body, 'headers' => $headers]);
|
|
|
|
|
|
|
|
if (isset($event->notification)) {
|
|
|
|
$body = new stdClass();
|
|
|
|
$body->user_code = $event->healthCareSheet->user->user_code;
|
|
|
|
$body->message = $event->notification;
|
|
|
|
$body->date = $event->healthCareSheet->created_at->format('Y-m-d H:i:s') ?? date('Y-m-d H:i:s');
|
|
|
|
|
|
|
|
$data = new stdClass();
|
2021-12-07 08:29:00 +00:00
|
|
|
$data->screen = "validateConsultationDetailScreen";
|
2021-11-26 07:28:58 +00:00
|
|
|
$data->data = new stdClass();
|
2021-12-07 08:29:00 +00:00
|
|
|
$data->data->id = $event->healthCareSheet->id;
|
2021-11-26 07:28:58 +00:00
|
|
|
$body->data = $data;
|
2022-01-26 13:48:04 +00:00
|
|
|
$data->not_saved = true; // Notification non sauvegardé
|
2021-11-26 07:28:58 +00:00
|
|
|
|
|
|
|
$client->request('POST', '/onesignal/pushToUser', ['json' => $body, 'headers' => $headers]);
|
|
|
|
}
|
|
|
|
} catch (Throwable $t) {
|
|
|
|
Log::error('-------- Insured Consultation notification not sent-----------');
|
|
|
|
Log::error($t->getMessage() . '\n' . $t->getTraceAsString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|