Browse Source

订单同步到卖家云之前查询收货人所在城市天气状况并更新到卖家备注当中

shensong 5 years ago
parent
commit
1cf2fd7435

+ 2 - 0
app/Console/Commands/SyncOrderToMj.php

@@ -98,6 +98,8 @@ class SyncOrderToMj extends Command {
98 98
                     FxOrderGoodsSkus::where('order_id', $id)->where('is_del', 0)->update($mj_status);
99 99
                 }
100 100
             }else{
101
+                #新加逻辑 查询收件人所在城市天气情况并更新
102
+                FxOrder::updateWeather($id);
101 103
                 $res = $this->syncFxOrderToMj($id);
102 104
                 if(!$res){
103 105
                     echo "\n订单ID:".$id." 同步失败";

+ 49 - 1
app/FxOrder.php

@@ -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
 }

+ 2 - 2
app/Http/Controllers/Admin/FxOrderController.php

@@ -1008,7 +1008,7 @@ class FxOrderController extends Controller
1008 1008
                     //其他仓变C仓           
1009 1009
                     if(empty($mjOrder)){
1010 1010
                         #新加逻辑 查询收件人所在城市天气情况并更新
1011
-                        Order::updateWeather($id);
1011
+                        FxOrder::updateWeather($id);
1012 1012
 
1013 1013
                         $mj_in = $this->syncOrderToMj($id, $orderSkus);
1014 1014
                         if( $mj_in == false ){
@@ -1276,7 +1276,7 @@ class FxOrderController extends Controller
1276 1276
                 #如果审核通过,c仓, 并且到预发货时间,同步卖家云
1277 1277
                 if($order->status == 2 && $order->warehouse == 3 && $order->delivery_date <= $today_date){
1278 1278
                     #新加逻辑 查询收件人所在城市天气情况并更新
1279
-                    Order::updateWeather($id);
1279
+                    FxOrder::updateWeather($id);
1280 1280
 
1281 1281
                     $syncMj = $this->syncOrderToMj($id);
1282 1282
                     if( $syncMj == false ){