|
@@ -306,4 +306,52 @@ class Order extends Model
|
306
|
306
|
$objWriter->save('php://output');
|
307
|
307
|
exit();
|
308
|
308
|
}
|
|
309
|
+
|
|
310
|
+ /*更新城市天气信息*/
|
|
311
|
+ public static function updateWeather($order_id) {
|
|
312
|
+ $redisKey = 'seafood_order_city_weather';
|
|
313
|
+ $appKey = '32c8f844f8055f70f702fc28ec930e52';
|
|
314
|
+ //查询订单收件人所在的城市(过滤关键字 市)
|
|
315
|
+ $city = self::where('id', $order_id)->pluck('receiverCity');
|
|
316
|
+ $city = str_replace('市','',$city);
|
|
317
|
+ $specialCity = array('朝阳区','嘉定区','海淀区','昌平区','密云区','大兴区','房山区','通州区','普陀区',);
|
|
318
|
+ if(in_array($city, $specialCity)) {
|
|
319
|
+ $city = str_replace('区','',$city);
|
|
320
|
+ }
|
|
321
|
+ //查询redis中是否有该键,若没有则查询
|
|
322
|
+ $weather = RedisModel::get($redisKey.'_'.$city);
|
|
323
|
+ if($weather) {
|
|
324
|
+ $sellerMemo = self::where('id', $order_id)->pluck('sellerMemo');
|
|
325
|
+ $sellerMemo = $sellerMemo.' '.$city.'天气状况:'.$weather;
|
|
326
|
+ self::where('id', $order_id)->update(['sellerMemo'=>$sellerMemo]);
|
|
327
|
+ } else {
|
|
328
|
+ $url = 'http://apis.juhe.cn/simpleWeather/query?city='.urlencode($city).'&key='.$appKey;
|
|
329
|
+ $result = file_get_contents($url);
|
|
330
|
+ $result = json_decode($result, true);
|
|
331
|
+ if($result['error_code'] == '0') {
|
|
332
|
+ //将数据缓存到redis里
|
|
333
|
+ $today = date('Y-m-d',time());
|
|
334
|
+ $tomorrow = date('Y-m-d',strtotime('+1 days'));
|
|
335
|
+ $weather = '';
|
|
336
|
+ foreach ($result['result']['future'] as $value) {
|
|
337
|
+ if($value['date'] == $today) {
|
|
338
|
+ $weather .= $today.'日气温:'.$value['temperature'].'; ';
|
|
339
|
+ }
|
|
340
|
+ if($value['date'] == $tomorrow) {
|
|
341
|
+ $weather .= $tomorrow.'日气温:'.$value['temperature'];
|
|
342
|
+ }
|
|
343
|
+ }
|
|
344
|
+
|
|
345
|
+ RedisModel::set($redisKey.'_'.$city, $weather);
|
|
346
|
+ $endTime = strtotime(date('Y-m-d 00:00:00',strtotime('+1 days'))) -1;
|
|
347
|
+ $expire = $endTime - time();
|
|
348
|
+ RedisModel::expire($redisKey.'_'.$city, $expire);
|
|
349
|
+ $sellerMemo = self::where('id', $order_id)->pluck('sellerMemo');
|
|
350
|
+ $sellerMemo = $sellerMemo.' '.$city.'天气状况:'.$weather;
|
|
351
|
+ self::where('id', $order_id)->update(['sellerMemo'=>$sellerMemo]);
|
|
352
|
+ }
|
|
353
|
+ }
|
|
354
|
+
|
|
355
|
+ return true;
|
|
356
|
+ }
|
309
|
357
|
}
|