cqpCow 1 年之前
父節點
當前提交
10b49f7294
共有 1 個文件被更改,包括 47 次插入1 次删除
  1. 47 1
      app/Service/ScreenService.php

+ 47 - 1
app/Service/ScreenService.php

@@ -439,9 +439,11 @@ class ScreenService extends Service
             'district' => '',
             'location' => [],
             'temperature' => [],
-            'humidity' => []
+            'humidity' => [],
+            'screen_num' => 1,
         ];
 
+        //选中仓的 传感器设备和定位设备信息
         $device = ScreenDevice::from('screen_device as a')
             ->leftJoin('device as b','b.id','a.device_id')
             ->whereIn('b.device_type_id',[DeviceType::type_one,DeviceType::type_four])
@@ -492,6 +494,34 @@ class ScreenService extends Service
         $result['temperature'] = $chart['temperature'];
         $result['humidity'] = $chart['humidity'];
 
+        //同一区域有几个仓
+        $counts = ScreenDevice::from('screen_device as a')
+            ->leftJoin('device as b','b.id','a.device_id')
+            ->where('b.device_type_id',DeviceType::type_four)
+            ->where('a.del_time',0)
+            ->where('b.del_time',0)
+            ->where('a.screen_id','<>',$data['screen_id'])
+            ->select('b.code')
+            ->get()->toArray();
+        if(! empty($counts)){
+            $time = strtotime('-2 min',time());
+            $time = $time * 1000;
+            $model = SystemL::whereIn('device_no', $gps)
+                ->select('value','device_no')
+                ->orderBy('id','desc');
+            $model->where('time','>=',$time);
+            $return_other_gps = $model->get()->toArray();
+            if(! empty($return_other_gps)){
+                $code_p = [];
+                foreach ($return_other_gps as $value){
+                    if(! isset($code_p[$value['device_no']]) && $value['value']) $code_p[$value['device_no']] = $value['value'];
+                }
+                if(! empty($code_p)){
+                    $this->isSameLocation($code_p,$result);
+                }
+            }
+        }
+
         return [true, $result];
     }
 
@@ -628,4 +658,20 @@ class ScreenService extends Service
         }catch (\Exception $exception){
         }
     }
+
+    public function isSameLocation($position,&$result){
+        foreach ($position as $position_tmp){
+            $url = 'https://restapi.amap.com/v3/geocode/regeo?location='.$position_tmp.'&key='.SystemL::GaoDeMapKey;
+            try{
+                $return = $this->curlOpen($url);
+                $return = json_decode($return,true);
+                if(! empty($return['status'])){
+                    $position_arr = $return['regeocode']['addressComponent'] ?? [];
+                    $province = $position_arr['province'] ?? '';
+                    if($province == $result['province']) $result['screen_num'] += 1;
+                }
+            }catch (\Exception $exception){
+            }
+        }
+    }
 }