|
@@ -25,5 +25,53 @@ class FxOrder extends Model
|
25
|
25
|
public static function createOuterCode(){
|
26
|
26
|
$order_sn = 'fx'.rand(100, 9999). substr(time(), 5, 5). rand(10, 9999);
|
27
|
27
|
return $order_sn;
|
28
|
|
- }
|
|
28
|
+ }
|
|
29
|
+
|
|
30
|
+ /*更新城市天气信息*/
|
|
31
|
+ public static function updateWeather($order_id) {
|
|
32
|
+ $redisKey = 'seafood_order_city_weather';
|
|
33
|
+ $appKey = '32c8f844f8055f70f702fc28ec930e52';
|
|
34
|
+ //查询订单收件人所在的城市(过滤关键字 市)
|
|
35
|
+ $city = self::where('id', $order_id)->pluck('receiverCity');
|
|
36
|
+ $city = str_replace('市','',$city);
|
|
37
|
+ $specialCity = array('朝阳区','嘉定区','海淀区','昌平区','密云区','大兴区','房山区','通州区','普陀区',);
|
|
38
|
+ if(in_array($city, $specialCity)) {
|
|
39
|
+ $city = str_replace('区','',$city);
|
|
40
|
+ }
|
|
41
|
+ //查询redis中是否有该键,若没有则查询
|
|
42
|
+ $weather = RedisModel::get($redisKey.'_'.$city);
|
|
43
|
+ if($weather) {
|
|
44
|
+ $sellerMemo = self::where('id', $order_id)->pluck('sellerMemo');
|
|
45
|
+ $sellerMemo = $sellerMemo.' '.$city.'天气状况:'.$weather;
|
|
46
|
+ self::where('id', $order_id)->update(['sellerMemo'=>$sellerMemo]);
|
|
47
|
+ } else {
|
|
48
|
+ $url = 'http://apis.juhe.cn/simpleWeather/query?city='.urlencode($city).'&key='.$appKey;
|
|
49
|
+ $result = file_get_contents($url);
|
|
50
|
+ $result = json_decode($result, true);
|
|
51
|
+ if($result['error_code'] == '0') {
|
|
52
|
+ //将数据缓存到redis里
|
|
53
|
+ $today = date('Y-m-d',time());
|
|
54
|
+ $tomorrow = date('Y-m-d',strtotime('+1 days'));
|
|
55
|
+ $weather = '';
|
|
56
|
+ foreach ($result['result']['future'] as $value) {
|
|
57
|
+ if($value['date'] == $today) {
|
|
58
|
+ $weather .= $today.'日气温:'.$value['temperature'].'; ';
|
|
59
|
+ }
|
|
60
|
+ if($value['date'] == $tomorrow) {
|
|
61
|
+ $weather .= $tomorrow.'日气温:'.$value['temperature'];
|
|
62
|
+ }
|
|
63
|
+ }
|
|
64
|
+
|
|
65
|
+ RedisModel::set($redisKey.'_'.$city, $weather);
|
|
66
|
+ $endTime = strtotime(date('Y-m-d 00:00:00',strtotime('+1 days'))) -1;
|
|
67
|
+ $expire = $endTime - time();
|
|
68
|
+ RedisModel::expire($redisKey.'_'.$city, $expire);
|
|
69
|
+ $sellerMemo = self::where('id', $order_id)->pluck('sellerMemo');
|
|
70
|
+ $sellerMemo = $sellerMemo.' '.$city.'天气状况:'.$weather;
|
|
71
|
+ self::where('id', $order_id)->update(['sellerMemo'=>$sellerMemo]);
|
|
72
|
+ }
|
|
73
|
+ }
|
|
74
|
+
|
|
75
|
+ return true;
|
|
76
|
+ }
|
29
|
77
|
}
|