|
@@ -95,17 +95,22 @@ class DashboardService
|
|
|
|
|
|
|
|
$blockedProviderIds = ScheduleBusinessRules::getBlockedProviderIdsForClient($cliente->id);
|
|
$blockedProviderIds = ScheduleBusinessRules::getBlockedProviderIdsForClient($cliente->id);
|
|
|
$providersWithWorkingDays = ScheduleBusinessRules::getProviderIdsWithWorkingDays();
|
|
$providersWithWorkingDays = ScheduleBusinessRules::getProviderIdsWithWorkingDays();
|
|
|
|
|
+ $clientAddress = Address::where('source', 'client')
|
|
|
|
|
+ ->where('source_id', $cliente->id)
|
|
|
|
|
+ ->orderBy('is_primary', 'desc')
|
|
|
|
|
+ ->first();
|
|
|
|
|
|
|
|
$providersClose = Provider::leftJoin('users as provider_user', 'provider_user.id', '=', 'providers.user_id')
|
|
$providersClose = Provider::leftJoin('users as provider_user', 'provider_user.id', '=', 'providers.user_id')
|
|
|
- ->leftJoin('addresses as provider_address', function ($join) {
|
|
|
|
|
- $join->on('provider_address.source_id', '=', 'providers.id')
|
|
|
|
|
- ->where('provider_address.source', 'provider');
|
|
|
|
|
- })
|
|
|
|
|
- ->leftJoin('addresses as client_address', function ($join) use ($cliente) {
|
|
|
|
|
- $join->where('client_address.source_id', $cliente->id)
|
|
|
|
|
- ->where('client_address.source', 'client');
|
|
|
|
|
- })
|
|
|
|
|
- ->whereColumn('provider_address.city_id', '=', 'client_address.city_id')
|
|
|
|
|
|
|
+ ->leftJoin(DB::raw("
|
|
|
|
|
+ (
|
|
|
|
|
+ SELECT DISTINCT ON (source_id)
|
|
|
|
|
+ *
|
|
|
|
|
+ FROM addresses
|
|
|
|
|
+ WHERE source = 'provider'
|
|
|
|
|
+ ORDER BY source_id, is_primary DESC
|
|
|
|
|
+ ) as provider_address
|
|
|
|
|
+ "), 'provider_address.source_id', '=', 'providers.id')
|
|
|
|
|
+ ->where('provider_address.city_id', '=', $clientAddress->city_id)
|
|
|
->whereNotIn('providers.id', $blockedProviderIds)
|
|
->whereNotIn('providers.id', $blockedProviderIds)
|
|
|
->whereIn('providers.id', $providersWithWorkingDays)
|
|
->whereIn('providers.id', $providersWithWorkingDays)
|
|
|
->where(function ($query) {
|
|
->where(function ($query) {
|
|
@@ -117,7 +122,6 @@ class DashboardService
|
|
|
->select(
|
|
->select(
|
|
|
'providers.id as provider_id',
|
|
'providers.id as provider_id',
|
|
|
'provider_user.name as provider_name',
|
|
'provider_user.name as provider_name',
|
|
|
- 'provider_address.district',
|
|
|
|
|
'providers.average_rating',
|
|
'providers.average_rating',
|
|
|
DB::raw("(
|
|
DB::raw("(
|
|
|
SELECT COUNT(*)
|
|
SELECT COUNT(*)
|
|
@@ -144,6 +148,72 @@ class DashboardService
|
|
|
];
|
|
];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public function buscaPrestadores(?string $name = null, ?string $date = null): array
|
|
|
|
|
+ {
|
|
|
|
|
+ $user = Auth::user();
|
|
|
|
|
+ $cliente = Client::where('user_id', $user->id)->first();
|
|
|
|
|
+
|
|
|
|
|
+ $blockedProviderIds = ScheduleBusinessRules::getBlockedProviderIdsForClient($cliente->id);
|
|
|
|
|
+ $providersWithWorkingDays = ScheduleBusinessRules::getProviderIdsWithWorkingDays();
|
|
|
|
|
+
|
|
|
|
|
+ $clientPrimaryAddress = Address::where('source', 'client')
|
|
|
|
|
+ ->where('source_id', $cliente->id)
|
|
|
|
|
+ ->orderBy('is_primary', 'desc')
|
|
|
|
|
+ ->first();
|
|
|
|
|
+
|
|
|
|
|
+ return Provider::leftJoin('users as provider_user', 'provider_user.id', '=', 'providers.user_id')
|
|
|
|
|
+ ->leftJoin(DB::raw("
|
|
|
|
|
+ (
|
|
|
|
|
+ SELECT DISTINCT ON (source_id)
|
|
|
|
|
+ *
|
|
|
|
|
+ FROM addresses
|
|
|
|
|
+ WHERE source = 'provider'
|
|
|
|
|
+ ORDER BY source_id, is_primary DESC
|
|
|
|
|
+ ) as provider_address
|
|
|
|
|
+ "), 'provider_address.source_id', '=', 'providers.id')
|
|
|
|
|
+ ->whereNotNull('provider_address.id')
|
|
|
|
|
+ ->where('provider_address.city_id', $clientPrimaryAddress?->city_id)
|
|
|
|
|
+ ->whereNotIn('providers.id', $blockedProviderIds)
|
|
|
|
|
+ ->whereIn('providers.id', $providersWithWorkingDays)
|
|
|
|
|
+ ->whereNotNull('providers.daily_price_8h')
|
|
|
|
|
+ ->whereNotNull('providers.daily_price_6h')
|
|
|
|
|
+ ->whereNotNull('providers.daily_price_4h')
|
|
|
|
|
+ ->whereNotNull('providers.daily_price_2h')
|
|
|
|
|
+ ->when($name, fn($q) => $q->where('provider_user.name', 'ILIKE', "%{$name}%"))
|
|
|
|
|
+ ->select(
|
|
|
|
|
+ 'providers.id as provider_id',
|
|
|
|
|
+ 'provider_user.name as provider_name',
|
|
|
|
|
+ 'provider_address.district',
|
|
|
|
|
+ 'providers.average_rating',
|
|
|
|
|
+ 'providers.total_services',
|
|
|
|
|
+ 'providers.daily_price_8h',
|
|
|
|
|
+ 'providers.daily_price_6h',
|
|
|
|
|
+ 'providers.daily_price_4h',
|
|
|
|
|
+ 'providers.daily_price_2h',
|
|
|
|
|
+ 'providers.created_at',
|
|
|
|
|
+ DB::raw("(
|
|
|
|
|
+ SELECT COUNT(*)
|
|
|
|
|
+ FROM reviews
|
|
|
|
|
+ LEFT JOIN schedules ON schedules.id = reviews.schedule_id
|
|
|
|
|
+ WHERE reviews.origin = 'provider'
|
|
|
|
|
+ AND schedules.provider_id = providers.id
|
|
|
|
|
+ ) as total_reviews"),
|
|
|
|
|
+ )
|
|
|
|
|
+ ->orderBy('providers.average_rating', 'desc')
|
|
|
|
|
+ ->get()
|
|
|
|
|
+ ->when(
|
|
|
|
|
+ $date,
|
|
|
|
|
+ fn($collection) => $collection->whereIn(
|
|
|
|
|
+ 'provider_id',
|
|
|
|
|
+ ScheduleBusinessRules::getAvailableProviderIdsForDate(
|
|
|
|
|
+ $date,
|
|
|
|
|
+ $collection->pluck('provider_id')
|
|
|
|
|
+ )->toArray()
|
|
|
|
|
+ )->values()
|
|
|
|
|
+ )
|
|
|
|
|
+ ->toArray();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public function dadosDashboardPrestador(): array
|
|
public function dadosDashboardPrestador(): array
|
|
|
{
|
|
{
|
|
|
$user = Auth::user();
|
|
$user = Auth::user();
|