cqpCow 1 год назад
Родитель
Сommit
0ce1a315d7
1 измененных файлов с 20 добавлено и 0 удалено
  1. 20 0
      app/Service/CustomerService.php

+ 20 - 0
app/Service/CustomerService.php

@@ -51,6 +51,12 @@ class CustomerService extends Service
             $model->save();
             $time = time();
 
+            $old = CustomerInfo::where('del_time',0)
+                ->where('customer_id',$data['id'])
+                ->whereIn('type',[CustomerInfo::type_five,CustomerInfo::type_six])
+                ->select('file')
+                ->get()->toArray();
+            $old = array_column($old,'file');
             CustomerInfo::where('del_time',0)
                 ->where('customer_id',$data['id'])
                 ->update(['del_time' => $time]);
@@ -108,6 +114,7 @@ class CustomerService extends Service
                 CustomerInfo::insert($insert);
             }
 
+            $new = [];
             if(! empty($data['img'])){
                 $insert = [];
                 foreach ($data['img'] as $value){
@@ -118,6 +125,7 @@ class CustomerService extends Service
                         'name' => $value['name'],
                         'crt_time' => $time,
                     ];
+                    $new[] = $value['url'];
                 }
                 CustomerInfo::insert($insert);
             }
@@ -132,6 +140,7 @@ class CustomerService extends Service
                         'name' => $value['name'],
                         'crt_time' => $time,
                     ];
+                    $new[] = $value['url'];
                 }
                 CustomerInfo::insert($insert);
             }
@@ -142,6 +151,8 @@ class CustomerService extends Service
             return [false,$exception->getMessage()];
         }
 
+        $this->delStorageFile($old, $new);
+
         return [true,''];
     }
 
@@ -287,6 +298,13 @@ class CustomerService extends Service
             Customer::where('id',$data['id'])->update([
                 'del_time'=> time()
             ]);
+            $old = CustomerInfo::where('del_time',0)
+                ->where('customer_id',$data['id'])
+                ->whereIn('type',[CustomerInfo::type_five,CustomerInfo::type_six])
+                ->select('file')
+                ->get()->toArray();
+            $old = array_column($old,'file');
+
             CustomerInfo::where('del_time',0)
                 ->where('customer_id',$data['id'])
                 ->update(['del_time' => time()]);
@@ -299,6 +317,8 @@ class CustomerService extends Service
             return [false,$exception->getMessage()];
         }
 
+        $this->delStorageFile($old);
+
         return [true,''];
     }