|
|
@@ -28,7 +28,7 @@ class DashboardService
|
|
|
{
|
|
|
$user = Auth::user();
|
|
|
|
|
|
- $cliente = Client::where('user_id', $user->id)->first();
|
|
|
+ $cliente = Client::with('profileMedia')->where('user_id', $user->id)->first();
|
|
|
|
|
|
$headerBar = [
|
|
|
'rating' => $cliente->average_rating,
|
|
|
@@ -47,6 +47,9 @@ class DashboardService
|
|
|
|
|
|
$summaryInfos = [
|
|
|
'name' => $user->name,
|
|
|
+ 'profile_photo' => $cliente->profileMedia?->path
|
|
|
+ ? Storage::temporaryUrl($cliente->profileMedia->path, now()->addMinutes(60))
|
|
|
+ : null,
|
|
|
'address' => $address,
|
|
|
'pending_services' => Schedule::where('client_id', $cliente->id)
|
|
|
->where('status', 'pending')
|
|
|
@@ -60,6 +63,7 @@ class DashboardService
|
|
|
->leftJoin('providers', 'providers.id', '=', 'schedules.provider_id')
|
|
|
->leftJoin('users as provider_user', 'provider_user.id', '=', 'providers.user_id')
|
|
|
->leftJoin('custom_schedules', 'custom_schedules.schedule_id', '=', 'schedules.id')
|
|
|
+ ->leftJoin('media as provider_media', 'provider_media.id', '=', 'providers.profile_media_id')
|
|
|
->where('schedules.date', '>=', now()->toDateString())
|
|
|
->select(
|
|
|
'schedules.id',
|
|
|
@@ -73,11 +77,19 @@ class DashboardService
|
|
|
'schedules.schedule_type',
|
|
|
'schedules.address_id',
|
|
|
'custom_schedules.address_type as custom_address_type',
|
|
|
+ 'provider_media.path as provider_photo_path',
|
|
|
)
|
|
|
->orderBy('schedules.date', 'asc')
|
|
|
->limit(5)
|
|
|
->get();
|
|
|
|
|
|
+ $nextSchedules->each(function ($item) {
|
|
|
+ $item->provider_photo = $item->provider_photo_path
|
|
|
+ ? Storage::temporaryUrl($item->provider_photo_path, now()->addMinutes(60))
|
|
|
+ : null;
|
|
|
+ unset($item->provider_photo_path);
|
|
|
+ });
|
|
|
+
|
|
|
$lastDoneSchedules = Schedule::where('schedules.client_id', $cliente->id)
|
|
|
->where('schedules.status', 'finished')
|
|
|
->leftJoin('providers', 'providers.id', '=', 'schedules.provider_id')
|
|
|
@@ -87,16 +99,25 @@ class DashboardService
|
|
|
->where('provider_address.source', 'provider')
|
|
|
->orderBy('provider_address.is_primary', 'desc');
|
|
|
})
|
|
|
+ ->leftJoin('media as provider_media', 'provider_media.id', '=', 'providers.profile_media_id')
|
|
|
->select(
|
|
|
'schedules.id',
|
|
|
'schedules.provider_id',
|
|
|
'provider_user.name as provider_name',
|
|
|
'provider_address.district as provider_district',
|
|
|
+ 'provider_media.path as provider_photo_path',
|
|
|
)
|
|
|
->orderBy('schedules.date', 'desc')
|
|
|
->limit(5)
|
|
|
->get();
|
|
|
|
|
|
+ $lastDoneSchedules->each(function ($item) {
|
|
|
+ $item->provider_photo = $item->provider_photo_path
|
|
|
+ ? Storage::temporaryUrl($item->provider_photo_path, now()->addMinutes(60))
|
|
|
+ : null;
|
|
|
+ unset($item->provider_photo_path);
|
|
|
+ });
|
|
|
+
|
|
|
$favoriteProviders = ClientFavoriteProvider::where('client_favorite_providers.client_id', $cliente->id)
|
|
|
->leftJoin('providers', 'providers.id', '=', 'client_favorite_providers.provider_id')
|
|
|
->leftJoin('users as provider_user', 'provider_user.id', '=', 'providers.user_id')
|
|
|
@@ -105,16 +126,25 @@ class DashboardService
|
|
|
->where('provider_address.source', 'provider')
|
|
|
->orderBy('provider_address.is_primary', 'desc');
|
|
|
})
|
|
|
+ ->leftJoin('media as provider_media', 'provider_media.id', '=', 'providers.profile_media_id')
|
|
|
->select(
|
|
|
'providers.id as provider_id',
|
|
|
'provider_user.name as provider_name',
|
|
|
'providers.average_rating',
|
|
|
'provider_address.district as provider_district',
|
|
|
+ 'provider_media.path as provider_photo_path',
|
|
|
)
|
|
|
->orderBy('client_favorite_providers.created_at', 'desc')
|
|
|
->limit(5)
|
|
|
->get();
|
|
|
|
|
|
+ $favoriteProviders->each(function ($item) {
|
|
|
+ $item->provider_photo = $item->provider_photo_path
|
|
|
+ ? Storage::temporaryUrl($item->provider_photo_path, now()->addMinutes(60))
|
|
|
+ : null;
|
|
|
+ unset($item->provider_photo_path);
|
|
|
+ });
|
|
|
+
|
|
|
$blockedProviderIds = ScheduleBusinessRules::getBlockedProviderIdsForClient($cliente->id);
|
|
|
$providersWithWorkingDays = ScheduleBusinessRules::getProviderIdsWithWorkingDays();
|
|
|
|
|
|
@@ -139,6 +169,7 @@ class DashboardService
|
|
|
ORDER BY source_id, is_primary DESC
|
|
|
) as provider_address
|
|
|
"), 'provider_address.source_id', '=', 'providers.id')
|
|
|
+ ->leftJoin('media as provider_media', 'provider_media.id', '=', 'providers.profile_media_id')
|
|
|
->whereNotNull('provider_address.id')
|
|
|
->where('provider_address.city_id', $clientPrimaryAddress?->city_id)
|
|
|
->whereNotIn('providers.id', $blockedProviderIds)
|
|
|
@@ -165,15 +196,24 @@ class DashboardService
|
|
|
AND schedules.provider_id = providers.id
|
|
|
) as total_reviews"),
|
|
|
$providersCloseDistanceSelect,
|
|
|
+ 'provider_media.path as provider_photo_path',
|
|
|
)
|
|
|
->get();
|
|
|
|
|
|
+ $providersClose->each(function ($item) {
|
|
|
+ $item->provider_photo = $item->provider_photo_path
|
|
|
+ ? Storage::temporaryUrl($item->provider_photo_path, now()->addMinutes(60))
|
|
|
+ : null;
|
|
|
+ unset($item->provider_photo_path);
|
|
|
+ });
|
|
|
+
|
|
|
$pendingSchedules = Schedule::with('address:district,address,number,source_id,source,id,address_type')
|
|
|
->where('schedules.client_id', $cliente->id)
|
|
|
->whereIn('schedules.status', ['pending', 'accepted'])
|
|
|
->where('schedules.schedule_type', 'default')
|
|
|
->leftJoin('providers', 'providers.id', '=', 'schedules.provider_id')
|
|
|
->leftJoin('users as provider_user', 'provider_user.id', '=', 'providers.user_id')
|
|
|
+ ->leftJoin('media as provider_media', 'provider_media.id', '=', 'providers.profile_media_id')
|
|
|
->select(
|
|
|
'schedules.id',
|
|
|
'schedules.provider_id',
|
|
|
@@ -188,11 +228,19 @@ class DashboardService
|
|
|
WHEN (now() - schedules.created_at) < INTERVAL '1 hour' THEN CONCAT(ROUND(EXTRACT(EPOCH FROM (now() - schedules.created_at)) / 60), 'min')
|
|
|
WHEN (now() - schedules.created_at) < INTERVAL '1 day' THEN CONCAT(ROUND(EXTRACT(EPOCH FROM (now() - schedules.created_at)) / 3600), 'h')
|
|
|
ELSE CONCAT(ROUND(EXTRACT(EPOCH FROM (now() - schedules.created_at)) / 86400), 'd')
|
|
|
- END as time_since_request")
|
|
|
+ END as time_since_request"),
|
|
|
+ 'provider_media.path as provider_photo_path',
|
|
|
)
|
|
|
->orderBy('schedules.date', 'asc')
|
|
|
->get();
|
|
|
|
|
|
+ $pendingSchedules->each(function ($item) {
|
|
|
+ $item->provider_photo = $item->provider_photo_path
|
|
|
+ ? Storage::temporaryUrl($item->provider_photo_path, now()->addMinutes(60))
|
|
|
+ : null;
|
|
|
+ unset($item->provider_photo_path);
|
|
|
+ });
|
|
|
+
|
|
|
$proposalsDistanceSelect = DistanceService::sqlExpression(
|
|
|
$clientPrimaryAddress?->latitude !== null ? (float) $clientPrimaryAddress->latitude : null,
|
|
|
$clientPrimaryAddress?->longitude !== null ? (float) $clientPrimaryAddress->longitude : null,
|
|
|
@@ -210,6 +258,7 @@ class DashboardService
|
|
|
AND deleted_at IS NULL
|
|
|
ORDER BY source_id, is_primary DESC
|
|
|
) as provider_address"), 'provider_address.source_id', '=', 'providers.id')
|
|
|
+ ->leftJoin('media as provider_media', 'provider_media.id', '=', 'providers.profile_media_id')
|
|
|
->where('schedules.client_id', $cliente->id)
|
|
|
->where('schedules.schedule_type', 'custom')
|
|
|
->where('schedules.status', 'pending')
|
|
|
@@ -233,9 +282,17 @@ class DashboardService
|
|
|
|
|
|
'users.name as provider_name',
|
|
|
$proposalsDistanceSelect,
|
|
|
+ 'provider_media.path as provider_photo_path',
|
|
|
])
|
|
|
->get();
|
|
|
|
|
|
+ $schedulesProposals->each(function ($item) {
|
|
|
+ $item->provider_photo = $item->provider_photo_path
|
|
|
+ ? Storage::temporaryUrl($item->provider_photo_path, now()->addMinutes(60))
|
|
|
+ : null;
|
|
|
+ unset($item->provider_photo_path);
|
|
|
+ });
|
|
|
+
|
|
|
$todaySchedules = Schedule::with('address:district,address,number,source_id,source,id,address_type')
|
|
|
->where('schedules.client_id', $cliente->id)
|
|
|
->whereIn('schedules.status', ['accepted', 'paid', 'started', 'finished'])
|
|
|
@@ -342,7 +399,7 @@ class DashboardService
|
|
|
{
|
|
|
$user = Auth::user();
|
|
|
|
|
|
- $provider = Provider::where('user_id', $user->id)->first();
|
|
|
+ $provider = Provider::with('profileMedia')->where('user_id', $user->id)->first();
|
|
|
|
|
|
$headerBar = [
|
|
|
'rating' => $provider->average_rating,
|
|
|
@@ -354,6 +411,9 @@ class DashboardService
|
|
|
|
|
|
$summaryInfos = [
|
|
|
'name' => $user->name,
|
|
|
+ 'profile_photo' => $provider->profileMedia?->path
|
|
|
+ ? Storage::temporaryUrl($provider->profileMedia->path, now()->addMinutes(60))
|
|
|
+ : null,
|
|
|
'address' => $address,
|
|
|
'pending_services' => Schedule::where('provider_id', $provider->id)->where('status', 'pending')->count(),
|
|
|
];
|
|
|
@@ -375,6 +435,7 @@ class DashboardService
|
|
|
->where('schedules.status', 'pending')
|
|
|
->leftJoin('clients', 'clients.id', '=', 'schedules.client_id')
|
|
|
->leftJoin('users as client_user', 'client_user.id', '=', 'clients.user_id')
|
|
|
+ ->leftJoin('media as client_media', 'client_media.id', '=', 'clients.profile_media_id')
|
|
|
->leftJoin('custom_schedules', 'custom_schedules.schedule_id', '=', 'schedules.id')
|
|
|
->select(
|
|
|
'schedules.id',
|
|
|
@@ -390,6 +451,7 @@ class DashboardService
|
|
|
'schedules.address_id',
|
|
|
'schedules.status',
|
|
|
'custom_schedules.offers_meal',
|
|
|
+ 'client_media.path as customer_photo_path',
|
|
|
DB::raw("CASE
|
|
|
WHEN (now() - schedules.created_at) < INTERVAL '1 day' THEN CONCAT(ROUND(EXTRACT(EPOCH FROM (now() - schedules.created_at)) / 3600), ' hours ago')
|
|
|
ELSE CONCAT(ROUND(EXTRACT(EPOCH FROM (now() - schedules.created_at)) / 86400), ' days ago')
|
|
|
@@ -402,6 +464,10 @@ class DashboardService
|
|
|
$providerLng = $address?->longitude !== null ? (float) $address->longitude : null;
|
|
|
|
|
|
$solicitations->each(function ($solicitation) use ($providerLat, $providerLng) {
|
|
|
+ $solicitation->customer_photo = $solicitation->customer_photo_path
|
|
|
+ ? Storage::temporaryUrl($solicitation->customer_photo_path, now()->addMinutes(60))
|
|
|
+ : null;
|
|
|
+ unset($solicitation->customer_photo_path);
|
|
|
$solicitation->distance_km = DistanceService::calculate(
|
|
|
$providerLat,
|
|
|
$providerLng,
|
|
|
@@ -416,6 +482,7 @@ class DashboardService
|
|
|
->whereDate('schedules.date', now()->toDateString())
|
|
|
->leftJoin('clients', 'clients.id', '=', 'schedules.client_id')
|
|
|
->leftJoin('users as client_user', 'client_user.id', '=', 'clients.user_id')
|
|
|
+ ->leftJoin('media as client_media', 'client_media.id', '=', 'clients.profile_media_id')
|
|
|
->leftJoin('custom_schedules', 'custom_schedules.schedule_id', '=', 'schedules.id')
|
|
|
->select(
|
|
|
'schedules.id',
|
|
|
@@ -432,6 +499,7 @@ class DashboardService
|
|
|
'schedules.code_verified',
|
|
|
'schedules.code',
|
|
|
'custom_schedules.offers_meal',
|
|
|
+ 'client_media.path as customer_photo_path',
|
|
|
DB::raw("EXISTS(
|
|
|
SELECT 1 FROM reviews
|
|
|
WHERE reviews.schedule_id = schedules.id
|
|
|
@@ -443,12 +511,20 @@ class DashboardService
|
|
|
->orderBy('schedules.start_time', 'asc')
|
|
|
->get();
|
|
|
|
|
|
+ $todayServices->each(function ($s) {
|
|
|
+ $s->customer_photo = $s->customer_photo_path
|
|
|
+ ? Storage::temporaryUrl($s->customer_photo_path, now()->addMinutes(60))
|
|
|
+ : null;
|
|
|
+ unset($s->customer_photo_path);
|
|
|
+ });
|
|
|
+
|
|
|
$nextSchedules = Schedule::with('address:district,address,number,source_id,source,id,latitude,longitude')
|
|
|
->where('schedules.provider_id', $provider->id)
|
|
|
->whereIn('schedules.status', ['accepted', 'paid'])
|
|
|
->whereDate('schedules.date', '>=', now()->toDateString())
|
|
|
->leftJoin('clients', 'clients.id', '=', 'schedules.client_id')
|
|
|
->leftJoin('users as client_user', 'client_user.id', '=', 'clients.user_id')
|
|
|
+ ->leftJoin('media as client_media', 'client_media.id', '=', 'clients.profile_media_id')
|
|
|
->leftJoin('custom_schedules', 'custom_schedules.schedule_id', '=', 'schedules.id')
|
|
|
->select(
|
|
|
'schedules.id',
|
|
|
@@ -462,11 +538,16 @@ class DashboardService
|
|
|
'schedules.schedule_type',
|
|
|
'schedules.status',
|
|
|
'custom_schedules.offers_meal',
|
|
|
+ 'client_media.path as customer_photo_path',
|
|
|
)
|
|
|
->orderBy('schedules.date', 'asc')
|
|
|
->get();
|
|
|
|
|
|
$nextSchedules->each(function ($schedule) use ($providerLat, $providerLng) {
|
|
|
+ $schedule->customer_photo = $schedule->customer_photo_path
|
|
|
+ ? Storage::temporaryUrl($schedule->customer_photo_path, now()->addMinutes(60))
|
|
|
+ : null;
|
|
|
+ unset($schedule->customer_photo_path);
|
|
|
$schedule->distance_km = DistanceService::calculate(
|
|
|
$providerLat,
|
|
|
$providerLng,
|
|
|
@@ -507,6 +588,12 @@ class DashboardService
|
|
|
|
|
|
$opportunities = $this->customScheduleService->getAvailableOpportunities($provider->id);
|
|
|
|
|
|
+ $opportunities->each(function ($o) {
|
|
|
+ $o->customer_photo = $o->client?->profileMedia?->path
|
|
|
+ ? Storage::temporaryUrl($o->client->profileMedia->path, now()->addMinutes(60))
|
|
|
+ : null;
|
|
|
+ });
|
|
|
+
|
|
|
return [
|
|
|
'headerBar' => $headerBar,
|
|
|
'summaryInfos' => $summaryInfos,
|