作者 lyh

gx

@@ -318,34 +318,37 @@ class ImageController extends Controller @@ -318,34 +318,37 @@ class ImageController extends Controller
318 private function multi(&$files) { 318 private function multi(&$files) {
319 $data = []; 319 $data = [];
320 foreach ($files as $file) { 320 foreach ($files as $file) {
321 - $hash = hash_file('sha256', $file->getPathname());  
322 - $name = $file->getClientOriginalName();  
323 - $imageModel = new ImageModel();  
324 - //查看图片是否已上传  
325 - $param = ['hash'=>$hash,'refer'=>$this->param['refer'] ?? 0,'is_cos'=>(($this->upload_location == 0) ? 1 : 0)];  
326 - if(isset($this->cache['project_id']) && !empty($this->cache['project_id'])){  
327 - $param['project_id'] = $this->cache['project_id'];  
328 - }  
329 - $image_hash = $imageModel->read($param);  
330 - if($image_hash !== false){  
331 - $data[] = $this->responseData($image_hash['path'],$image_hash['name']);  
332 - continue;  
333 - }  
334 - $image_type = $file->getClientOriginalExtension();  
335 - $fileName = $this->getOnlyFilename($name,$param['project_id'] ?? 0);  
336 - $this->saveMysql($imageModel,$file->getSize(),$image_type,$fileName,$hash,$this->upload_location,$file->getMimeType(),$name);  
337 - //同步数据到cos  
338 - if($this->upload_location == 0){  
339 - $cosService = new CosService();  
340 - $cosService->uploadFile($file,$this->path,$fileName);  
341 - }else{  
342 - //TODO::上传亚马逊  
343 - $amazonS3Service = new AmazonS3Service();  
344 - $amazonS3Service->uploadFiles($file,$this->path,$fileName); 321 + try {
  322 + $hash = hash_file('sha256', $file->getPathname());
  323 + $imageModel = new ImageModel();
  324 + //查看图片是否已上传
  325 + $param = ['hash'=>$hash,'refer'=>$this->param['refer'] ?? 0,'is_cos'=>(($this->upload_location == 0) ? 1 : 0)];
  326 + if(isset($this->cache['project_id']) && !empty($this->cache['project_id'])){
  327 + $param['project_id'] = $this->cache['project_id'];
  328 + }
  329 + $image_hash = $imageModel->read($param);
  330 + if($image_hash !== false){
  331 + $data[] = $this->responseData($image_hash['path'],$image_hash['name']);
  332 + continue;
  333 + }
  334 + $name = $file->getClientOriginalName();
  335 + $fileName = $this->getOnlyFilename($name,$param['project_id'] ?? 0);
  336 + $image_type = $file->getClientOriginalExtension();
  337 + $this->saveMysql($imageModel,$file->getSize(),$image_type,$fileName,$hash,$this->upload_location,$file->getMimeType(),$name);
  338 + //同步数据到cos
  339 + if($this->upload_location == 0){
  340 + $cosService = new CosService();
  341 + $cosService->uploadFile($file,$this->path,$fileName);
  342 + }else{
  343 + //TODO::上传亚马逊
  344 + $amazonS3Service = new AmazonS3Service();
  345 + $amazonS3Service->uploadFiles($file,$this->path,$fileName);
  346 + }
  347 + $this->synchronizationImage($fileName,$this->upload_location);
  348 + $data[] = $this->responseData($this->path.'/'.$fileName,$name);
  349 + }catch (\Exception $e){
  350 + $this->response('图片资源',Code::SUCCESS,$data);
345 } 351 }
346 - $this->synchronizationImage($fileName,$this->upload_location);  
347 - $data[] = $this->responseData($this->path.'/'.$fileName,$name);  
348 - $hash = $name = '';  
349 } 352 }
350 $this->response('图片资源',Code::SUCCESS,$data); 353 $this->response('图片资源',Code::SUCCESS,$data);
351 } 354 }