Переглянути джерело

拆分外委、自营数据

qr 6 місяців тому
батько
коміт
37a7f61ccd

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

@@ -2907,6 +2907,7 @@ class CameraApiController extends BaseController
     //导出总表
     public function export1(Request $request){
         $params = $request->all();
+
         if(isset($params['date'])){
             $date = $params['date'];
         }else{
@@ -2928,9 +2929,13 @@ class CameraApiController extends BaseController
         $risk_list = DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->whereDate('create_time', $date)->where('is_delete',0)->get();
         // 洗煤厂数据
         $coal_washery_list = DB::connection('mysql_fwe10')->table('uf_xx_coal_washery')->where('is_delete',0)->orderBy('sort')->get();
-        $col_washery_dict = [];
+
+
+        $coal_washery_dict = [];
+        $coal_washery_type_dict = [];
         foreach ($coal_washery_list as $key=>$value) {
-            $col_washery_dict[$value->ID] = $value;
+            $coal_washery_dict[$value->ID] = $value;
+            $coal_washery_type_dict[$value->ID] = $value->obj_type;
         }
 
         $res = [
@@ -2941,11 +2946,15 @@ class CameraApiController extends BaseController
             "ziying"    => 0,
             "waiwei"    => 0,
             "risk_info" => "",
-            "table_list" => [],
+            "ziying_list"   => [],
+            "waiwei_list"   => [],
+            "table_list"    => [],
         ];
         $risk_zhong_con = [];
         $risk_gao_con = [];
         $coal_washery_risk_list = [];
+        $coal_washery_risk_waiwei = [];
+        $coal_washery_risk_ziying = [];
 
         foreach ($risk_list as $key=>$value) {
             // 风险数量统计
@@ -2971,7 +2980,7 @@ class CameraApiController extends BaseController
 
             // 洗煤厂类型统计
             $col_washery_id = $value->coal_washery_id;
-            $col_washery_type = $col_washery_dict[$col_washery_id]->obj_type;
+            $col_washery_type = $coal_washery_dict[$col_washery_id]->obj_type;
             if($col_washery_type == 0) {
                 $res['ziying']++;
             } else if ($col_washery_type == 1) {
@@ -2985,7 +2994,9 @@ class CameraApiController extends BaseController
 
         $coal_list = [];
         $index = 0;
-        foreach ($col_washery_dict as $key => $value) {
+        $index_ziying = 0;
+        $index_waiwei = 0;
+        foreach ($coal_washery_dict as $key => $value) {
             $id = $value->ID;
             if (isset($coal_washery_risk_list[$id])) {
                 $index++;
@@ -3020,11 +3031,10 @@ class CameraApiController extends BaseController
                     }
                 }
                 $level_total = '';
-                if ($gao > 0) $level_total .= '高风险'.$gao.'项 ';
+                if ($gao   > 0) $level_total .= '高风险'.$gao.'项 ';
                 if ($zhong > 0) $level_total .= '中风险'.$zhong.'项 ';
-                if ($di > 0) $level_total .= '低风险'.$di.'项 ';
-
-                $coal_list[] = [
+                if ($di    > 0) $level_total .= '低风险'.$di.'项 ';
+                $line = [
                     'index' => $index,
                     'unit' => $v->unit,
                     'coal_washery' => $value->title,
@@ -3038,6 +3048,19 @@ class CameraApiController extends BaseController
                     'reviewer' => implode(',', $reviewer),
                     'id' => $value->ID,
                 ];
+                $coal_list[] = $line;
+
+                // 自营、外委
+                if (isset($coal_washery_type_dict[$id])) {
+                    $coal_washery_type = $coal_washery_type_dict[$id];
+                    if ($coal_washery_type == 0) {
+                        $line['index'] = ++ $index_ziying;
+                        $res["ziying_list"][] = $line;
+                    } else {
+                        $line['index'] = ++ $index_waiwei;
+                        $res["waiwei_list"][] = $line;
+                    }
+                }
             }
         }
         $res['table_list'] = $coal_list;