Browse Source

宁煤不在线摄像头接口修改

任敬轩 2 years ago
parent
commit
2e255d4bbf
1 changed files with 9 additions and 27 deletions
  1. 9 27
      Modules/Camera/Http/Controllers/Api/CameraApiController.php

+ 9 - 27
Modules/Camera/Http/Controllers/Api/CameraApiController.php

@@ -169,27 +169,25 @@ class CameraApiController extends BaseController
             }
         }
 
-        $mine_list = DB::table('mine_list')->where('parent_id',0)->where('slug','like','%'.$mine_code.'%')->where('deleted_at',null)->get();
+        if(count(explode('_',$mine_code)) > 1){
+            $mine_code = explode('_',$mine_code)[0];
+        }
 
-        $res = [];
+        $mine_list = DB::table('mine_list')->where('parent_id',0)->where('slug','like','%'.$mine_code.'%')->where('deleted_at',null)->get();
 
         //如果传参是宁煤显示全部
         if(isset($mine_list[0]->title) && $mine_list[0]->title == config('mine_hls')[0]){
             //宁煤在离线数量
-            $res['title'] = '宁煤公司';
-            $res['mine_code'] = $ningmei[0]->slug;
-            $res['total'] = DB::table('camera_list')->whereIn('mine_id',$mine_ningmei)->where('deleted_at',null)->count();
-            $res['total_online'] = DB::table('camera_list')->whereIn('mine_id',$mine_ningmei)->where('camera_status',1)->where('deleted_at',null)->count();
-            $res['total_offline'] = $res['total'] - $res['total_online'];
-            $res['rate'] = round($res['total_online'] / $res['total'] * 100,2)."%";
-            $res['offline_list'] = DB::table('camera_list')->select('id','camera_name','cover_picture','camera_status')->whereIn('mine_id',$mine_ningmei)->where('camera_status','!=',1)->where('deleted_at',null)->get();
+            $offline_list = DB::table('camera_list')->select('id','camera_name','cover_picture','camera_status')->whereIn('mine_id',$mine_ningmei)->where('camera_status','!=',1)->where('deleted_at',null)->get();
 
-            return self::successResponse($res);
+            return self::successResponse($offline_list);
         }
 
         //宁煤下各矿在离线数量
         $mine_list = DB::table('mine_list')->where('parent_id',$ningmei[0]->id)->where('slug','like','%'.$mine_code.'%')->where('deleted_at',null)->get();
 
+        $total_offline = [];
+
         foreach($mine_list as $k => $v){
             $mine_use = [];//宁煤下每个矿所有区域
             foreach($mine_all as $key=>$value){
@@ -200,26 +198,10 @@ class CameraApiController extends BaseController
                 }
             }
 
-            $total = DB::table('camera_list')->whereIn('mine_id',$mine_use)->where('is_show',1)->where('deleted_at',null)->count();
-            $total_online = DB::table('camera_list')->whereIn('mine_id',$mine_use)->where('is_show',1)->where('camera_status',1)->where('deleted_at',null)->count();
             $total_offline = DB::table('camera_list')->select('id','camera_name','cover_picture','camera_status')->whereIn('mine_id',$mine_use)->where('is_show',1)->where('camera_status','!=',1)->where('deleted_at',null)->get();
-
-            if($total == 0){
-                $rate = "0%";
-            }else{
-                $rate = round($total_online / $total * 100,2)."%";
-            }
-
-            $res['title'] = $v->title;
-            $res['mine_code'] = $v->slug."_jituan";
-            $res['total'] = $total;
-            $res['total_online'] = $total_online;
-            $res['total_offline'] = $total - $total_online;
-            $res['rate'] = $rate;
-            $res['offline_list'] = $total_offline;
         }
 
-        return self::successResponse($res);
+        return self::successResponse($total_offline);
     }
 
     //宁煤高风险摄像头