|
|
@@ -8,6 +8,7 @@ use App\Models\Schedule;
|
|
|
use App\Rules\ScheduleBusinessRules;
|
|
|
use App\Services\NotificationService;
|
|
|
use App\Enums\NotificationTypeEnum;
|
|
|
+use App\Enums\UserTypeEnum;
|
|
|
use Carbon\Carbon;
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
@@ -275,7 +276,7 @@ class ScheduleService
|
|
|
{
|
|
|
try {
|
|
|
DB::beginTransaction();
|
|
|
- $schedule = Schedule::with(['provider.user','client.user','address'])->findOrFail($id);
|
|
|
+ $schedule = Schedule::with(['provider.user', 'client.user', 'address'])->findOrFail($id);
|
|
|
|
|
|
$allowedTransitions = [
|
|
|
'pending' => ['accepted', 'rejected', 'cancelled'],
|
|
|
@@ -300,7 +301,8 @@ class ScheduleService
|
|
|
$schedule->update(['status' => $status]);
|
|
|
$schedule->refresh();
|
|
|
|
|
|
-
|
|
|
+ $currentStatus = $schedule->status;
|
|
|
+
|
|
|
switch ($status) {
|
|
|
|
|
|
case 'pending':
|
|
|
@@ -312,7 +314,7 @@ class ScheduleService
|
|
|
|
|
|
switch (Auth::user()->type) {
|
|
|
|
|
|
- case 'provider':
|
|
|
+ case UserTypeEnum::PROVIDER:
|
|
|
|
|
|
$notificationService->create([
|
|
|
'title' => 'Agendamento aceito!',
|
|
|
@@ -333,7 +335,7 @@ class ScheduleService
|
|
|
|
|
|
break;
|
|
|
|
|
|
- case 'client':
|
|
|
+ case UserTypeEnum::CLIENT:
|
|
|
|
|
|
if ($schedule->provider_id) {
|
|
|
|
|
|
@@ -362,144 +364,40 @@ class ScheduleService
|
|
|
|
|
|
break;
|
|
|
|
|
|
- case 'rejected':
|
|
|
+ case 'cancelled':
|
|
|
|
|
|
$notificationService = app(NotificationService::class);
|
|
|
|
|
|
switch (Auth::user()->type) {
|
|
|
|
|
|
-
|
|
|
- case 'provider':
|
|
|
+ case UserTypeEnum::CLIENT:
|
|
|
|
|
|
$notificationService->create([
|
|
|
- 'title' => 'Agendamento recusado!',
|
|
|
+ 'title' => 'Agendamento cancelado!',
|
|
|
|
|
|
'description' =>
|
|
|
- 'O diarista não poderá atender. Veja outros profissionais disponíveis.',
|
|
|
+ 'O cliente cancelou o agendamento.',
|
|
|
|
|
|
'origin' => 'schedule',
|
|
|
|
|
|
'origin_id' => $schedule->id,
|
|
|
|
|
|
'type' =>
|
|
|
- NotificationTypeEnum::SCHEDULE_CLIENT_PROVIDER_REFUSED->value,
|
|
|
+ NotificationTypeEnum::SCHEDULE_PROVIDER_CLIENT_CANCELLED->value,
|
|
|
|
|
|
- 'user_id' => $schedule->client->user_id,
|
|
|
+ 'user_id' => $schedule->provider->user_id,
|
|
|
]);
|
|
|
|
|
|
break;
|
|
|
|
|
|
- case 'client':
|
|
|
-
|
|
|
- if ($schedule->provider_id) {
|
|
|
-
|
|
|
- $notificationService->create([
|
|
|
- 'title' => 'Proposta recusada!',
|
|
|
-
|
|
|
- 'description' =>
|
|
|
- 'O cliente recusou sua proposta de diária.',
|
|
|
-
|
|
|
- 'origin' => 'schedule',
|
|
|
-
|
|
|
- 'origin_id' => $schedule->id,
|
|
|
-
|
|
|
- 'type' =>
|
|
|
- NotificationTypeEnum::SCHEDULE_PROVIDER_CLIENT_CANCELLED->value,
|
|
|
-
|
|
|
- 'user_id' => $schedule->provider->user_id,
|
|
|
- ]);
|
|
|
- }
|
|
|
-
|
|
|
- break;
|
|
|
-
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- break;
|
|
|
-
|
|
|
- case 'paid':
|
|
|
-
|
|
|
- $notificationService = app(NotificationService::class);
|
|
|
-
|
|
|
- switch (Auth::user()->type) {
|
|
|
-
|
|
|
- case 'client':
|
|
|
-
|
|
|
- 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,
|
|
|
- ]);
|
|
|
- }
|
|
|
-
|
|
|
- break;
|
|
|
-
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- $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);
|
|
|
-
|
|
|
- break;
|
|
|
-
|
|
|
- case 'cancelled':
|
|
|
-
|
|
|
- $notificationService = app(NotificationService::class);
|
|
|
-
|
|
|
- switch (Auth::user()->type) {
|
|
|
-
|
|
|
- case 'client':
|
|
|
-
|
|
|
- if ($schedule->provider_id) {
|
|
|
-
|
|
|
- $notificationService->create([
|
|
|
- 'title' => 'Agendamento cancelado!',
|
|
|
-
|
|
|
- 'description' =>
|
|
|
- 'O cliente cancelou a diária.',
|
|
|
-
|
|
|
- 'origin' => 'schedule',
|
|
|
-
|
|
|
- 'origin_id' => $schedule->id,
|
|
|
-
|
|
|
- 'type' =>
|
|
|
- NotificationTypeEnum::SCHEDULE_PROVIDER_CLIENT_CANCELLED->value,
|
|
|
-
|
|
|
- 'user_id' => $schedule->provider->user_id,
|
|
|
- ]);
|
|
|
- }
|
|
|
-
|
|
|
- break;
|
|
|
-
|
|
|
- case 'provider':
|
|
|
+ case UserTypeEnum::PROVIDER:
|
|
|
|
|
|
$notificationService->create([
|
|
|
'title' => 'Agendamento cancelado!',
|
|
|
|
|
|
'description' =>
|
|
|
$schedule->provider->user->name .
|
|
|
- ' cancelou a diária.',
|
|
|
+ ' cancelou sua solicitação de diária.',
|
|
|
|
|
|
'origin' => 'schedule',
|
|
|
|
|
|
@@ -523,13 +421,12 @@ class ScheduleService
|
|
|
|
|
|
$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.',
|
|
|
+ 'Informe o código ' . $schedule->code . ' para liberar o início do serviço.',
|
|
|
|
|
|
'origin' => 'schedule',
|
|
|
|
|
|
@@ -541,12 +438,12 @@ class ScheduleService
|
|
|
'user_id' => $schedule->client->user_id,
|
|
|
]);
|
|
|
|
|
|
-
|
|
|
+ // PRESTADOR
|
|
|
$notificationService->create([
|
|
|
- 'title' => 'Você iniciou o deslocamento!',
|
|
|
+ 'title' => 'Início do serviço!',
|
|
|
|
|
|
'description' =>
|
|
|
- 'O cliente foi avisado que você está a caminho.',
|
|
|
+ 'Solicite o código ao cliente para iniciar a diária.',
|
|
|
|
|
|
'origin' => 'schedule',
|
|
|
|
|
|
@@ -564,11 +461,12 @@ class ScheduleService
|
|
|
|
|
|
$notificationService = app(NotificationService::class);
|
|
|
|
|
|
+ // CLIENTE
|
|
|
$notificationService->create([
|
|
|
- 'title' => 'Diária finalizada!',
|
|
|
+ 'title' => 'Serviço finalizado!',
|
|
|
|
|
|
'description' =>
|
|
|
- 'Avalie o serviço feito pelo diarista e conte-nos como foi sua experiência.',
|
|
|
+ 'Sua diária foi finalizada com sucesso.',
|
|
|
|
|
|
'origin' => 'schedule',
|
|
|
|
|
|
@@ -580,26 +478,80 @@ class ScheduleService
|
|
|
'user_id' => $schedule->client->user_id,
|
|
|
]);
|
|
|
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 'paid':
|
|
|
+
|
|
|
+ $notificationService = app(NotificationService::class);
|
|
|
+
|
|
|
+ switch (Auth::user()->type) {
|
|
|
+
|
|
|
+ case UserTypeEnum::CLIENT:
|
|
|
+
|
|
|
+ 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,
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ $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);
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 'rejected':
|
|
|
+
|
|
|
+ $notificationService = app(NotificationService::class);
|
|
|
+
|
|
|
$notificationService->create([
|
|
|
- 'title' => 'Diária concluída!',
|
|
|
+ 'title' => 'Agendamento recusado!',
|
|
|
|
|
|
'description' =>
|
|
|
- 'A diária foi finalizada com sucesso.',
|
|
|
+ 'O diarista não poderá atender. Veja outros profissionais disponíveis.',
|
|
|
|
|
|
'origin' => 'schedule',
|
|
|
|
|
|
'origin_id' => $schedule->id,
|
|
|
|
|
|
'type' =>
|
|
|
- NotificationTypeEnum::SCHEDULE_PROVIDER_START->value,
|
|
|
+ NotificationTypeEnum::SCHEDULE_CLIENT_PROVIDER_REFUSED->value,
|
|
|
|
|
|
- 'user_id' => $schedule->provider->user_id,
|
|
|
+ 'user_id' => $schedule->client->user_id,
|
|
|
]);
|
|
|
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
DB::commit();
|
|
|
|
|
|
return $schedule->fresh(['client.user', 'provider.user', 'address']);
|