|
@@ -3,6 +3,7 @@
|
|
|
namespace app\data\service;
|
|
|
|
|
|
use app\data\model\BasePostageRegion;
|
|
|
+use Carbon\Carbon;
|
|
|
use think\admin\Service;
|
|
|
use think\helper\Arr;
|
|
|
use think\helper\Str;
|
|
@@ -48,6 +49,9 @@ class WeatherSvc extends Service
|
|
|
if(empty($result)){
|
|
|
return $result;
|
|
|
}
|
|
|
+ foreach ($result as &$item){
|
|
|
+ $item['fxTime']=Carbon::parse($item['fxTime'])->format('H');
|
|
|
+ }
|
|
|
return $result;
|
|
|
},30*60);
|
|
|
$daily=$this->app->cache->remember("weather_7d_{$this->getCity()}",function (){
|
|
@@ -79,7 +83,45 @@ class WeatherSvc extends Service
|
|
|
}
|
|
|
return $result;
|
|
|
},30*60);
|
|
|
- return compact('hourly','daily','index');
|
|
|
+ $airQuality=$this->app->cache->remember("weather_index_{$this->getCity()}",function (){
|
|
|
+ $data=client()->get($this->heApi('airQuality'),[
|
|
|
+ 'query'=>[
|
|
|
+ 'location'=>$this->location(),
|
|
|
+ 'key'=>sysconf('app_juhe_config.key'),
|
|
|
+ ]
|
|
|
+ ]);
|
|
|
+ $json=json_decode($data->getBody()->getContents(),true);
|
|
|
+ $result=$json['now']??null;
|
|
|
+ if(empty($result)){
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
+ return $result;
|
|
|
+ },30*60);
|
|
|
+ $now=$this->app->cache->remember("weather_now_{$this->getCity()}",function (){
|
|
|
+ $data=client()->get($this->heApi('now'),[
|
|
|
+ 'query'=>[
|
|
|
+ 'location'=>$this->location(),
|
|
|
+ 'key'=>sysconf('app_juhe_config.key'),
|
|
|
+ ]
|
|
|
+ ]);
|
|
|
+ $json=json_decode($data->getBody()->getContents(),true);
|
|
|
+ $result=$json['now']??null;
|
|
|
+ if(empty($result)){
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
+ return $result;
|
|
|
+ },1*60);
|
|
|
+ if($hourly){
|
|
|
+ foreach ($hourly as &$item){
|
|
|
+ $item['category']=$airQuality['category']??'优';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if($now){
|
|
|
+ $now['category']=$airQuality['category']??'优';
|
|
|
+ $now['aqi']=$airQuality['aqi']??'22';
|
|
|
+ $now['obsTime']=Carbon::parse($now['obsTime'])->format('m-d H:i');
|
|
|
+ }
|
|
|
+ return compact('hourly','daily','index','now');
|
|
|
}
|
|
|
|
|
|
protected function heApi($api){
|
|
@@ -96,7 +138,15 @@ class WeatherSvc extends Service
|
|
|
'index'=>[
|
|
|
'fee'=>'https://api.qweather.com/v7/indices/1d',
|
|
|
'free'=>'https://devapi.qweather.com/v7/indices/1d',
|
|
|
- ]
|
|
|
+ ],
|
|
|
+ 'airQuality'=>[
|
|
|
+ 'fee'=>'https://api.qweather.com/v7/air/now',
|
|
|
+ 'free'=>'https://devapi.qweather.com/v7/air/now',
|
|
|
+ ],
|
|
|
+ 'now'=>[
|
|
|
+ 'fee'=>'https://api.qweather.com/v7/weather/now',
|
|
|
+ 'free'=>'https://devapi.qweather.com/v7/weather/now',
|
|
|
+ ],
|
|
|
];
|
|
|
return Arr::get($apiList[$api],$mode);
|
|
|
}
|