|
|
@@ -203,9 +203,11 @@ class DashboardService
|
|
|
->where('is_primary', true)
|
|
|
->first();
|
|
|
|
|
|
+ $clientDistanceAddress = $this->addressForDistance($cliente->id, $clientPrimaryAddress);
|
|
|
+
|
|
|
$providersCloseDistanceSelect = $this->distanceSelect(
|
|
|
- $clientPrimaryAddress?->latitude !== null ? (float) $clientPrimaryAddress->latitude : null,
|
|
|
- $clientPrimaryAddress?->longitude !== null ? (float) $clientPrimaryAddress->longitude : null,
|
|
|
+ $clientDistanceAddress?->latitude !== null ? (float) $clientDistanceAddress->latitude : null,
|
|
|
+ $clientDistanceAddress?->longitude !== null ? (float) $clientDistanceAddress->longitude : null,
|
|
|
);
|
|
|
|
|
|
$providersClose = Provider::leftJoin(
|
|
|
@@ -270,7 +272,7 @@ class DashboardService
|
|
|
|
|
|
'provider_media.path as provider_photo_path',
|
|
|
)
|
|
|
- ->orderBy('distance_km', 'asc')
|
|
|
+ ->orderByRaw('distance_km ASC NULLS LAST')
|
|
|
->get();
|
|
|
|
|
|
$providersClose->each(function ($item) {
|
|
|
@@ -850,11 +852,39 @@ class DashboardService
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- $rate = (float) config('services.pagarme.platform_credit_card_fee_rate');
|
|
|
+ $rate = $this->platformCreditCardFeeRate();
|
|
|
|
|
|
return round($price * (1 + $rate), 2);
|
|
|
}
|
|
|
|
|
|
+ private function platformCreditCardFeeRate(): float
|
|
|
+ {
|
|
|
+ $rate = config('services.pagarme.platform_credit_card_fee_rate', 0.16);
|
|
|
+
|
|
|
+ if (is_string($rate)) {
|
|
|
+ $rate = str_replace(',', '.', trim($rate));
|
|
|
+ }
|
|
|
+
|
|
|
+ $rate = (float) $rate;
|
|
|
+
|
|
|
+ return $rate > 1 ? $rate / 100 : $rate;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function addressForDistance(int $clientId, ?Address $primaryAddress): ?Address
|
|
|
+ {
|
|
|
+ if ($primaryAddress?->latitude !== null && $primaryAddress?->longitude !== null) {
|
|
|
+ return $primaryAddress;
|
|
|
+ }
|
|
|
+
|
|
|
+ return Address::where('source', 'client')
|
|
|
+ ->where('source_id', $clientId)
|
|
|
+ ->whereNotNull('latitude')
|
|
|
+ ->whereNotNull('longitude')
|
|
|
+ ->orderByDesc('is_primary')
|
|
|
+ ->orderByDesc('id')
|
|
|
+ ->first() ?? $primaryAddress;
|
|
|
+ }
|
|
|
+
|
|
|
private function distanceSelect(?float $clientLatitude, ?float $clientLongitude): \Illuminate\Contracts\Database\Query\Expression
|
|
|
{
|
|
|
return DistanceService::sqlExpression($clientLatitude, $clientLongitude);
|