|
@@ -14,6 +14,11 @@ use App\Rules\ScheduleBusinessRules;
|
|
|
use App\Services\NotificationService;
|
|
use App\Services\NotificationService;
|
|
|
use App\Services\PushNotificationService;
|
|
use App\Services\PushNotificationService;
|
|
|
use App\Notifications\Push\Cliente\Agendamento\PrestadorAceitouPush;
|
|
use App\Notifications\Push\Cliente\Agendamento\PrestadorAceitouPush;
|
|
|
|
|
+use App\Notifications\Push\Cliente\Agendamento\PrestadorRecusouPush;
|
|
|
|
|
+use App\Notifications\Push\Prestador\Agendamento\ClienteAceitouPush;
|
|
|
|
|
+use App\Notifications\Push\Prestador\Pagamento\ClienteEfetuouPagamentoPush;
|
|
|
|
|
+use App\Notifications\Push\Cliente\Agendamento\PrestadorCancelouPush;
|
|
|
|
|
+use App\Notifications\Push\Prestador\Agendamento\ClienteCancelouPush;
|
|
|
use App\Notifications\Push\Prestador\Agendamento\NewPushRequest;
|
|
use App\Notifications\Push\Prestador\Agendamento\NewPushRequest;
|
|
|
use Carbon\Carbon;
|
|
use Carbon\Carbon;
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Auth;
|
|
@@ -219,6 +224,8 @@ class ScheduleService
|
|
|
]);
|
|
]);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ $this->sendClientAcceptedPush($schedule);
|
|
|
|
|
+
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
default:
|
|
@@ -240,6 +247,7 @@ class ScheduleService
|
|
|
'type' => NotificationTypeEnum::SCHEDULE_PROVIDER_CLIENT_CANCELLED->value,
|
|
'type' => NotificationTypeEnum::SCHEDULE_PROVIDER_CLIENT_CANCELLED->value,
|
|
|
'user_id' => $schedule->provider->user_id,
|
|
'user_id' => $schedule->provider->user_id,
|
|
|
]);
|
|
]);
|
|
|
|
|
+ $this->sendProviderCancelledPush($schedule);
|
|
|
|
|
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
@@ -252,6 +260,7 @@ class ScheduleService
|
|
|
'type' => NotificationTypeEnum::SCHEDULE_CLIENT_PROVIDER_CANCELLED->value,
|
|
'type' => NotificationTypeEnum::SCHEDULE_CLIENT_PROVIDER_CANCELLED->value,
|
|
|
'user_id' => $schedule->client->user_id,
|
|
'user_id' => $schedule->client->user_id,
|
|
|
]);
|
|
]);
|
|
|
|
|
+ $this->sendClientCancelledPush($schedule);
|
|
|
|
|
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
@@ -319,7 +328,7 @@ class ScheduleService
|
|
|
'user_id' => $schedule->provider->user_id,
|
|
'user_id' => $schedule->provider->user_id,
|
|
|
]);
|
|
]);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ $this->sendClientPaymentPush($schedule);
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
default:
|
|
@@ -350,6 +359,8 @@ class ScheduleService
|
|
|
'user_id' => $schedule->client->user_id,
|
|
'user_id' => $schedule->client->user_id,
|
|
|
]);
|
|
]);
|
|
|
|
|
|
|
|
|
|
+ $this->sendProviderRefusedPush($schedule);
|
|
|
|
|
+
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -550,26 +561,28 @@ class ScheduleService
|
|
|
$siblingSchedules = $package->items->pluck('schedule')->filter();
|
|
$siblingSchedules = $package->items->pluck('schedule')->filter();
|
|
|
|
|
|
|
|
$siblingSchedules
|
|
$siblingSchedules
|
|
|
- ->filter(fn (Schedule $sibling) => $sibling->id !== $schedule->id
|
|
|
|
|
|
|
+ ->filter(fn(Schedule $sibling) => $sibling->id !== $schedule->id
|
|
|
&& in_array($sibling->status, ['pending', 'accepted', 'paid'], true))
|
|
&& in_array($sibling->status, ['pending', 'accepted', 'paid'], true))
|
|
|
- ->each(fn (Schedule $sibling) => $sibling->update([
|
|
|
|
|
|
|
+ ->each(fn(Schedule $sibling) => $sibling->update([
|
|
|
'status' => 'cancelled',
|
|
'status' => 'cancelled',
|
|
|
'cancel_text' => $cancelText,
|
|
'cancel_text' => $cancelText,
|
|
|
'cancelled_by' => $cancelledBy,
|
|
'cancelled_by' => $cancelledBy,
|
|
|
]));
|
|
]));
|
|
|
|
|
|
|
|
$hasRealizedSchedule = $siblingSchedules->contains(
|
|
$hasRealizedSchedule = $siblingSchedules->contains(
|
|
|
- fn (Schedule $sibling) => in_array($sibling->status, ['started', 'finished'], true),
|
|
|
|
|
|
|
+ fn(Schedule $sibling) => in_array($sibling->status, ['started', 'finished'], true),
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- if ($package->status === ServicePackageStatusEnum::OPEN
|
|
|
|
|
- || ($package->status === ServicePackageStatusEnum::PAID && ! $hasRealizedSchedule)) {
|
|
|
|
|
|
|
+ if (
|
|
|
|
|
+ $package->status === ServicePackageStatusEnum::OPEN
|
|
|
|
|
+ || ($package->status === ServicePackageStatusEnum::PAID && ! $hasRealizedSchedule)
|
|
|
|
|
+ ) {
|
|
|
$package->update(['status' => ServicePackageStatusEnum::CANCELLED->value]);
|
|
$package->update(['status' => ServicePackageStatusEnum::CANCELLED->value]);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- //
|
|
|
|
|
|
|
+ //Notificações por push do sistema
|
|
|
|
|
|
|
|
private function sendProviderAcceptedPush(Schedule $schedule): void
|
|
private function sendProviderAcceptedPush(Schedule $schedule): void
|
|
|
{
|
|
{
|
|
@@ -597,6 +610,147 @@ class ScheduleService
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private function sendProviderRefusedPush(Schedule $schedule): void
|
|
|
|
|
+ {
|
|
|
|
|
+ $user = $schedule->client->user;
|
|
|
|
|
+
|
|
|
|
|
+ if (! $user) {
|
|
|
|
|
+ Log::warning('Push de recusa ignorada: cliente sem usuário', [
|
|
|
|
|
+ 'schedule_id' => $schedule->id,
|
|
|
|
|
+ ]);
|
|
|
|
|
+
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ app(PushNotificationService::class)->sendToUser(
|
|
|
|
|
+ $user,
|
|
|
|
|
+ new PrestadorRecusouPush(
|
|
|
|
|
+ $schedule->provider->user->name
|
|
|
|
|
+ )
|
|
|
|
|
+ );
|
|
|
|
|
+ } catch (\Throwable $exception) {
|
|
|
|
|
+ Log::error('Falha ao enviar push de recusa do prestador', [
|
|
|
|
|
+ 'schedule_id' => $schedule->id,
|
|
|
|
|
+ 'user_id' => $user->id,
|
|
|
|
|
+ 'error' => $exception->getMessage(),
|
|
|
|
|
+ ]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private function sendClientAcceptedPush(Schedule $schedule): void
|
|
|
|
|
+ {
|
|
|
|
|
+ $user = $schedule->provider?->user;
|
|
|
|
|
+
|
|
|
|
|
+ if (! $user) {
|
|
|
|
|
+ Log::warning('Push de aceite do cliente ignorado: prestador sem usuário', [
|
|
|
|
|
+ 'schedule_id' => $schedule->id,
|
|
|
|
|
+ ]);
|
|
|
|
|
+
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ app(PushNotificationService::class)->sendToUser(
|
|
|
|
|
+ $user,
|
|
|
|
|
+ new ClienteAceitouPush(
|
|
|
|
|
+ $schedule->client->user->name
|
|
|
|
|
+ )
|
|
|
|
|
+ );
|
|
|
|
|
+ } catch (\Throwable $exception) {
|
|
|
|
|
+ Log::error('Falha ao enviar push de aceite do cliente', [
|
|
|
|
|
+ 'schedule_id' => $schedule->id,
|
|
|
|
|
+ 'user_id' => $user->id,
|
|
|
|
|
+ 'error' => $exception->getMessage(),
|
|
|
|
|
+ ]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private function sendClientPaymentPush(Schedule $schedule): void
|
|
|
|
|
+ {
|
|
|
|
|
+ $user = $schedule->provider?->user;
|
|
|
|
|
+
|
|
|
|
|
+ if (! $user) {
|
|
|
|
|
+ Log::warning('Push de pagamento ignorado: prestador sem usuário', [
|
|
|
|
|
+ 'schedule_id' => $schedule->id,
|
|
|
|
|
+ ]);
|
|
|
|
|
+
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ app(PushNotificationService::class)->sendToUser(
|
|
|
|
|
+ $user,
|
|
|
|
|
+ new ClienteEfetuouPagamentoPush(
|
|
|
|
|
+ $schedule->client?->user?->name ?? 'Cliente'
|
|
|
|
|
+ )
|
|
|
|
|
+ );
|
|
|
|
|
+ } catch (\Throwable $exception) {
|
|
|
|
|
+ Log::error('Falha ao enviar push de pagamento ao prestador', [
|
|
|
|
|
+ 'schedule_id' => $schedule->id,
|
|
|
|
|
+ 'provider_id' => $schedule->provider_id,
|
|
|
|
|
+ 'user_id' => $user->id,
|
|
|
|
|
+ 'error' => $exception->getMessage(),
|
|
|
|
|
+ ]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private function sendClientCancelledPush(Schedule $schedule): void
|
|
|
|
|
+ {
|
|
|
|
|
+ $user = $schedule->provider->user;
|
|
|
|
|
+
|
|
|
|
|
+ if (! $user) {
|
|
|
|
|
+ Log::warning('Push de cancelamento ignorado: prestador sem usuário', [
|
|
|
|
|
+ 'schedule_id' => $schedule->id,
|
|
|
|
|
+ ]);
|
|
|
|
|
+
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ app(PushNotificationService::class)->sendToUser(
|
|
|
|
|
+ $user,
|
|
|
|
|
+ new ClienteCancelouPush(
|
|
|
|
|
+ $schedule->client->user->name
|
|
|
|
|
+ )
|
|
|
|
|
+ );
|
|
|
|
|
+ } catch (\Throwable $exception) {
|
|
|
|
|
+ Log::error('Falha ao enviar push de cancelamento pelo cliente', [
|
|
|
|
|
+ 'schedule_id' => $schedule->id,
|
|
|
|
|
+ 'user_id' => $user->id,
|
|
|
|
|
+ 'error' => $exception->getMessage(),
|
|
|
|
|
+ ]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private function sendProviderCancelledPush(Schedule $schedule): void
|
|
|
|
|
+ {
|
|
|
|
|
+ $user = $schedule->client->user;
|
|
|
|
|
+
|
|
|
|
|
+ if (! $user) {
|
|
|
|
|
+ Log::warning('Push de cancelamento ignorado: cliente sem usuário', [
|
|
|
|
|
+ 'schedule_id' => $schedule->id,
|
|
|
|
|
+ ]);
|
|
|
|
|
+
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ app(PushNotificationService::class)->sendToUser(
|
|
|
|
|
+ $user,
|
|
|
|
|
+ new PrestadorCancelouPush(
|
|
|
|
|
+ $schedule->provider->user->name
|
|
|
|
|
+ )
|
|
|
|
|
+ );
|
|
|
|
|
+ } catch (\Throwable $exception) {
|
|
|
|
|
+ Log::error('Falha ao enviar push de cancelamento pelo prestador', [
|
|
|
|
|
+ 'schedule_id' => $schedule->id,
|
|
|
|
|
+ 'user_id' => $user->id,
|
|
|
|
|
+ 'error' => $exception->getMessage(),
|
|
|
|
|
+ ]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private function calculateAmount(Provider $provider, string $periodType): float
|
|
private function calculateAmount(Provider $provider, string $periodType): float
|
|
|
{
|
|
{
|
|
|
$hourlyRates = [
|
|
$hourlyRates = [
|