dyjh 6 년 전
부모
커밋
f74f1d214a
2개의 변경된 파일36개의 추가작업 그리고 10개의 파일을 삭제
  1. 27 10
      app/Http/Controllers/Admin/Album/ManufacturerController.php
  2. 9 0
      app/Http/Controllers/Admin/Controller.php

+ 27 - 10
app/Http/Controllers/Admin/Album/ManufacturerController.php

xqd
@@ -90,24 +90,41 @@ class ManufacturerController extends Controller
      */
     private function _updateSave() {
         $data = (array) request('data');
-        if(!empty($data['avatar']))
+        $saveData = AlbumManufacturerModel::where('store_id', $this->getStoreId())->first();
+        if (!empty($data['avatar'])) {
             $data['avatar'] = $this->formatImgUrl($data['avatar']);
+            $this->deleteUrl($saveData->avatar);
+        }
+        if (!empty($data['background_pic'])) {
+            $data['background_pic'] = $this->formatImgUrl($data['background_pic']);
+            $this->deleteUrl($saveData->background_pic);
+        }
+        if (!empty($data['advertising_pic'])) {
+            $data['advertising_pic'] = $this->formatImgUrl($data['advertising_pic']);
+            $this->deleteUrl($saveData->advertising_pic);
+        }
+        if (!empty($data['notice_icon'])) {
+            $data['notice_icon'] = $this->formatImgUrl($data['notice_icon']);
+            $this->deleteUrl($saveData->notice_icon);
+        }
+        if (!empty($data['furniture_ads_pic'])) {
+            $data['furniture_ads_pic'] = $this->formatImgUrl($data['furniture_ads_pic']);
+            $this->deleteUrl($saveData->furniture_ads_pic);
+        }
+
         if (!empty($data['banner']['url'])) {
             foreach ($data['banner']['url'] as $key => $val) {
                 $data['banner']['url'][$key] = $this->formatImgUrl($val);
             }
             $data['banner'] = json_encode($data['banner']['url']);
+            $banner = json_decode($data['banner'], true);
+            foreach ($banner as $val) {
+                $this->deleteUrl($val);
+            }
         }
-        if(!empty($data['background_pic']))
-            $data['background_pic'] = $this->formatImgUrl($data['background_pic']);
-        if(!empty($data['advertising_pic']))
-            $data['advertising_pic'] = $this->formatImgUrl($data['advertising_pic']);
-        if(!empty($data['notice_icon']))
-            $data['notice_icon'] = $this->formatImgUrl($data['notice_icon']);
-        if(!empty($data['furniture_ads_pic']))
-            $data['furniture_ads_pic'] = $this->formatImgUrl($data['furniture_ads_pic']);
 
-        $id = AlbumManufacturerModel::where('store_id',$this->getStoreId())->first()->id;
+
+        $id = $saveData->id;
         $ok = $this->repository->update($id,$data);
         if($ok) {
             return $this->showMessage('操作成功');

+ 9 - 0
app/Http/Controllers/Admin/Controller.php

xqd
@@ -52,6 +52,15 @@ abstract class Controller extends BaseController
         }
     }
 
+    public function deleteUrl($url)
+    {
+        $url = str_replace(env('CDN_URL'), public_path(), $url);
+        if (file_exists($url)) {
+            unlink($url);
+        }
+        return true;
+    }
+
     /**
      * 检测表单篡改
      *