Quellcode durchsuchen

电量油画布

unknown vor 1 Monat
Ursprung
Commit
b2be7a3049
1 geänderte Dateien mit 10 neuen und 6 gelöschten Zeilen
  1. 10 6
      application/api/controller/PowerManagement.php

+ 10 - 6
application/api/controller/PowerManagement.php

@@ -96,7 +96,6 @@ class PowerManagement extends Api
         // 查询电表数据并优化为一次性查询
         $machineIds = array_keys($machineList);
         $meterData = $this->getBatchMeterData($machineIds, [$monthLast, $month]);
-
         // 遍历机台列表
         foreach ($machineList as $machineId => $machineName) {
             $lastData = $meterData[$machineId][$monthLast] ?? [];
@@ -127,10 +126,15 @@ class PowerManagement extends Api
 
         // 根据机台ID和月份批量查询电表数据 (假设可用的电表数据模型)
         foreach ($months as $month) {
-            $data = db('设备_产量计酬') // 替换为真实的电表数据表
-            ->whereIn('sczl_jtbh', $machineIds)
-                ->where('开工时间', '>=', $month . '-01')
-                ->where('开工时间', '<=', $month . '-' . date('t', strtotime($month)))
+            $data = db('设备_产量计酬')
+                ->whereIn('sczl_jtbh', $machineIds)
+                ->where(function($query) use ($month) {
+                    $startDate = $month . '-01';
+                    $endDate = date('Y-m-d', strtotime($startDate . ' +1 month'));
+                    $query->where('开工时间', '>=', $startDate)
+                        ->where('开工时间', '<', $endDate);
+                })
+                ->fetchSql(true)
                 ->select();
 
             // 按设备编号和月份分组存储
@@ -192,7 +196,7 @@ class PowerManagement extends Api
         $list = db('设备_产量计酬')
             ->field('sczl_jtbh as 机台编号,开工时间,主电表,辅电表')
             ->where($where)
-            ->order('开工时间 desc')
+            ->order('sczl_rq desc')
             ->select();
         if (empty($list)){
             $this->error('未找到数据');