|
@@ -24,6 +24,7 @@ class DashboardService
|
|
|
{
|
|
{
|
|
|
public function __construct(
|
|
public function __construct(
|
|
|
private readonly CustomScheduleService $customScheduleService,
|
|
private readonly CustomScheduleService $customScheduleService,
|
|
|
|
|
+ private readonly ZipCodeCoordinatesService $zipCodeCoordinatesService,
|
|
|
) {}
|
|
) {}
|
|
|
|
|
|
|
|
public function dadosDashboardCliente(): array
|
|
public function dadosDashboardCliente(): array
|
|
@@ -206,9 +207,15 @@ class DashboardService
|
|
|
|
|
|
|
|
$clientDistanceAddress = $this->addressForDistance($cliente->id, $clientPrimaryAddress);
|
|
$clientDistanceAddress = $this->addressForDistance($cliente->id, $clientPrimaryAddress);
|
|
|
|
|
|
|
|
- $providersCloseDistanceSelect = $this->distanceSelect(
|
|
|
|
|
- $clientDistanceAddress?->latitude !== null ? (float) $clientDistanceAddress->latitude : null,
|
|
|
|
|
|
|
+ $clientCoordinates = $this->zipCodeCoordinatesService->resolve(
|
|
|
|
|
+ $clientDistanceAddress?->latitude !== null ? (float) $clientDistanceAddress->latitude : null,
|
|
|
$clientDistanceAddress?->longitude !== null ? (float) $clientDistanceAddress->longitude : null,
|
|
$clientDistanceAddress?->longitude !== null ? (float) $clientDistanceAddress->longitude : null,
|
|
|
|
|
+ $clientDistanceAddress?->zip_code,
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ $providersCloseDistanceSelect = $this->distanceSelect(
|
|
|
|
|
+ $clientCoordinates['latitude'] ?? null,
|
|
|
|
|
+ $clientCoordinates['longitude'] ?? null,
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
$providersClose = Provider::leftJoin(
|
|
$providersClose = Provider::leftJoin(
|
|
@@ -255,6 +262,7 @@ class DashboardService
|
|
|
'providers.id as provider_id',
|
|
'providers.id as provider_id',
|
|
|
'provider_user.name as provider_name',
|
|
'provider_user.name as provider_name',
|
|
|
'provider_address.id as address_id',
|
|
'provider_address.id as address_id',
|
|
|
|
|
+ 'provider_address.zip_code as provider_zip_code',
|
|
|
'provider_address.district',
|
|
'provider_address.district',
|
|
|
'provider_address.latitude as provider_latitude',
|
|
'provider_address.latitude as provider_latitude',
|
|
|
'provider_address.longitude as provider_longitude',
|
|
'provider_address.longitude as provider_longitude',
|
|
@@ -283,12 +291,27 @@ class DashboardService
|
|
|
->orderByRaw('distance_km ASC NULLS LAST')
|
|
->orderByRaw('distance_km ASC NULLS LAST')
|
|
|
->get();
|
|
->get();
|
|
|
|
|
|
|
|
- $providersClose->each(function ($item) {
|
|
|
|
|
|
|
+ $this->zipCodeCoordinatesService->preload(
|
|
|
|
|
+ $providersClose->whereNull('distance_km')->pluck('provider_zip_code')
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ $providersClose->each(function ($item) use ($clientDistanceAddress) {
|
|
|
|
|
+ if ($item->distance_km === null) {
|
|
|
|
|
+ $item->distance_km = $this->zipCodeCoordinatesService->calculateDistance(
|
|
|
|
|
+ $clientDistanceAddress?->latitude !== null ? (float) $clientDistanceAddress->latitude : null,
|
|
|
|
|
+ $clientDistanceAddress?->longitude !== null ? (float) $clientDistanceAddress->longitude : null,
|
|
|
|
|
+ $clientDistanceAddress?->zip_code,
|
|
|
|
|
+ $item->provider_latitude !== null ? (float) $item->provider_latitude : null,
|
|
|
|
|
+ $item->provider_longitude !== null ? (float) $item->provider_longitude : null,
|
|
|
|
|
+ $item->provider_zip_code,
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
$item->provider_photo = $item->provider_photo_path
|
|
$item->provider_photo = $item->provider_photo_path
|
|
|
? Storage::temporaryUrl($item->provider_photo_path, now()->addMinutes(60))
|
|
? Storage::temporaryUrl($item->provider_photo_path, now()->addMinutes(60))
|
|
|
: null;
|
|
: null;
|
|
|
|
|
|
|
|
- unset($item->provider_photo_path);
|
|
|
|
|
|
|
+ unset($item->provider_photo_path, $item->provider_zip_code);
|
|
|
|
|
|
|
|
$item->daily_price_8h_base = $item->daily_price_8h;
|
|
$item->daily_price_8h_base = $item->daily_price_8h;
|
|
|
$item->daily_price_6h_base = $item->daily_price_6h;
|
|
$item->daily_price_6h_base = $item->daily_price_6h;
|
|
@@ -301,6 +324,10 @@ class DashboardService
|
|
|
$item->daily_price_2h = $this->applyCreditCardFee($item->daily_price_2h);
|
|
$item->daily_price_2h = $this->applyCreditCardFee($item->daily_price_2h);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+ $providersClose = $providersClose
|
|
|
|
|
+ ->sortBy(fn ($provider) => $provider->distance_km ?? PHP_FLOAT_MAX)
|
|
|
|
|
+ ->values();
|
|
|
|
|
+
|
|
|
$pendingSchedules = Schedule::with([
|
|
$pendingSchedules = Schedule::with([
|
|
|
'address:district,address,number,source_id,source,id,address_type',
|
|
'address:district,address,number,source_id,source,id,address_type',
|
|
|
])
|
|
])
|
|
@@ -377,8 +404,8 @@ class DashboardService
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
$proposalsDistanceSelect = DistanceService::sqlExpression(
|
|
$proposalsDistanceSelect = DistanceService::sqlExpression(
|
|
|
- $clientPrimaryAddress?->latitude !== null ? (float) $clientPrimaryAddress->latitude : null,
|
|
|
|
|
- $clientPrimaryAddress?->longitude !== null ? (float) $clientPrimaryAddress->longitude : null,
|
|
|
|
|
|
|
+ $clientCoordinates['latitude'] ?? null,
|
|
|
|
|
+ $clientCoordinates['longitude'] ?? null,
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
$schedulesProposals = ScheduleProposal::query()
|
|
$schedulesProposals = ScheduleProposal::query()
|
|
@@ -445,12 +472,20 @@ class DashboardService
|
|
|
|
|
|
|
|
'users.name as provider_name',
|
|
'users.name as provider_name',
|
|
|
|
|
|
|
|
|
|
+ 'provider_address.latitude as provider_latitude',
|
|
|
|
|
+ 'provider_address.longitude as provider_longitude',
|
|
|
|
|
+ 'provider_address.zip_code as provider_zip_code',
|
|
|
|
|
+
|
|
|
$proposalsDistanceSelect,
|
|
$proposalsDistanceSelect,
|
|
|
|
|
|
|
|
'provider_media.path as provider_photo_path',
|
|
'provider_media.path as provider_photo_path',
|
|
|
])
|
|
])
|
|
|
->get();
|
|
->get();
|
|
|
|
|
|
|
|
|
|
+ $this->zipCodeCoordinatesService->preload(
|
|
|
|
|
+ $schedulesProposals->whereNull('distance_km')->pluck('provider_zip_code')
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
$custom_schedules_with_no_proposals = Schedule::where('client_id', $cliente->id)
|
|
$custom_schedules_with_no_proposals = Schedule::where('client_id', $cliente->id)
|
|
|
->where('schedule_type', 'custom')
|
|
->where('schedule_type', 'custom')
|
|
|
->where('status', 'pending')
|
|
->where('status', 'pending')
|
|
@@ -458,12 +493,28 @@ class DashboardService
|
|
|
->doesntHave('proposals')
|
|
->doesntHave('proposals')
|
|
|
->get();
|
|
->get();
|
|
|
|
|
|
|
|
- $schedulesProposals->each(function ($item) {
|
|
|
|
|
|
|
+ $schedulesProposals->each(function ($item) use ($clientDistanceAddress) {
|
|
|
|
|
+ if ($item->distance_km === null) {
|
|
|
|
|
+ $item->distance_km = $this->zipCodeCoordinatesService->calculateDistance(
|
|
|
|
|
+ $clientDistanceAddress?->latitude !== null ? (float) $clientDistanceAddress->latitude : null,
|
|
|
|
|
+ $clientDistanceAddress?->longitude !== null ? (float) $clientDistanceAddress->longitude : null,
|
|
|
|
|
+ $clientDistanceAddress?->zip_code,
|
|
|
|
|
+ $item->provider_latitude !== null ? (float) $item->provider_latitude : null,
|
|
|
|
|
+ $item->provider_longitude !== null ? (float) $item->provider_longitude : null,
|
|
|
|
|
+ $item->provider_zip_code,
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
$item->provider_photo = $item->provider_photo_path
|
|
$item->provider_photo = $item->provider_photo_path
|
|
|
? Storage::temporaryUrl($item->provider_photo_path, now()->addMinutes(60))
|
|
? Storage::temporaryUrl($item->provider_photo_path, now()->addMinutes(60))
|
|
|
: null;
|
|
: null;
|
|
|
|
|
|
|
|
- unset($item->provider_photo_path);
|
|
|
|
|
|
|
+ unset(
|
|
|
|
|
+ $item->provider_photo_path,
|
|
|
|
|
+ $item->provider_latitude,
|
|
|
|
|
+ $item->provider_longitude,
|
|
|
|
|
+ $item->provider_zip_code,
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
$todaySchedules = Schedule::with([
|
|
$todaySchedules = Schedule::with([
|
|
@@ -612,7 +663,7 @@ class DashboardService
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
$solicitations = Schedule::with([
|
|
$solicitations = Schedule::with([
|
|
|
- 'address:district,source_id,source,id,latitude,longitude',
|
|
|
|
|
|
|
+ 'address:district,source_id,source,id,zip_code,latitude,longitude',
|
|
|
])
|
|
])
|
|
|
->where('schedules.provider_id', $provider->id)
|
|
->where('schedules.provider_id', $provider->id)
|
|
|
->where('schedules.status', 'pending')
|
|
->where('schedules.status', 'pending')
|
|
@@ -666,21 +717,20 @@ class DashboardService
|
|
|
->orderBy('schedules.date', 'asc')
|
|
->orderBy('schedules.date', 'asc')
|
|
|
->get();
|
|
->get();
|
|
|
|
|
|
|
|
- $providerLat = $address?->latitude !== null ? (float) $address->latitude : null;
|
|
|
|
|
- $providerLng = $address?->longitude !== null ? (float) $address->longitude : null;
|
|
|
|
|
-
|
|
|
|
|
- $solicitations->each(function ($solicitation) use ($providerLat, $providerLng) {
|
|
|
|
|
|
|
+ $solicitations->each(function ($solicitation) use ($address) {
|
|
|
$solicitation->customer_photo = $solicitation->customer_photo_path
|
|
$solicitation->customer_photo = $solicitation->customer_photo_path
|
|
|
? Storage::temporaryUrl($solicitation->customer_photo_path, now()->addMinutes(60))
|
|
? Storage::temporaryUrl($solicitation->customer_photo_path, now()->addMinutes(60))
|
|
|
: null;
|
|
: null;
|
|
|
|
|
|
|
|
unset($solicitation->customer_photo_path);
|
|
unset($solicitation->customer_photo_path);
|
|
|
|
|
|
|
|
- $solicitation->distance_km = DistanceService::calculate(
|
|
|
|
|
- $providerLat,
|
|
|
|
|
- $providerLng,
|
|
|
|
|
|
|
+ $solicitation->distance_km = $this->zipCodeCoordinatesService->calculateDistance(
|
|
|
|
|
+ $address?->latitude !== null ? (float) $address->latitude : null,
|
|
|
|
|
+ $address?->longitude !== null ? (float) $address->longitude : null,
|
|
|
|
|
+ $address?->zip_code,
|
|
|
$solicitation->address?->latitude !== null ? (float) $solicitation->address->latitude : null,
|
|
$solicitation->address?->latitude !== null ? (float) $solicitation->address->latitude : null,
|
|
|
$solicitation->address?->longitude !== null ? (float) $solicitation->address->longitude : null,
|
|
$solicitation->address?->longitude !== null ? (float) $solicitation->address->longitude : null,
|
|
|
|
|
+ $solicitation->address?->zip_code,
|
|
|
);
|
|
);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -733,7 +783,7 @@ class DashboardService
|
|
|
unset($s->customer_photo_path);
|
|
unset($s->customer_photo_path);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- $nextSchedules = Schedule::with('address:district,address,number,source_id,source,id,latitude,longitude')
|
|
|
|
|
|
|
+ $nextSchedules = Schedule::with('address:district,address,number,source_id,source,id,zip_code,latitude,longitude')
|
|
|
->where('schedules.provider_id', $provider->id)
|
|
->where('schedules.provider_id', $provider->id)
|
|
|
->whereIn('schedules.status', ['accepted', 'paid'])
|
|
->whereIn('schedules.status', ['accepted', 'paid'])
|
|
|
->whereDate('schedules.date', '>=', now()->toDateString())
|
|
->whereDate('schedules.date', '>=', now()->toDateString())
|
|
@@ -758,18 +808,20 @@ class DashboardService
|
|
|
->orderBy('schedules.date', 'asc')
|
|
->orderBy('schedules.date', 'asc')
|
|
|
->get();
|
|
->get();
|
|
|
|
|
|
|
|
- $nextSchedules->each(function ($schedule) use ($providerLat, $providerLng) {
|
|
|
|
|
|
|
+ $nextSchedules->each(function ($schedule) use ($address) {
|
|
|
$schedule->customer_photo = $schedule->customer_photo_path
|
|
$schedule->customer_photo = $schedule->customer_photo_path
|
|
|
? Storage::temporaryUrl($schedule->customer_photo_path, now()->addMinutes(60))
|
|
? Storage::temporaryUrl($schedule->customer_photo_path, now()->addMinutes(60))
|
|
|
: null;
|
|
: null;
|
|
|
|
|
|
|
|
unset($schedule->customer_photo_path);
|
|
unset($schedule->customer_photo_path);
|
|
|
|
|
|
|
|
- $schedule->distance_km = DistanceService::calculate(
|
|
|
|
|
- $providerLat,
|
|
|
|
|
- $providerLng,
|
|
|
|
|
|
|
+ $schedule->distance_km = $this->zipCodeCoordinatesService->calculateDistance(
|
|
|
|
|
+ $address?->latitude !== null ? (float) $address->latitude : null,
|
|
|
|
|
+ $address?->longitude !== null ? (float) $address->longitude : null,
|
|
|
|
|
+ $address?->zip_code,
|
|
|
$schedule->address?->latitude !== null ? (float) $schedule->address->latitude : null,
|
|
$schedule->address?->latitude !== null ? (float) $schedule->address->latitude : null,
|
|
|
$schedule->address?->longitude !== null ? (float) $schedule->address->longitude : null,
|
|
$schedule->address?->longitude !== null ? (float) $schedule->address->longitude : null,
|
|
|
|
|
+ $schedule->address?->zip_code,
|
|
|
);
|
|
);
|
|
|
});
|
|
});
|
|
|
|
|
|