|
|
@@ -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;
|
|
|
}
|
|
|
|