فهرست منبع

feat: :sparkles: feat (modulo-de-notificação) Finalizando os ajustes da logica para envio da notificação

Esta sendo finalizado as informações dos modulos de envio de notificação

fase:dev | origin:escopo
kayo henrique 2 هفته پیش
والد
کامیت
39927e74ed
3فایلهای تغییر یافته به همراه165 افزوده شده و 18 حذف شده
  1. 16 9
      app/Enums/NotificationTypeEnum.php
  2. 1 1
      app/Services/NotificationService.php
  3. 148 8
      app/Services/ScheduleService.php

+ 16 - 9
app/Enums/NotificationTypeEnum.php

@@ -4,19 +4,26 @@ namespace App\Enums;
 
 enum NotificationTypeEnum: string
 {
-    case SCHEDULE_CREATED = 'schedule_created';
 
-    case SCHEDULE_ACCEPTED = 'schedule_accepted';
+    // Notificação cliente
+    case SCHEDULE_CLIENT_PROVIDER_ACCEPTED = 'schedule_client_provider_accepted';
 
-    case SCHEDULE_REFUSED = 'schedule_refused';
+    case SCHEDULE_CLIENT_PROVIDER_REFUSED = 'schedule_client_provider_refused';
 
-    case SCHEDULE_STARTED = 'schedule_started';
+    case SCHEDULE_CLIENT_PROVIDER_CANCELLED = 'schedule_client_provider_cancelled';
 
-    case SCHEDULE_FINISHED = 'schedule_finished';
+    case SCHEDULE_CLIENT_PROVIDER_COMING = 'schedule_client_provider_coming';
 
-    case PAYMENT_APPROVED = 'payment_approved';
+    case SCHEDULE_CLIENT_PROVIDER_FINISHED = 'schedule_client_provider_finished';
 
-    case PAYMENT_REFUSED = 'payment_refused';
 
-    case REVIEW_RECEIVED = 'review_received';
-}
+
+        // Notificação PRESTADO
+    case SCHEDULE_PROVIDER_CLIENT_NEW_SOLICITATION = 'schedule_provider_client_new_solicitation';
+
+    case SCHEDULE_PROVIDER_START = 'schedule_provider_start';
+
+    case SCHEDULE_PROVIDER_CLIENT_CANCELLED = 'schedule_provider_client_cancelled';
+
+    case SCHEDULE_PROVIDER_CLIENT_PROPOSAL_ACCEPTED = 'schedule_provider_client_proposal_accepted';
+}

+ 1 - 1
app/Services/NotificationService.php

@@ -56,4 +56,4 @@ class NotificationService
     {
         $notification->delete();
     }
-}
+}

+ 148 - 8
app/Services/ScheduleService.php

@@ -264,44 +264,184 @@ class ScheduleService
 
             $schedule->update(['status' => $status]);
 
