cqp 11 months ago
parent
commit
8afbeb9b30
1 changed files with 39 additions and 13 deletions
  1. 39 13
      app/Service/ReportFormsService.php

+ 39 - 13
app/Service/ReportFormsService.php

@@ -135,20 +135,46 @@ class ReportFormsService extends Service
         $return_time = $this->getTimeAreaData($new_finish_time);
         $return_time = $this->getTimeAreaData($new_finish_time);
 
 
         //检索分表数据
         //检索分表数据
+        $batchSize = 1000; // 每次处理的数据量
         $result = $team = [];
         $result = $team = [];
         foreach ($return_time as $value){
         foreach ($return_time as $value){
-            //子表搜索
-            $models = new OrdersProductProcess(['channel' => $value]);
-            $tmp = $models->where('del_time',0)
-                ->whereBetween('finished_time',[$data['finish_time'][0], $data['finish_time'][1]])
-                ->where('status',2)
-                ->when(!empty($team_id), function ($query) use ($team_id) {
-                    return $query->whereIn('team_id', $team_id);
-                })
-                ->select('team_id','finished_time','production_no')
-                ->get()->toArray();//完工数据
-            $result = array_merge_recursive($result,$tmp);
-            $team = array_merge_recursive($team,array_unique(array_column($tmp,'team_id')));
+            $offset = 0;
+            $hasMoreData = true;
+
+            while ($hasMoreData) {
+                // 子表搜索
+                $models = new OrdersProductProcess(['channel' => $value]);
+                $tmp = $models->where('del_time', 0)
+                    ->whereBetween('finished_time', [$data['finish_time'][0], $data['finish_time'][1]])
+                    ->where('status', 2)
+                    ->when(!empty($team_id), function ($query) use ($team_id) {
+                        return $query->whereIn('team_id', $team_id);
+                    })
+                    ->skip($offset) // 跳过前面的数据
+                    ->take($batchSize) // 获取固定数量的数据
+                    ->select('team_id', 'finished_time', 'production_no')
+                    ->get()->toArray(); // 完工数据
+
+                if (empty($tmp)) {
+                    $hasMoreData = false;
+                } else {
+                    $result = array_merge_recursive($result, $tmp);
+                    $team = array_merge_recursive($team, array_unique(array_column($tmp, 'team_id')));
+                    $offset += $batchSize;
+                }
+            }
+//            //子表搜索
+//            $models = new OrdersProductProcess(['channel' => $value]);
+//            $tmp = $models->where('del_time',0)
+//                ->whereBetween('finished_time',[$data['finish_time'][0], $data['finish_time'][1]])
+//                ->where('status',2)
+//                ->when(!empty($team_id), function ($query) use ($team_id) {
+//                    return $query->whereIn('team_id', $team_id);
+//                })
+//                ->select('team_id','finished_time','production_no')
+//                ->get()->toArray();//完工数据
+//            $result = array_merge_recursive($result,$tmp);
+//            $team = array_merge_recursive($team,array_unique(array_column($tmp,'team_id')));
         }
         }
 
 
         if(empty($result)) return [true , []];
         if(empty($result)) return [true , []];
@@ -228,7 +254,7 @@ class ReportFormsService extends Service
         $newStartTimestamp = strtotime('-3 months', $time_area[0]);
         $newStartTimestamp = strtotime('-3 months', $time_area[0]);
         $newEndTimestamp = strtotime('+3 months', $time_area[1]);
         $newEndTimestamp = strtotime('+3 months', $time_area[1]);
 
 
-        return [$newStartTimestamp,$newEndTimestamp];
+        return [$time_area[0],$time_area[1]];
     }
     }
 
 
     /**
     /**