diffInDays($end); $tariffs = UniModel::model('pipi_auto_tariffs') ->where('model_id', $markId) ->get(); if ($tariffs->isEmpty()) { throw new \Exception(__('Отсутствуют данные по машине')); } $basePrice = null; $discountRate = null; $deposit = null; foreach ($tariffs as $range) { if ($range->day_range_start == 1 && $range->day_range_end == 2) { $basePrice = $range->base_rate; } if (isset($range->deposit)) { $deposit = $range->deposit; } if ($days >= $range->day_range_start && $days <= $range->day_range_end) { $discountRate = $range->base_rate; } } // Если не нашли скидку, но дней > 30 if (is_null($discountRate) && $days > 30 && $basePrice) { $discountRate = round($basePrice * 0.6); } $baseSum = $basePrice ? $basePrice * $days : null; $discountedSum = $discountRate ? $discountRate * $days : null; return [ 'days' => $days, 'base_price_per_day' => $basePrice, 'discount_price_per_day' => $discountRate, 'base_sum' => $baseSum, 'discounted_sum' => $discountedSum, 'deposit_base' => $deposit, 'without_deposit' => $this->calcWithoutDeposit($deposit, $days), ]; } }