Explorar el Código

修改图片上传

cqpCow hace 10 meses
padre
commit
bc1063c255

+ 17 - 9
app/Http/Controllers/Api/FileUploadController.php

@@ -3,7 +3,9 @@ namespace App\Http\Controllers\Api;
 
 use App\Exports\MyExport;
 use App\Service\FileUploadService;
+use App\Service\OssService;
 use Illuminate\Http\Request;
+use PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions\F;
 
 //文件上传
 class FileUploadController extends BaseController
@@ -19,16 +21,22 @@ class FileUploadController extends BaseController
         }
     }
 
-    //获取文件的位置
+    //获取文件的位置预览(临时文件)
     public function getFile($file_name){
-        $path = storage_path() . "/app/public/upload_files/".$file_name;
-//        $ext = '';
-//        foreach (FileUploadService::FILE_TYPE as $value){
-//            if(file_exists($path. '.' . $value)){
-//                $ext = $value;
-//            }
-//        }
-//        if(empty($ext)) return ''; .'.'.$ext
+        $file_name = str_replace(FileUploadService::string2,'',$file_name);
+        $timestamp = substr($file_name, 0, 8); // 截取前八位数字
+        $date = \DateTime::createFromFormat('Ymd', $timestamp);
+        $date = $date->format('Y-m-d');
+        $path = storage_path() . "/app/public/" . FileUploadService::tmp_dir . '/' . $date. '/' . $file_name;
+
         return response()->file($path);
     }
+
+    //获取文件的位置
+    public function getFileLocal($file_name){
+        $path = storage_path() . "/app/public/upload_files/".$file_name;
+        if(file_exists($path)) return response()->file($path);
+
+        return "";
+    }
 }

+ 16 - 10
app/Service/ConstructionService.php

@@ -162,7 +162,13 @@ class ConstructionService extends Service
                         'mark' => $value['mark'] ?? "",
                         'crt_time' => $time,
                     ];
-                    $new[]= $value['url'];
+                    if(in_array($value['url'], $old)) {
+                        foreach ($old as $o_k => $o_v){
+                            if($o_v == $value['url']) unset($old[$o_k]);
+                        }
+                    }else{
+                        $new[] = $value['url'];
+                    }
                 }
                 ConstructionFile::insert($insert);
             }
@@ -173,8 +179,6 @@ class ConstructionService extends Service
             return [false,$exception->getMessage()];
         }
 
-        $this->delStorageFile($old, $new);
-
         if(! empty($data['check'])) {
             list($status,$msg) = (new CheckService())->checkAll([
                 "id" => $model->id,
@@ -182,10 +186,10 @@ class ConstructionService extends Service
                 "opt_case" => CheckService::five,
                 "menu_id" => $data['menu_id']
             ],$user);
-            if(! $status) return [true, '保存成功,施工单确认失败,异常信息:' . $msg];
+//            if(! $status) return [true, '保存成功,施工单确认失败,异常信息:' . $msg];
         }
 
