浏览代码

摄像头接口

任敬轩 4 月之前
父节点
当前提交
d125b24c1c
共有 1 个文件被更改,包括 30 次插入21 次删除
  1. 30 21
      Modules/Camera/Http/Controllers/Api/CameraApiController.php

+ 30 - 21
Modules/Camera/Http/Controllers/Api/CameraApiController.php

@@ -201,7 +201,7 @@ class CameraApiController extends BaseController
         return self::successResponse($data);
     }
 
-    //宁煤摄像头统计
+    //宁煤摄像头统计
     public function getTotalNingmeiWeek(){
         $result['status'] = true;
         $result['msg']    = ApiEnum::RETURN_SUCCESS;
@@ -211,7 +211,8 @@ class CameraApiController extends BaseController
         $data = [];
 
         if($type == 'nmjt' || $type == ''){
-            $list = DB::table('camera_status_history')->where('title','宁煤公司')->where('date', '<=', date('Y-m-d H:i:s', strtotime('-7 days')))->get();
+            $list = DB::table('camera_status_history')->where('title','宁煤公司')->where('date', '>=', date('Y-m-d H:i:s', strtotime('-7 days')))->get();
+
             $total = 0;
             $total_online = 0;
             $totle_offline = 0;
@@ -220,24 +221,27 @@ class CameraApiController extends BaseController
                 for($i=0;$i<count($list);$i++){
                     $total = $total + $list[$i]->total;
                     $total_online = $total_online + $list[$i]->total_online;
-                    $totle_offline = $totle_offline + $list[$i]->totle_offline;
+                    $totle_offline = $totle_offline + $list[$i]->total_offline;
                     $rate = $rate + $list[$i]->rate;
                 }
+
+                array_push($data,[
+                    'title'=>           $list[0]->title,
+                    'mine_code'=>       $list[0]->mine_code,
+                    'total'=>           $total/count($list),
+                    'total_online'=>    $total_online/count($list),
+                    'total_offline'=>   $totle_offline/count($list),
+                    'rate'=>            $rate/count($list)
+                ]);
             }
-            array_push($data,[
-                'title'=>           $list[0]->title,
-                'mine_code'=>       $list[0]->mine_code,
-                'total'=>           $total/count($list),
-                'total_online'=>    $total_online/count($list),
-                'total_offline'=>   $totle_offline/count($list),
-                'rate'=>            $rate/count($list)
-            ]);
         }
 
         if($type == 'nmjt'){
             return self::successResponse($data);
         }
 
+        $id_list = [];
+
         //宁煤下各矿在离线数量
         if($type == 'mtdw'){
             $id_list = ['1941', '1982', '2019', '2099', '2160', '2181', '2193', '2226', '2258', '2307', '2308', '2323', '2324', '2345', '2376', '2405', '2923', '2427', '2429', '6157'];
@@ -250,12 +254,16 @@ class CameraApiController extends BaseController
             $id_list = ['2628', '2599', '2600', '2611', '3167'];
         }elseif($type == 'gfx'){
             $id_list = ['4272'];
+        }else{
+            $id_list = ['1941', '1982', '2019', '2099', '2160', '2181', '2193', '2226', '2258', '2307', '2308', '2323', '2324', '2345', '2376', '2405', '2923', '2427', '2429', '6157','2447', '2525', '2557', '2576', '3868', '2597', '3452','6001','2628', '2599', '2600', '2611', '3167','4272'];
         }
 
         $unit_list = DB::table('mine_list')->whereIn('id',$id_list)->pluck('title');
+
         if(count($unit_list) > 0){
             for($i=0;$i<count($unit_list);$i++){
-                $list = DB::table('camera_status_history')->where('title',$unit_list[$i])->where('date', '<=', date('Y-m-d H:i:s', strtotime('-7 days')))->get();
+                $list = DB::table('camera_status_history')->where('title',$unit_list[$i])->where('date', '>=', date('Y-m-d H:i:s', strtotime('-7 days')))->get();
+
                 $total = 0;
                 $total_online = 0;
                 $totle_offline = 0;
@@ -264,18 +272,19 @@ class CameraApiController extends BaseController
                     for($j=0;$j<count($list);$j++){
                         $total = $total + $list[$j]->total;
                         $total_online = $total_online + $list[$j]->total_online;
-                        $totle_offline = $totle_offline + $list[$j]->totle_offline;
+                        $totle_offline = $totle_offline + $list[$j]->total_offline;
                         $rate = $rate + $list[$j]->rate;
                     }
+
+                    array_push($data,[
+                        'title'=>           $unit_list[$i],
+                        'mine_code'=>       $list[0]->mine_code,
+                        'total'=>           $total/count($list),
+                        'total_online'=>    $total_online/count($list),
+                        'total_offline'=>   $totle_offline/count($list),
+                        'rate'=>            $rate/count($list)
+                    ]);
                 }
-                array_push($data,[
-                    'title'=>           $unit_list[$i],
-                    'mine_code'=>       $list[0]->mine_code,
-                    'total'=>           $total/count($list),
-                    'total_online'=>    $total_online/count($list),
-                    'total_offline'=>   $totle_offline/count($list),
-                    'rate'=>            $rate/count($list)
-                ]);
             }
         }