cqpCow 1 year ago
parent
commit
b915318866
1 changed files with 17 additions and 0 deletions
  1. 17 0
      app/Service/ConstructionService.php

+ 17 - 0
app/Service/ConstructionService.php

@@ -75,6 +75,11 @@ class ConstructionService extends Service
             ConstructionProductInfo::where('del_time',0)
                 ->where('construction_id',$data['id'])
                 ->update(['del_time' => $time]);
+            $old = ConstructionFile::where('del_time',0)
+                ->where('construction_id',$data['id'])
+                ->select('file')
+                ->get()->toArray();
+            $old = array_column($old,'file');
             ConstructionFile::where('del_time',0)
                 ->where('construction_id',$data['id'])
                 ->update(['del_time' => $time]);
@@ -131,6 +136,7 @@ class ConstructionService extends Service
 
             if(! empty($data['schedule_info_id'])) ScheduleInfo::where('id',$data['schedule_info_id'])->update(['is_use' => 1]);
 
+            $new = [];
             if(! empty($data['file'])){
                 $insert = [];
                 foreach ($data['file'] as $value){
@@ -142,6 +148,7 @@ class ConstructionService extends Service
                         'mark' => $value['mark'] ?? "",
                         'crt_time' => $time,
                     ];
+                    $new[]= $value['url'];
                 }
                 ConstructionFile::insert($insert);
             }
@@ -152,6 +159,8 @@ class ConstructionService extends Service
             return [false,$exception->getMessage()];
         }
 
+        $this->delStorageFile($old, $new);
+
         return [true,''];
     }
 
@@ -298,6 +307,12 @@ class ConstructionService extends Service
             ConstructionInfo::where('del_time',0)
                 ->where('construction_id',$data['id'])
                 ->update(['del_time' => time()]);
+            $old = ConstructionFile::where('del_time',0)
+                ->where('construction_id',$data['id'])
+                ->select('file')
+                ->get()->toArray();
+            $old = array_column($old,'file');
+
             ConstructionFile::where('del_time',0)
                 ->where('construction_id',$data['id'])
                 ->update(['del_time' => time()]);
@@ -324,6 +339,8 @@ class ConstructionService extends Service
             return [false,$exception->getMessage()];
         }
 
+        $this->delStorageFile($old);
+
         return [true,''];
     }