-        return [true,''];
+        return [true, ['file' => ['new' => $new, 'old' => $old]]];
     }
 
     /**
@@ -286,6 +290,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){
@@ -297,6 +302,7 @@ class ConstructionService extends Service
                         'mark' => $value['mark'] ?? "",
                         'crt_time' => $time,
                     ];
+                    if(! empty($value['url'])) $new[] = $value['url'];
                 }
                 ConstructionFile::insert($insert);
             }
@@ -315,10 +321,10 @@ class ConstructionService extends Service
                 "opt_case" => CheckService::five,
                 "menu_id" => $data['menu_id']
             ],$user);
-            if(! $status) return [true, '保存成功,施工单确认失败,异常信息:' . $msg];
+//            if(! $status) return [true, '保存成功,施工单确认失败,异常信息:' . $msg];
         }
 
-        return [true,''];
+        return [true, ['file' => ['new' => $new]]];
     }
 
     /**
@@ -375,9 +381,7 @@ class ConstructionService extends Service
             return [false,$exception->getMessage()];
         }
 
-        $this->delStorageFile($old);
-
-        return [true,''];
+        return [true, ['file' => ['old' => $old]]];
     }
 
     /**
@@ -463,11 +467,13 @@ class ConstructionService extends Service
             ->where('construction_id',$construction['id'])
             ->select('id','construction_id','file','name','mark')
             ->get()->toArray();
+        $fileUploadService = new FileUploadService();
         foreach ($file as $value){
             $construction['file'][] = [
                 'url' => $value['file'],
                 'name' => $value['name'],
                 'mark' => $value['mark'],
+                'show_url' => $fileUploadService->getFileShow($value['file']),
             ];
         }
 

+ 23 - 9
app/Service/CustomerService.php

@@ -143,7 +143,13 @@ class CustomerService extends Service
                         'name' => $value['name'],
                         'crt_time' => $time,
                     ];
-                    $new[] = $value['url'];
+                    if(in_array($value['url'], $old)) {
+                        foreach ($old as $o_k => $o_v){
+                            if($o_v == $value['url']) unset($old[$o_k]);
+                        }
+                    }else{
+                        $new[] = $value['url'];
+                    }
                 }
                 CustomerInfo::insert($insert);
             }
@@ -158,7 +164,13 @@ class CustomerService extends Service
                         'name' => $value['name'],
                         'crt_time' => $time,
                     ];
-                    $new[] = $value['url'];
+                    if(in_array($value['url'], $old)) {
+                        foreach ($old as $o_k => $o_v){
+                            if($o_v == $value['url']) unset($old[$o_k]);
+                        }
+                    }else{
+                        $new[] = $value['url'];
+                    }
                 }
                 CustomerInfo::insert($insert);
             }
@@ -169,9 +181,7 @@ class CustomerService extends Service
             return [false,$exception->getMessage()];
         }
 
-        $this->delStorageFile($old, $new);
-
-        return [true,''];
+        return [true, ['file' => ['new' => $new, 'old' => $old]]];
     }
 
     /**
@@ -282,6 +292,7 @@ class CustomerService extends Service
                 CustomerInfo::insert($insert);
             }
 
+            $new = [];
             if(! empty($data['img'])){
                 $insert = [];
                 foreach ($data['img'] as $value){
@@ -292,6 +303,7 @@ class CustomerService extends Service
                         'name' => $value['name'],
                         'crt_time' => $time,
                     ];
+                    if(! empty($value['url'])) $new[] = $value['url'];
                 }
                 CustomerInfo::insert($insert);
             }
@@ -306,6 +318,7 @@ class CustomerService extends Service
                         'name' => $value['name'],
                         'crt_time' => $time,
                     ];
+                    if(! empty($value['url'])) $new[] = $value['url'];
                 }
                 CustomerInfo::insert($insert);
             }
@@ -319,7 +332,7 @@ class CustomerService extends Service
         $data['order_number'] = Customer::$order_number . "|" . $model->id . "|" . $data['title'];
         (new OperationLogService())->setOperationList($data,$user);
 
-        return [true,''];
+        return [true, ['file' => ['new' => $new]]];
     }
 
     /**
@@ -355,9 +368,7 @@ class CustomerService extends Service
             return [false,$exception->getMessage()];
         }
 
-        $this->delStorageFile($old);
-
-        return [true,''];
+        return [true, ['file' => ['old' => $old]]];
     }
 
     /**
@@ -444,6 +455,7 @@ class CustomerService extends Service
         $basic_map2 = BasicType::whereIn('id',array_unique(array_column($customer_info,'contact_type')))
             ->pluck('title','id')
             ->toArray();
+        $fileUploadService = new FileUploadService();
         foreach ($customer_info as $value){
             if($value['type'] == CustomerInfo::type_one){
                 $tmp = [
@@ -474,12 +486,14 @@ class CustomerService extends Service
                 $tmp = [
                     'url' => $value['file'],
                     'name' => $value['name'],
+                    'show_url' => $fileUploadService->getFileShow($value['file']),
                 ];
                 $customer['img'][] = $tmp;
             }elseif ($value['type'] == CustomerInfo::type_six){
                 $tmp = [
                     'url' => $value['file'],
                     'name' => $value['name'],
+                    'show_url' => $fileUploadService->getFileShow($value['file']),
                 ];
                 $customer['file'][] = $tmp;
             }elseif ($value['type'] == CustomerInfo::type_nine){

+ 93 - 1
app/Service/FileUploadService.php

@@ -19,6 +19,10 @@ class FileUploadService extends Service
         'xlsx',
         'xls'
     ];
+    const tmp_dir = 'upload_occ';
+    const string = '/api/uploadFiles/';
+    const string2 = 't9|';
+    const string3 = 't9/';
 
     public function uploadFile($file){
         if(empty($file)) return [false, '请上传文件'];
@@ -35,12 +39,100 @@ class FileUploadService extends Service
             return [false,$str];
         }
 
+        $date = date("Y-m-d");
+        //文件名
+        $file_name = date("Ymd").time().rand(1000,9999);
+        $filename =  $file_name.'.' . $ext;
+
+        $dir = self::tmp_dir . '/' . $date . '/' . $filename;
+        Storage::disk('public')->put($dir, file_get_contents($realPath));
+
+        return [true, self::string . self::string2 . $filename];
+    }
+
+    //获取文件的位置oss
+    public function getFileShow($file_name){
+        $path = "";
+        if(empty($file_name)) return $path;
+
+        $document = self::string3;
+        if(strpos($file_name, FileUploadService::string . FileUploadService::string2) !== false){
+            $file_name = str_replace(FileUploadService::string . FileUploadService::string2,'', $file_name);
+            $timestamp = substr($file_name, 0, 8); // 截取前八位数字
+            $date = \DateTime::createFromFormat('Ymd', $timestamp);
+            $date = $date->format('Y-m-d');
+            $savePath = $document . $date . '/' . $file_name;
+            list($status,$path) = (new OssService())->getTemporaryUrl($savePath);
+        }else{
+            if(strpos($file_name, FileUploadService::string) !== false){
+                $file_name = str_replace(FileUploadService::string ,'', $file_name);
+                $savePath = $document . 'old/upload_files/' . $file_name;
+                list($status,$path) = (new OssService())->getTemporaryUrl($savePath);
+            }
+        }
+
+        return $path;
+    }
+
+    public function uploadFileLocal($file){
+        if(empty($file)) return [false, '请上传文件'];
+        // 获取文件相关信息
+        $ext = $file->getClientOriginalExtension();     // 扩展名
+        $realPath = $file->getRealPath();   //临时文件的绝对路径
+
+        $ext = strtolower($ext);
+        if (! in_array($ext, self::FILE_TYPE)){
+            $str = '文件格式为:';
+            foreach (self::FILE_TYPE as $value){
+                $str.= $value . ' ' ;
+            }
+            return [false,$str];
+        }
+
         // 上传文件
         $file_name = date("Ymd").time().rand(1000,9999);
         $filename =  $file_name.'.' . $ext;
         // 使用我们新建的uploads本地存储空间(目录)
         Storage::disk('public')->put('upload_files/'.$filename, file_get_contents($realPath));
 
-        return [true,'/api/uploadFiles/'.$filename];
+        return [true, self::string . $filename];
+    }
+
+    public function createOssUpload($file){
+        if(! is_array($file) && empty($file)) return;
+        foreach ($file as $filename){
+            $filename = str_replace(FileUploadService::string.FileUploadService::string2,'', $filename);
+            $timestamp = substr($filename, 0, 8); // 截取前八位数字
+            $date = \DateTime::createFromFormat('Ymd', $timestamp);
+            $date = $date->format('Y-m-d');
+            $dir = FileUploadService::tmp_dir . '/' . $date . '/' . $filename;
+            $realPath = storage_path() . "/app/public/" . $dir;
+            $savePath = self::string3 . $date . '/' . $filename;
+            list($status,$msg) = (new OssService())->uploadFile($realPath,$savePath);
+            if($status) Storage::disk('public')->delete($dir);
+        }
+    }
+
+    public function createOssUploadOld($file){
+        if(! is_array($file) && empty($file)) return;
+
+        foreach ($file as $filename){
+            if(strpos($filename, FileUploadService::string.FileUploadService::string2) !== false){
+                $filename = str_replace(FileUploadService::string.FileUploadService::string2,'',$filename);
+                $timestamp = substr($filename, 0, 8); // 截取前八位数字
+                $date = \DateTime::createFromFormat('Ymd', $timestamp);
+                $date = $date->format('Y-m-d');
+                $delPath = self::string3 . $date . '/' . $filename;
+
+                list($status,$msg) = (new OssService())->deleteFile($delPath);
+//                if(! $status) return [false , $msg];
+            }else{
+                if(strpos($filename, FileUploadService::string) !== false){
+                    $filename = str_replace(FileUploadService::string,'',$filename);
+                    $delPath = self::string3 . 'old' . '/' . $filename;
+                    list($status,$msg) = (new OssService())->deleteFile($delPath);
+                }
+            }
+        }
     }
 }

+ 7 - 3
app/Service/FollowUpRecordService.php

@@ -12,7 +12,7 @@ use Illuminate\Support\Facades\DB;
 
 class FollowUpRecordService extends Service
 {
-    public function followUpRecordEdit($data,$user){
+    public function followUpRecordEdit($data,$user){return [true, ''];
         list($status,$msg) = $this->followUpRecordRule($data,false);
         if(!$status) return [$status,$msg];
 
@@ -80,6 +80,7 @@ class FollowUpRecordService extends Service
 
             $time = time();
 
+            $new = [];
             if(! empty($data['file'])){
                 $insert = [];
                 foreach ($data['file'] as $value){
@@ -90,6 +91,7 @@ class FollowUpRecordService extends Service
                         'type' => FollowUpRecordFile::type_one,
                         'crt_time' => $time,
                     ];
+                    if(! empty($value['url'])) $new[] = $value['url'];
                 }
                 FollowUpRecordFile::insert($insert);
             }
@@ -102,10 +104,10 @@ class FollowUpRecordService extends Service
 
         file_put_contents('follow_record.txt',date("Y-m-d H:i:s") . "请求参数:" . json_encode($data) . '操作人:' .$user['id'] . '|' .$user['emp_name'] . PHP_EOL,8);
 
-        return [true,''];
+        return [true, ['file' => ['new' => $new]]];
     }
 
-    public function followUpRecordDel($data){
+    public function followUpRecordDel($data){return [true, ''];
         if($this->isEmpty($data,'id')) return [false,'ID必须!'];
 
         try {
@@ -193,11 +195,13 @@ class FollowUpRecordService extends Service
         $sales_info = FollowUpRecordFile::where('del_time',0)
             ->where('follow_up_record_id',$data['id'])
             ->get()->toArray();
+        $fileUploadService = new FileUploadService();
         foreach ($sales_info as $value){
             if ($value['type'] == FollowUpRecordFile::type_one){
                 $record[] = [
                     'url' => $value['file'],
                     'name' => $value['name'],
+                    'show_url' => $fileUploadService->getFileShow($value['file']),
                 ];
             }
         }

+ 2 - 0
app/Service/OperationLogService.php

@@ -169,7 +169,9 @@ class OperationLogService extends Service
             ->select('follow_up_record_id','file','name')
             ->get()->toArray();
         $log_list3_detail_map = [];
+        $fileUploadService = new FileUploadService();
         foreach ($log_list3_detail as $value){
+            $value['file'] = $fileUploadService->getFileShow($value['file']);
             $log_list3_detail_map[$value['follow_up_record_id']][] = $value;
         }
         foreach ($log_list3 as $key => $value){

+ 16 - 10
app/Service/PaymentReceiptService.php

@@ -58,8 +58,14 @@ class PaymentReceiptService extends Service
                         'name' => $value['name'],
                         'crt_time' => $time,
                     ];
+                    if(in_array($value['url'], $old)) {
+                        foreach ($old as $o_k => $o_v){
+                            if($o_v == $value['url']) unset($old[$o_k]);
+                        }
+                    }else{
+                        $new[] = $value['url'];
+                    }
                 }
-                $new[]= $value['url'];
                 PaymentReceiptInfo::insert($insert);
             }
             if(! empty($data['employee_one'])){
@@ -96,8 +102,6 @@ class PaymentReceiptService extends Service
             return [false,$exception->getMessage()];
         }
 
-        $this->delStorageFile($old, $new);
-
         if(! empty($data['check'])) {
             list($status,$msg) = (new CheckService())->checkAll([
                 "id" => $data['id'],
@@ -105,10 +109,10 @@ class PaymentReceiptService extends Service
                 "opt_case" => CheckService::ten,
                 "menu_id" => $data['menu_id']
             ],$user);
-            if(! $status) return [true, '保存成功,收付款确认失败,异常信息:' . $msg];
+//            if(! $status) return [true, '保存成功,收付款确认失败,异常信息:' . $msg];
         }
 
-        return [true,''];
+        return [true, ['file' => ['new' => $new, 'old' => $old]]];
     }
 
     public function customerAdd($data,$user){
@@ -134,6 +138,7 @@ class PaymentReceiptService extends Service
             $model->save();
 
             $time = time();
+            $new = [];
             if(! empty($data['file'])){
                 $insert = [];
                 foreach ($data['file'] as $value){
@@ -144,6 +149,7 @@ class PaymentReceiptService extends Service
                         'name' => $value['name'],
                         'crt_time' => $time,
                     ];
+                    if(! empty($value['url'])) $new[] = $value['url'];
                 }
                 PaymentReceiptInfo::insert($insert);
             }
@@ -187,10 +193,10 @@ class PaymentReceiptService extends Service
                 "opt_case" => CheckService::ten,
                 "menu_id" => $data['menu_id']
             ],$user);
-            if(! $status) return [true, '保存成功,收付款确认失败,异常信息:' . $msg];
+//            if(! $status) return [true, '保存成功,收付款确认失败,异常信息:' . $msg];
         }
 
-        return [true,''];
+        return [true, ['file' => ['new' => $new]]];
     }
 
     public function customerDel($data){
@@ -223,9 +229,7 @@ class PaymentReceiptService extends Service
             return [false,$exception->getMessage()];
         }
 
-        $this->delStorageFile($old);
-
-        return [true,''];
+        return [true, ['file' => ['old' => $old]]];
     }
 
     public function customerDetail($data){
@@ -275,11 +279,13 @@ class PaymentReceiptService extends Service
             ->toArray();
 
         $customer['file'] = $customer['employee_one'] = [];
+        $fileUploadService = new FileUploadService();
         foreach ($file as $value){
             if($value['type'] == PaymentReceiptInfo::type_one){
                 $tmp = [
                     'url' => $value['file'],
                     'name' => $value['name'],
+                    'show_url' => $fileUploadService->getFileShow($value['file']),
                 ];
                 $customer['file'][] = $tmp;
             }elseif (in_array($value['type'],PaymentReceiptInfo::$man)){

+ 26 - 9
app/Service/ProductService.php

@@ -265,7 +265,13 @@ class ProductService extends Service
                         'name' => $value['name'],
                         'crt_time' => $time,
                     ];
-                    $new[] = $value['url'];
+                    if(in_array($value['url'], $old)) {
+                        foreach ($old as $o_k => $o_v){
+                            if($o_v == $value['url']) unset($old[$o_k]);
+                        }
+                    }else{
+                        $new[] = $value['url'];
+                    }
                 }
                 ProductInfo::insert($insert);
             }
@@ -279,7 +285,13 @@ class ProductService extends Service
                         'name' => $value['name'],
                         'crt_time' => $time,
                     ];
-                    $new[] = $value['url'];
+                    if(in_array($value['url'], $old)) {
+                        foreach ($old as $o_k => $o_v){
+                            if($o_v == $value['url']) unset($old[$o_k]);
+                        }
+                    }else{
+                        $new[] = $value['url'];
+                    }
                 }
                 ProductInfo::insert($insert);
             }
@@ -307,9 +319,7 @@ class ProductService extends Service
             return [false,$exception->getMessage()];
         }
 
-        $this->delStorageFile($old, $new);
-
-        return [true,''];
+        return [true, ['file' => ['new' => $new, 'old' => $old]]];
     }
 
     /**
@@ -354,6 +364,7 @@ class ProductService extends Service
                 $models->save();
             }
 
+            $new = [];
             if(! empty($data['img'])){
                 $insert = [];
                 foreach ($data['img'] as $value){
@@ -364,6 +375,7 @@ class ProductService extends Service
                         'name' => $value['name'],
                         'crt_time' => $time,
                     ];
+                    if(! empty($value['url'])) $new[] = $value['url'];
                 }
                 ProductInfo::insert($insert);
             }
@@ -378,6 +390,7 @@ class ProductService extends Service
                         'name' => $value['name'],
                         'crt_time' => $time,
                     ];
+                    if(! empty($value['url'])) $new[] = $value['url'];
                 }
                 ProductInfo::insert($insert);
             }
@@ -401,7 +414,7 @@ class ProductService extends Service
             return [false,$exception->getMessage()];
         }
 
-        return [true,''];
+        return [true, ['file' => ['new' => $new]]];
     }
 
     /**
@@ -444,8 +457,7 @@ class ProductService extends Service
             return [false,$exception->getMessage()];
         }
 
-        $this->delStorageFile($old,[]);
-        return [true,''];
+        return [true, ['file' => ['old' => $old]]];
     }
 
     /**
@@ -531,10 +543,12 @@ class ProductService extends Service
             ->where('product_id',$customer['id'])
             ->select('id','product_id','file','type','name')
             ->get()->toArray();
+        $fileUploadService = new FileUploadService();
         foreach ($customer_info as $value){
             $tmp = [
                 'url' => $value['file'],
                 'name' => $value['name'],
+                'show_url' => $fileUploadService->getFileShow($value['file']),
             ];
             if($value['type'] == ProductInfo::type_one){
                 $customer['img'][] = $tmp;
@@ -768,9 +782,12 @@ class ProductService extends Service
             ->where('type',ProductInfo::type_one)
             ->select('product_id','file','type','name')
             ->get()->toArray();
+        $fileUploadService = new FileUploadService();
         foreach ($customer_info as $value){
             if(isset($img[$value['product_id']])) continue;
-            $img[$value['product_id']] = $value['file'];
+            $url = "";
+            if(! empty($value['file'])) $url = $fileUploadService->getFileShow($value['file']);
+            $img[$value['product_id']] = $url;
         }
 
         return $img;

+ 16 - 8
app/Service/PurchaseOrderService.php

@@ -16,6 +16,7 @@ use App\Model\SalesOrder;
 use App\Model\SeeRange;
 use App\Model\Storehouse;
 use App\Model\Supplier;
+use Illuminate\Http\Request;
 use Illuminate\Support\Facades\DB;
 
 /**
@@ -98,7 +99,13 @@ class PurchaseOrderService extends Service
                         'name' => $value['name'],
                         'crt_time' => $time,
                     ];
-                    $new[] = $value['url'];
+                    if(in_array($value['url'], $old)) {
+                        foreach ($old as $o_k => $o_v){
+                            if($o_v == $value['url']) unset($old[$o_k]);
+                        }
+                    }else{
+                        $new[] = $value['url'];
+                    }
                 }
                 PurchaseOrderFile::insert($insert);
             }
@@ -109,9 +116,7 @@ class PurchaseOrderService extends Service
             return [false,$e->getMessage()];
         }
 
-        $this->delStorageFile($old,$new);
-
-        return [true,''];
+        return [true, ['file' => ['new' => $new, 'old' => $old]]];
     }
 
     /**
@@ -123,6 +128,7 @@ class PurchaseOrderService extends Service
     public function add($data,$user){
         list($status,$msg) = $this->orderRule($data, $user);
         if(!$status) return [$status,$msg];
+
         try{
             DB::beginTransaction();
             $material_model = new PurchaseOrder();
@@ -162,6 +168,7 @@ class PurchaseOrderService extends Service
                 PurchaseOrderInfo::insert($sub);
             }
 
+            $new = [];
             if(! empty($data['file'])){
                 $insert = [];
                 foreach ($data['file'] as $value){
@@ -173,6 +180,7 @@ class PurchaseOrderService extends Service
                         'name' => $value['name'],
                         'crt_time' => $time,
                     ];
+                    if(! empty($value['url'])) $new[] = $value['url'];
                 }
                 PurchaseOrderFile::insert($insert);
             }
@@ -185,7 +193,7 @@ class PurchaseOrderService extends Service
 
         (new OperationLogService())->setOperationList($data,$user);
 
-        return [true,''];
+        return [true, ['file' => ['new' => $new]]];
     }
 
     /**
@@ -235,11 +243,13 @@ class PurchaseOrderService extends Service
         $file = PurchaseOrderFile::where('del_time',0)
             ->where('order_number',$data['order_number'])
             ->get()->toArray();
+        $fileUploadService = new FileUploadService();
         foreach ($file as $value){
             if($value['type'] == PurchaseOrderFile::type_one){
                 $tmp = [
                     'url' => $value['file'],
                     'name' => $value['name'],
+                    'show_url' => $fileUploadService->getFileShow($value['file']),
                 ];
                 $order['file'][] = $tmp;
             }
@@ -318,9 +328,7 @@ class PurchaseOrderService extends Service
             return [false,$e->getMessage()];
         }
 
-        $this->delStorageFile($old);
-
-        return [true,''];
+        return [true, ['file' => ['old' => $old]]];
     }
 
     /**

+ 5 - 0
app/Service/SalesOrderService.php

@@ -392,6 +392,7 @@ class SalesOrderService extends Service
             $model->crt_time = $time;
             $model->save();
 
+            $new = [];
             if(! empty($order['file'])){
                 $insert = [];
                 foreach ($order['file'] as $value){
@@ -402,6 +403,7 @@ class SalesOrderService extends Service
                         'name' => $value['name'],
                         'crt_time' => $time,
                     ];
+                    if(! empty($value['url'])) $new[] = $value['url'];
                 }
                 PaymentReceiptInfo::insert($insert);
             }
@@ -429,6 +431,8 @@ class SalesOrderService extends Service
                 'crt_time' => $time,
             ];
             PaymentReceiptInfo::insert($insert);
+
+            if(! empty($new)) (new FileUploadService())->createOssUpload($new);
         }else{
             $order = $data['payment_receipt'];
             $orders->type = $order['type'];
@@ -908,6 +912,7 @@ class SalesOrderService extends Service
 
         //收付款信息
         if(! empty($data['payment_receipt']['order_number'])){
+            if(! isset($data['contract_fee'])) return [false, '合同金额不能为空'];
             if(empty($data['payment_receipt']['data_type'])) $data['payment_receipt']['data_type'] = PaymentReceipt::data_type_one;
             if(empty($data['payment_receipt']['data_order_no'])) $data['payment_receipt']['data_order_no'] = $data['payment_receipt']['order_number'];
             if(empty($data['payment_receipt']['type'])) return [false,'金额类型不能为空'];

+ 18 - 18
routes/api.php

@@ -112,17 +112,17 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
 
     //跟进记录
     $route->any('followUpRecordList', 'Api\FollowUpRecordController@followUpRecordList');
-    $route->any('followUpRecordEdit', 'Api\FollowUpRecordController@followUpRecordEdit');
-    $route->any('followUpRecordAdd', 'Api\FollowUpRecordController@followUpRecordAdd');
+    $route->any('followUpRecordEdit', 'Api\FollowUpRecordController@followUpRecordEdit')->middleware('OssFileDeal');
+    $route->any('followUpRecordAdd', 'Api\FollowUpRecordController@followUpRecordAdd')->middleware('OssFileDeal');
     $route->any('followUpRecordDetail', 'Api\FollowUpRecordController@followUpRecordDetail');
-    $route->any('followUpRecordDel', 'Api\FollowUpRecordController@followUpRecordDel');
+    $route->any('followUpRecordDel', 'Api\FollowUpRecordController@followUpRecordDel')->middleware('OssFileDeal');
 
     //客户
     $route->any('customerList', 'Api\CustomerController@customerList');
     $route->any('customerCapitalList', 'Api\CustomerController@customerList2');
-    $route->any('customerEdit', 'Api\CustomerController@customerEdit');
-    $route->any('customerAdd', 'Api\CustomerController@customerAdd');
-    $route->any('customerDel', 'Api\CustomerController@customerDel');
+    $route->any('customerEdit', 'Api\CustomerController@customerEdit')->middleware('OssFileDeal');
+    $route->any('customerAdd', 'Api\CustomerController@customerAdd')->middleware('OssFileDeal');
+    $route->any('customerDel', 'Api\CustomerController@customerDel')->middleware('OssFileDeal');
     $route->any('customerDetail', 'Api\CustomerController@customerDetail');
     $route->any('customerGrabbing', 'Api\CustomerController@customerGrabbing');
 
@@ -149,18 +149,18 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
 
     //产品名称
     $route->any('productList', 'Api\ProductController@productList');
-    $route->any('productEdit', 'Api\ProductController@productEdit');
-    $route->any('productAdd', 'Api\ProductController@productAdd');
-    $route->any('productDel', 'Api\ProductController@productDel');
+    $route->any('productEdit', 'Api\ProductController@productEdit')->middleware('OssFileDeal');
+    $route->any('productAdd', 'Api\ProductController@productAdd')->middleware('OssFileDeal');
+    $route->any('productDel', 'Api\ProductController@productDel')->middleware('OssFileDeal');
     $route->any('productDetail', 'Api\ProductController@productDetail');
     $route->any('productList2', 'Api\ProductController@productList2');
 
     //采购单
     $route->any('purchaseOrderList', 'Api\PurchaseOrderController@purchaseOrderList');
-    $route->any('purchaseOrderEdit', 'Api\PurchaseOrderController@purchaseOrderEdit');
+    $route->any('purchaseOrderEdit', 'Api\PurchaseOrderController@purchaseOrderEdit')->middleware('OssFileDeal');
     $route->any('purchaseOrderDetail', 'Api\PurchaseOrderController@purchaseOrderDetail');
-    $route->any('purchaseOrderAdd', 'Api\PurchaseOrderController@purchaseOrderAdd');
-    $route->any('purchaseOrderDel', 'Api\PurchaseOrderController@purchaseOrderDel');
+    $route->any('purchaseOrderAdd', 'Api\PurchaseOrderController@purchaseOrderAdd')->middleware('OssFileDeal');
+    $route->any('purchaseOrderDel', 'Api\PurchaseOrderController@purchaseOrderDel')->middleware('OssFileDeal');
 
     //特殊采购单
     $route->any('purchaseOrderSpecialList', 'Api\PurchaseOrderSpecialController@purchaseOrderList');
@@ -196,10 +196,10 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     //施工单
     $route->any('constructionGet', 'Api\ConstructionController@constructionGet');
     $route->any('constructionList', 'Api\ConstructionController@constructionList');
-    $route->any('constructionEdit', 'Api\ConstructionController@constructionEdit');
+    $route->any('constructionEdit', 'Api\ConstructionController@constructionEdit')->middleware('OssFileDeal');
     $route->any('constructionDetail', 'Api\ConstructionController@constructionDetail');
-    $route->any('constructionAdd', 'Api\ConstructionController@constructionAdd');
-    $route->any('constructionDel', 'Api\ConstructionController@constructionDel');
+    $route->any('constructionAdd', 'Api\ConstructionController@constructionAdd')->middleware('OssFileDeal');
+    $route->any('constructionDel', 'Api\ConstructionController@constructionDel')->middleware('OssFileDeal');
     $route->any('constructionPdf', 'Api\ConstructionController@constructionPdf');
     $route->any('constructionOperation', 'Api\ConstructionController@constructionOperation');
 
@@ -241,9 +241,9 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     //收付款
     $route->any('paymentReceiptGet', 'Api\PaymentReceiptController@paymentReceiptGet');
     $route->any('paymentReceiptList', 'Api\PaymentReceiptController@paymentReceiptList');
-    $route->any('paymentReceiptAdd', 'Api\PaymentReceiptController@paymentReceiptAdd');
-    $route->any('paymentReceiptEdit', 'Api\PaymentReceiptController@paymentReceiptEdit');
-    $route->any('paymentReceiptDel', 'Api\PaymentReceiptController@paymentReceiptDel');
+    $route->any('paymentReceiptAdd', 'Api\PaymentReceiptController@paymentReceiptAdd')->middleware('OssFileDeal');
+    $route->any('paymentReceiptEdit', 'Api\PaymentReceiptController@paymentReceiptEdit')->middleware('OssFileDeal');
+    $route->any('paymentReceiptDel', 'Api\PaymentReceiptController@paymentReceiptDel')->middleware('OssFileDeal');
     $route->any('paymentReceiptDetail', 'Api\PaymentReceiptController@paymentReceiptDetail');
 
     //排班设置

+ 10 - 10
routes/wx.php

@@ -36,10 +36,10 @@ Route::group(['middleware'=> ['checkWx']],function ($route){
     //需要账号登录的
     //采购单
     $route->any('purchaseOrderList', 'Api\WxController@purchaseOrderList');
-    $route->any('purchaseOrderEdit', 'Api\PurchaseOrderController@purchaseOrderEdit');
+    $route->any('purchaseOrderEdit', 'Api\PurchaseOrderController@purchaseOrderEdit')->middleware('OssFileDeal');
     $route->any('purchaseOrderDetail', 'Api\PurchaseOrderController@purchaseOrderDetail');
-    $route->any('purchaseOrderAdd', 'Api\PurchaseOrderController@purchaseOrderAdd');
-    $route->any('purchaseOrderDel', 'Api\PurchaseOrderController@purchaseOrderDel');
+    $route->any('purchaseOrderAdd', 'Api\PurchaseOrderController@purchaseOrderAdd')->middleware('OssFileDeal');
+    $route->any('purchaseOrderDel', 'Api\PurchaseOrderController@purchaseOrderDel')->middleware('OssFileDeal');
 
     //合同
     $route->any('salesOrderGet', 'Api\SalesOrderController@salesOrderGet');
@@ -52,10 +52,10 @@ Route::group(['middleware'=> ['checkWx']],function ($route){
     $route->any('constructionOperation', 'Api\ConstructionController@constructionOperation');
     $route->any('constructionGet', 'Api\ConstructionController@constructionGet');
     $route->any('constructionList', 'Api\ConstructionController@constructionList');
-    $route->any('constructionEdit', 'Api\ConstructionController@constructionEdit');
+    $route->any('constructionEdit', 'Api\ConstructionController@constructionEdit')->middleware('OssFileDeal');
     $route->any('constructionDetail', 'Api\ConstructionController@constructionDetail');
-    $route->any('constructionAdd', 'Api\ConstructionController@constructionAdd');
-    $route->any('constructionDel', 'Api\ConstructionController@constructionDel');
+    $route->any('constructionAdd', 'Api\ConstructionController@constructionAdd')->middleware('OssFileDeal');
+    $route->any('constructionDel', 'Api\ConstructionController@constructionDel')->middleware('OssFileDeal');
     $route->any('deliveryNoteList', 'Api\ConstructionController@deliveryNoteList');
     $route->any('deliveryNoteDetail', 'Api\ConstructionController@deliveryNoteDetail');
     $route->any('deliveryNoteEdit', 'Api\ConstructionController@deliveryNoteEdit');
@@ -71,7 +71,7 @@ Route::group(['middleware'=> ['checkWx']],function ($route){
     $route->any('customerList', 'Api\CustomerController@customerList');
     $route->any('customerCapitalList', 'Api\CustomerController@customerList2');
     $route->any('sportsBagOrderList', 'Api\SportsBagController@orderList');
-    $route->any('productAdd', 'Api\ProductController@productAdd');
+    $route->any('productAdd', 'Api\ProductController@productAdd')->middleware('OssFileDeal');
     $route->any('productCategoryList', 'Api\ProductController@productCategoryList');
     $route->any('productList2', 'Api\ProductController@productList2');
 
@@ -107,9 +107,9 @@ Route::group(['middleware'=> ['checkWx']],function ($route){
     $route->any('getSettingGetDetail2', 'Api\ScheduleController@getSettingGetDetail2');
     //客户
     $route->any('customerList', 'Api\CustomerController@customerList');
-    $route->any('customerEdit', 'Api\CustomerController@customerEdit');
-    $route->any('customerAdd', 'Api\CustomerController@customerAdd');
-    $route->any('customerDel', 'Api\CustomerController@customerDel');
+    $route->any('customerEdit', 'Api\CustomerController@customerEdit')->middleware('OssFileDeal');
+    $route->any('customerAdd', 'Api\CustomerController@customerAdd')->middleware('OssFileDeal');
+    $route->any('customerDel', 'Api\CustomerController@customerDel')->middleware('OssFileDeal');
     $route->any('customerDetail', 'Api\CustomerController@customerDetail');
     $route->any('customerGrabbing', 'Api\CustomerController@customerGrabbing');
 });