zgg 16 часов назад
Родитель
Сommit
7388d8f120
1 измененных файлов с 47 добавлено и 7 удалено
  1. 47 7
      application/api/controller/screen/Patrol.php

+ 47 - 7
application/api/controller/screen/Patrol.php

@@ -21,6 +21,16 @@ class Patrol extends Index
             $dates2[] = $startDate->format('Ymd');
             $startDate->add(new \DateInterval('P1D'));
         }
+        $map[] = ['del','=',0];
+        $map[] = ['enable','=',1];
+        $map[] = ['org_id','=',$this->orgId];
+        $cateIds = Db::name('device_cate')
+            ->where(function ($query) {
+                $query->whereOr('title', 'like','%消防栓%');
+                $query->whereOr('title', 'like','%灭火器%');
+            })
+            ->where($map)
+            ->column('id');
         $list = [];
          foreach ($dates as $k=>$v){
              $count = $lists = Db::name('device_record')
@@ -28,7 +38,7 @@ class Patrol extends Index
                 ->join('device d', 'd.id=dr.device_id')
                 ->field('dr.*,d.title as device_name,d.content as device_details')
                 ->where('dr.org_id',$this->orgId)
-                ->where('cate_id','in',[22,23])
+                ->whereIn('cate_id',$cateIds)
                 ->where('create_yyyymmdd',$dates2[$k])
                 ->count();
             $list[$k] = $count>0 ? $count : 0;
@@ -41,12 +51,22 @@ class Patrol extends Index
         HelpHander::success($data);
     }
     public function patrolImg4(){
+        $map[] = ['del','=',0];
+        $map[] = ['enable','=',1];
+        $map[] = ['org_id','=',$this->orgId];
+        $cateIds = Db::name('device_cate')
+            ->where(function ($query) {
+                $query->whereOr('title', 'like','%消防栓%');
+                $query->whereOr('title', 'like','%灭火器%');
+            })
+            ->where($map)
+            ->column('id');
          $data =  Db::name('device_record')
                 ->alias('dr')
                 ->join('device d', 'd.id=dr.device_id')
                 ->field('dr.*,d.title as device_name,d.content as device_details')
                 ->where('dr.org_id',$this->orgId)
-                ->where('cate_id','in',[22,23])
+                ->whereIn('cate_id',$cateIds)
                 ->order('dr.id desc')
                 ->limit(30)
                 ->select();
@@ -67,12 +87,22 @@ class Patrol extends Index
         HelpHander::success($eList);
     }
     public function patrolDevice(){
+        $map[] = ['del','=',0];
+        $map[] = ['enable','=',1];
+        $map[] = ['org_id','=',$this->orgId];
+        $cateIds = Db::name('device_cate')
+            ->where(function ($query) {
+                $query->whereOr('title', 'like','%消防栓%');
+                $query->whereOr('title', 'like','%灭火器%');
+            })
+            ->where($map)
+            ->column('id');
          $lists = Db::name('device_record')
                 ->alias('dr')
                 ->join('device d', 'd.id=dr.device_id')
                 ->field('dr.*,d.title as device_name,d.content as device_details')
                 ->where('dr.org_id',$this->orgId)
-                ->where('cate_id','in',[22,23])
+                ->whereIn('cate_id',$cateIds)
                 ->order('dr.id desc')
                 ->limit(30)
                 ->select();
@@ -94,11 +124,21 @@ class Patrol extends Index
     }
 
     public function newData(){
-        $map[] = ['cate_id','in',[22,23]];
+
         $map[] = ['del','=',0];
         $map[] = ['enable','=',1];
         $map[] = ['org_id','=',$this->orgId];
-        $count1 = Db::name('device')->where($map)->count();
+        $cateIds = Db::name('device_cate')
+            ->where(function ($query) {
+                $query->whereOr('title', 'like','%消防栓%');
+                $query->whereOr('title', 'like','%灭火器%');
+            })
+            ->where($map)
+            ->column('id');
+        $count1 = Db::name('device')
+            ->whereIn('cate_id',$cateIds)
+            ->where($map)
+            ->count();
 //        $count1 = Db::name('address')
 //            ->where('org_id',$this->orgId)
 //            ->where('enable',1)
@@ -136,7 +176,7 @@ class Patrol extends Index
         $count4 = Db::name('device_record')
             ->alias('a')
             ->join('device b','a.device_id = b.id')
-            ->where('b.cate_id','in',[22,23])
+            ->whereIn('b.cate_id',$cateIds)
             ->where('a.org_id',$this->orgId)
             ->where('a.create_yyyymm',date("Ym"))
             ->count();
@@ -159,7 +199,7 @@ class Patrol extends Index
         if($task > 0 ){
             $count5 = round($task1/$task*100,1);
         }
-         $data = [
+        $data = [
             'count1' => $count1,
             'count2' => $count2,
             'count3' => $count3,