Просмотр исходного кода

Merge remote-tracking branch 'origin/development' into fix/diaria-kay-ajustes-no-agendamento

Gustavo Zanatta 7 часов назад
Родитель
Сommit
2847703f79
3 измененных файлов с 30 добавлено и 22 удалено
  1. 16 0
      app/Models/Schedule.php
  2. 2 0
      app/Services/CustomScheduleService.php
  3. 12 22
      app/Services/DashboardService.php

+ 16 - 0
app/Models/Schedule.php

@@ -5,6 +5,7 @@ namespace App\Models;
 use Illuminate\Database\Eloquent\Factories\HasFactory;
 use Illuminate\Database\Eloquent\Factories\HasFactory;
 use Illuminate\Database\Eloquent\Model;
 use Illuminate\Database\Eloquent\Model;
 use Illuminate\Database\Eloquent\SoftDeletes;
 use Illuminate\Database\Eloquent\SoftDeletes;
+use Illuminate\Support\Collection;
 
 
 /**
 /**
  * @property int $id
  * @property int $id
@@ -137,6 +138,21 @@ class Schedule extends Model
         return $this->hasMany(Review::class);
         return $this->hasMany(Review::class);
     }
     }
 
 
+    public function getSpecialitiesAttribute(): Collection
+    {
+        if ($this->schedule_type !== 'custom') {
+            return collect();
+        }
+
+        return $this->customSchedule?->specialities
+            ->sortBy('description')
+            ->map(fn(CustomScheduleSpeciality $speciality) => [
+                'id'          => $speciality->id,
+                'description' => $speciality->description,
+            ])
+            ->values() ?? collect();
+    }
+
     //
     //
 
 
     public function ensureCustomerPhone(?string $fallbackPhone = null): void
     public function ensureCustomerPhone(?string $fallbackPhone = null): void

+ 2 - 0
app/Services/CustomScheduleService.php

@@ -488,6 +488,8 @@ class CustomScheduleService
 
 
             $schedule->load(['provider.user', 'client.user']);
             $schedule->load(['provider.user', 'client.user']);
 
 
+            $notificationService = app(NotificationService::class);
+
             $notificationService->create([
             $notificationService->create([
                 'title'       => __('notifications.proposal_accepted_title'),
                 'title'       => __('notifications.proposal_accepted_title'),
                 'description' => __('notifications.proposal_accepted_description'),
                 'description' => __('notifications.proposal_accepted_description'),

+ 12 - 22
app/Services/DashboardService.php

@@ -11,12 +11,10 @@ use App\Models\ClientFavoriteProvider;
 use App\Models\ClientPaymentMethod;
 use App\Models\ClientPaymentMethod;
 use App\Models\Notification;
 use App\Models\Notification;
 use App\Models\Provider;
 use App\Models\Provider;
-use App\Models\ProviderSpeciality;
 use App\Models\Review;
 use App\Models\Review;
 use App\Models\Schedule;
 use App\Models\Schedule;
 use App\Models\ScheduleProposal;
 use App\Models\ScheduleProposal;
 use App\Models\ServicePackage;
 use App\Models\ServicePackage;
-use App\Models\Speciality;
 use App\Rules\ScheduleBusinessRules;
 use App\Rules\ScheduleBusinessRules;
 use Illuminate\Auth\Access\AuthorizationException;
 use Illuminate\Auth\Access\AuthorizationException;
 use Illuminate\Support\Collection;
 use Illuminate\Support\Collection;
@@ -671,6 +669,7 @@ class DashboardService
 
 
         $solicitations = Schedule::with([
         $solicitations = Schedule::with([
             'address:district,source_id,source,id,zip_code,latitude,longitude',
             'address:district,source_id,source,id,zip_code,latitude,longitude',
+            'customSchedule.specialities',
         ])
         ])
             ->where('schedules.provider_id', $provider->id)
             ->where('schedules.provider_id', $provider->id)
             ->where('schedules.status', 'pending')
             ->where('schedules.status', 'pending')
@@ -728,9 +727,11 @@ class DashboardService
                     LIMIT 1
                     LIMIT 1
                 ) AS service_package_id
                 ) AS service_package_id
             "),
             "),
-            )
-            ->orderBy('schedules.date', 'asc')
-            ->get();
+        )
+        ->orderBy('schedules.date', 'asc')
+        ->get()
+        ->append('specialities')
+        ->makeHidden('customSchedule');
 
 
         $solicitations->each(function ($solicitation) use ($address) {
         $solicitations->each(function ($solicitation) use ($address) {
             $solicitation->distance_km = $this->zipCodeCoordinatesService->calculateDistance(
             $solicitation->distance_km = $this->zipCodeCoordinatesService->calculateDistance(
@@ -895,13 +896,16 @@ class DashboardService
 
 
         $cliente = Client::where('user_id', $user->id)->firstOrFail();
         $cliente = Client::where('user_id', $user->id)->firstOrFail();
 
 
-        $schedule = Schedule::where('schedules.id', $scheduleId)
+        $schedule = Schedule::with('customSchedule.specialities')
+            ->where('schedules.id', $scheduleId)
             ->where('schedules.client_id', $cliente->id)
             ->where('schedules.client_id', $cliente->id)
             ->leftJoin('providers', 'providers.id', '=', 'schedules.provider_id')
             ->leftJoin('providers', 'providers.id', '=', 'schedules.provider_id')
             ->leftJoin('users as provider_user', 'provider_user.id', '=', 'providers.user_id')
             ->leftJoin('users as provider_user', 'provider_user.id', '=', 'providers.user_id')
             ->leftJoin('custom_schedules', 'custom_schedules.schedule_id', '=', 'schedules.id')
             ->leftJoin('custom_schedules', 'custom_schedules.schedule_id', '=', 'schedules.id')
             ->select(
             ->select(
+                'schedules.id',
                 'schedules.provider_id',
                 'schedules.provider_id',
+                'schedules.schedule_type',
                 'provider_user.name as provider_name',
                 'provider_user.name as provider_name',
                 'providers.birth_date as provider_birth_date',
                 'providers.birth_date as provider_birth_date',
                 'providers.gender',
                 'providers.gender',
@@ -912,28 +916,14 @@ class DashboardService
         $providerPhoto = $this->providerPhotoUrls([$schedule->provider_id])
         $providerPhoto = $this->providerPhotoUrls([$schedule->provider_id])
             ->get($schedule->provider_id);
             ->get($schedule->provider_id);
 
 
-        $allSpecialities = Speciality::where('active', true)
-            ->select('id', 'description')
-            ->orderBy('description')
-            ->get();
-
-        $providerSpecialityIds = ProviderSpeciality::where('provider_id', $schedule->provider_id)
-            ->pluck('speciality_id')
-            ->all();
-
-        $specialities = $allSpecialities->map(fn($sp) => [
-            'id'             => $sp->id,
-            'description'    => $sp->description,
-            'has_speciality' => in_array($sp->id, $providerSpecialityIds),
-        ])->values();
-
         return [
         return [
+            'schedule_type'       => $schedule->schedule_type,
             'provider_name'       => $schedule->provider_name,
             'provider_name'       => $schedule->provider_name,
             'provider_birth_date' => $schedule->provider_birth_date,
             'provider_birth_date' => $schedule->provider_birth_date,
             'gender'              => $schedule->gender,
             'gender'              => $schedule->gender,
             'gender_label'        => GenderEnum::labelFor($schedule->gender),
             'gender_label'        => GenderEnum::labelFor($schedule->gender),
             'offers_meal'         => $schedule->offers_meal,
             'offers_meal'         => $schedule->offers_meal,
-            'specialities'        => $specialities,
+            'specialities'        => $schedule->specialities,
 
 
             'provider_photo' => $providerPhoto,
             'provider_photo' => $providerPhoto,
         ];
         ];