|
|
@@ -752,10 +752,10 @@ 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',
|
|
|
+ 'schedules.client_id',
|
|
|
'client_user.name as client_name',
|
|
|
'clients.average_rating',
|
|
|
'schedules.date',
|
|
|
@@ -772,7 +772,6 @@ class DashboardService
|
|
|
'schedules.address_id',
|
|
|
'schedules.status',
|
|
|
'custom_schedules.offers_meal',
|
|
|
- 'client_media.path as customer_photo_path',
|
|
|
|
|
|
DB::raw("
|
|
|
CASE
|
|
|
@@ -801,12 +800,6 @@ class DashboardService
|
|
|
->get();
|
|
|
|
|
|
$solicitations->each(function ($solicitation) use ($address) {
|
|
|
- $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 = $this->zipCodeCoordinatesService->calculateDistance(
|
|
|
$address?->latitude !== null ? (float) $address->latitude : null,
|
|
|
$address?->longitude !== null ? (float) $address->longitude : null,
|
|
|
@@ -825,7 +818,6 @@ 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',
|
|
|
@@ -842,7 +834,6 @@ class DashboardService
|
|
|
'schedules.code_verified',
|
|
|
'schedules.code',
|
|
|
'custom_schedules.offers_meal',
|
|
|
- 'client_media.path as customer_photo_path',
|
|
|
|
|
|
DB::raw("
|
|
|
EXISTS (
|
|
|
@@ -858,24 +849,16 @@ 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,zip_code,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',
|
|
|
+ 'schedules.client_id',
|
|
|
'client_user.name as client_name',
|
|
|
'schedules.date',
|
|
|
'schedules.start_time',
|
|
|
@@ -886,18 +869,11 @@ 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 ($address) {
|
|
|
- $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 = $this->zipCodeCoordinatesService->calculateDistance(
|
|
|
$address?->latitude !== null ? (float) $address->latitude : null,
|
|
|
$address?->longitude !== null ? (float) $address->longitude : null,
|
|
|
@@ -908,6 +884,24 @@ class DashboardService
|
|
|
);
|
|
|
});
|
|
|
|
|
|
+ $clientCollections = collect([
|
|
|
+ $solicitations,
|
|
|
+ $todayServices,
|
|
|
+ $nextSchedules,
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $clientPhotoUrls = $this->clientPhotoUrls(
|
|
|
+ $clientCollections->flatMap(
|
|
|
+ fn (Collection $items) => $items->pluck('client_id'),
|
|
|
+ ),
|
|
|
+ );
|
|
|
+
|
|
|
+ $clientCollections->each(function (Collection $items) use ($clientPhotoUrls) {
|
|
|
+ $items->each(function ($item) use ($clientPhotoUrls) {
|
|
|
+ $item->customer_photo = $clientPhotoUrls->get($item->client_id);
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
$notifications = Notification::where('user_id', $user->id)
|
|
|
->orderBy('read', 'asc')
|
|
|
->orderBy('created_at', 'desc')
|
|
|
@@ -1012,6 +1006,24 @@ class DashboardService
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ // Gera URLs apenas para fotos verificadas ou visíveis ao próprio cliente.
|
|
|
+
|
|
|
+ private function clientPhotoUrls(iterable $clientIds): Collection
|
|
|
+ {
|
|
|
+ return Client::query()
|
|
|
+ ->select('id', 'profile_media_id')
|
|
|
+ ->with('profileMedia')
|
|
|
+ ->whereIn('id', collect($clientIds)->filter()->unique())
|
|
|
+ ->get()
|
|
|
+ ->mapWithKeys(function (Client $client) {
|
|
|
+ $path = $client->profileMedia?->path;
|
|
|
+
|
|
|
+ return [
|
|
|
+ $client->id => $path ? Storage::temporaryUrl($path, now()->addMinutes(60)) : null,
|
|
|
+ ];
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
//
|
|
|
|
|
|
private function applyCreditCardFee(?float $price): ?float
|