cqp il y a 2 semaines
Parent
commit
79edbe6555
2 fichiers modifiés avec 30 ajouts et 10 suppressions
  1. 12 6
      app/Service/DeviceService.php
  2. 18 4
      app/Service/StatisticsService.php

+ 12 - 6
app/Service/DeviceService.php

@@ -179,14 +179,20 @@ class DeviceService extends Service
             $model->where('crt_time','>=',$return[0]);
             $model->where('crt_time','<=',$return[1]);
         }
-        $model->when(!empty($data['power']), function ($query) use ($data) {
+        if(! empty($data['power'])){
             $power = $data['power'];
-            $operators = [1 => '>', 2 => '=', 3 => '<'];
-
-            if (isset($operators[$power['type']])) {
-                $query->where('power', $operators[$power['type']], $power['value']);
+            $type = $power['type'];
+
+            if($type == 1){
+                $str = '>';
+            }elseif ($type == 2){
+                $str = '=';
+            }else{
+                $str = '<';
             }
-        });
+            $value = $power['value'] ?? '';
+            $model->where('power',$str, $value);
+        }
 
         return $model;
     }

+ 18 - 4
app/Service/StatisticsService.php

@@ -304,12 +304,19 @@ class StatisticsService extends Service
             $device[$key]['type_title'] = Device::$type[$value['type']] ?? "";
             $device[$key]['type_2_title'] = Device::$type_2[$value['type_2']] ?? "";
 
-            $rate_one = "100";
+            //应有占比
+            if($value['type_2'] == Device::type_one){
+                $rate_one = "100";
+            } else{
+                $rate_one = "10";
+            }
+            $rate_one = $rate_one . "%";
             $device[$key]['rate_one'] = $rate_one . "%";
             $rate_two = floatval($rd_total_hours) > 0.0 ? bcdiv($rd_total_hours, $set_total_hours,2) : 0;
             $rate_two = bcmul($rate_two, 100,2);
             $device[$key]['rate_two'] = $rate_two . "%";
-            $device[$key]['rate_three'] = $rate_two . "%";
+            $rate_three = bcmul(bcdiv($rate_two, $rate_one,2),100,2);
+            $device[$key]['rate_three'] = $rate_three . "%";
         }
 
         return $device;
@@ -562,11 +569,18 @@ class StatisticsService extends Service
             $device[$key]['type_2_title'] = Device::$type_2[$value['type_2']] ?? "";
 
             // 百分比计算
-            $device[$key]['rate_one'] = "100%";
+            //应有占比
+            if($value['type_2'] == Device::type_one){
+                $rate_one = "100";
+            } else{
+                $rate_one = "10";
+            }
+            $device[$key]['rate_one'] = $rate_one . "%";
             $rate_two = floatval($rd_total_hours) > 0.0 ? bcdiv($rd_total_hours, $set_total_hours,2) : 0;
             $rate_two = bcmul($rate_two, 100,2);
             $device[$key]['rate_two'] = $rate_two;
-            $device[$key]['rate_three'] = $rate_two;
+            $rate_three = bcmul(bcdiv($rate_two, $rate_one,2),100,2);
+            $device[$key]['rate_three'] = $rate_three . "%";
         }
 
         // --- 合计逻辑 ---