+            $schedule->update(['status' => $status]);
+
             switch ($status) {
+
                 case 'pending':
+
                     break;
+
                 case 'accepted':
 
                     $notificationService = app(NotificationService::class);
 
+                    // CLIENTE
                     $notificationService->create([
-                        'title' => 'Agendamento aceito',
+                        'title' => 'Agendamento aceito!',
 
-                        'description' => 'Seu agendamento foi aceito pelo prestador.',
+                        'description' =>
+                        $schedule->provider->user->name .
+                            ' aceitou sua solicitação de diária.',
 
                         'origin' => 'schedule',
 
                         'origin_id' => $schedule->id,
 
-                        'type' => NotificationTypeEnum::SCHEDULE_ACCEPTED->value,
+                        'type' => NotificationTypeEnum::SCHEDULE_CLIENT_PROVIDER_ACCEPTED->value,
 
                         'user_id' => $schedule->client->user_id,
                     ]);
 
                     break;
+
                 case 'rejected':
+
+                    $notificationService = app(NotificationService::class);
+
+                    // CLIENTE
+                    $notificationService->create([
+                        'title' => 'Agendamento recusado!',
+
+                        'description' =>
+                        'O diarista não poderá atender. Veja outros profissionais disponíveis.',
+
+                        'origin' => 'schedule',
+
+                        'origin_id' => $schedule->id,
+
+                        'type' => NotificationTypeEnum::SCHEDULE_CLIENT_PROVIDER_REFUSED->value,
+
+                        'user_id' => $schedule->client->user_id,
+                    ]);
+
                     break;
+
                 case 'paid':
-                    $date_cleaned       = Carbon::parse($schedule->date)->format('Y-m-d');
-                    $date_time_dispatch = Carbon::parse($date_cleaned . ' ' . $schedule->start_time);
 
-                    // StartScheduleJob::dispatch($schedule->id)->delay($date_time_dispatch);
+                    $notificationService = app(NotificationService::class);
+
+                    // PRESTADOR
+                    if ($schedule->provider_id) {
+
+                        $notificationService->create([
+                            'title' => 'Pagamento confirmado!',
+
+                            'description' =>
+                            'O cliente confirmou o pagamento da diária.',
+
+                            'origin' => 'schedule',
+
+                            'origin_id' => $schedule->id,
+
+                            'type' => NotificationTypeEnum::SCHEDULE_PROVIDER_START->value,
+
+                            'user_id' => $schedule->provider->user_id,
+                        ]);
+                    }
+
+                    $date_cleaned = Carbon::parse($schedule->date)
+                        ->format('Y-m-d');
+
+                    $date_time_dispatch = Carbon::parse(
+                        $date_cleaned . ' ' . $schedule->start_time
+                    )->subHour();
+
+                    StartScheduleJob::dispatch($schedule->id)
+                        ->delay($date_time_dispatch);
 
-                    // dispatch de teste em local
-                    StartScheduleJob::dispatch($schedule->id)->delay(now()->addSeconds(15));
                     break;
+
                 case 'cancelled':
+
+                    $notificationService = app(NotificationService::class);
+
+
+                    if ($schedule->cancelled_by === 'client') {
+
+                        if ($schedule->provider_id) {
+
+                            $notificationService->create([
+                                'title' => 'Agendamento cancelado!',
+
+                                'description' =>
+                                'O cliente cancelou o agendamento.',
+
+                                'origin' => 'schedule',
+
+                                'origin_id' => $schedule->id,
+
+                                'type' => NotificationTypeEnum::SCHEDULE_PROVIDER_CLIENT_CANCELLED->value,
+
+                                'user_id' => $schedule->provider->user_id,
+                            ]);
+                        }
+                    } else {
+
+                        $notificationService->create([
+                            'title' => 'Agendamento cancelado!',
+
+                            'description' =>
+                            'Infelizmente ' .
+                                $schedule->provider->user->name .
+                                ' cancelou o agendamento. O valor pago será extornado em breve.',
+
+                            'origin' => 'schedule',
+
+                            'origin_id' => $schedule->id,
+
+                            'type' => NotificationTypeEnum::SCHEDULE_CLIENT_PROVIDER_CANCELLED->value,
+
+                            'user_id' => $schedule->client->user_id,
+                        ]);
+                    }
+
                     break;
+
                 case 'started':
+
+                    $notificationService = app(NotificationService::class);
+
+                    // CLIENTE
+                    $notificationService->create([
+                        'title' => 'Diarista a caminho!',
+
+                        'description' =>
+                        'Informe o código ' .
+                            $schedule->code .
+                            ' para confirmar a chegada da diarista e liberar o início do serviço.',
+
+                        'origin' => 'schedule',
+
+                        'origin_id' => $schedule->id,
+
+                        'type' => NotificationTypeEnum::SCHEDULE_CLIENT_PROVIDER_COMING->value,
+
+                        'user_id' => $schedule->client->user_id,
+                    ]);
+
                     break;
+
                 case 'finished':
+
+                    $notificationService = app(NotificationService::class);
+
+                    // CLIENTE
+                    $notificationService->create([
+                        'title' => 'Diária finalizada!',
+
+                        'description' =>
+                        'Avalie o serviço feito pelo diarista e conte-nos como foi sua experiência.',
+
+                        'origin' => 'schedule',
+
+                        'origin_id' => $schedule->id,
+
+                        'type' => NotificationTypeEnum::SCHEDULE_CLIENT_PROVIDER_FINISHED->value,
+
+                        'user_id' => $schedule->client->user_id,
+                    ]);
+
                     break;
             }