diff --git a/app/Services/WeatherService.php b/app/Services/WeatherService.php index 81779e5a..72932b60 100644 --- a/app/Services/WeatherService.php +++ b/app/Services/WeatherService.php @@ -63,30 +63,36 @@ private function buildForecast(): array $midTa = $this->fetchMidTemperature(); $midLand = $this->fetchMidLandForecast(); - // 오늘부터 7일간 데이터 조합 + // 오늘부터 7일간 데이터 조합 (단기 + 중기 병합) $forecasts = []; for ($i = 0; $i < 7; $i++) { $date = $today->copy()->addDays($i)->format('Ymd'); - // 단기예보 데이터 우선 - if (isset($short[$date])) { - $forecasts[] = $short[$date]; - - continue; - } + $shortData = $short[$date] ?? null; // 중기예보 데이터 - $tmn = $midTa["taMin{$i}"] ?? null; - $tmx = $midTa["taMax{$i}"] ?? null; - $wf = $midLand["wf{$i}Am"] ?? ($midLand["wf{$i}"] ?? ''); + $midTmn = $midTa["taMin{$i}"] ?? null; + $midTmx = $midTa["taMax{$i}"] ?? null; + $midWf = $midLand["wf{$i}Am"] ?? ($midLand["wf{$i}"] ?? ''); - $forecasts[] = [ - 'date' => $date, - 'tmn' => $tmn, - 'tmx' => $tmx, - 'icon' => ! empty($wf) ? $this->midWeatherToIcon($wf) : null, - 'weather_text' => $wf, - ]; + if ($shortData) { + // 단기예보 우선, 기온이 없으면 중기로 보충 + $forecasts[] = [ + 'date' => $date, + 'tmn' => $shortData['tmn'] ?? $midTmn, + 'tmx' => $shortData['tmx'] ?? $midTmx, + 'icon' => $shortData['icon'] ?? (! empty($midWf) ? $this->midWeatherToIcon($midWf) : null), + 'weather_text' => $shortData['weather_text'] ?: $midWf, + ]; + } else { + $forecasts[] = [ + 'date' => $date, + 'tmn' => $midTmn, + 'tmx' => $midTmx, + 'icon' => ! empty($midWf) ? $this->midWeatherToIcon($midWf) : null, + 'weather_text' => $midWf, + ]; + } } return $forecasts;