作者 lyh

列表页聚合页模式

@@ -35,13 +35,26 @@ class AiVideoController extends BaseController @@ -35,13 +35,26 @@ class AiVideoController extends BaseController
35 Log::channel('ai_video')->info('当前数据不存在或已被删除'.$this->param['id']); 35 Log::channel('ai_video')->info('当前数据不存在或已被删除'.$this->param['id']);
36 } 36 }
37 $cosService = new CosService(); 37 $cosService = new CosService();
38 - $imagePath = $cosService->uploadRemote(1,'video',$data['url']);  
39 - if($imagePath){  
40 - //裁剪图片为4张  
41 - }else{  
42 - Log::channel('ai_video')->info('上传图片失败'); 38 + $imagePath = $cosService->uploadRemote($info['project_id'],'video',$data['url']);
  39 + try {
  40 + if($imagePath){
  41 + $cos = config('filesystems.disks.cos');
  42 + $url = $cos['cdn1'].'/'.$imagePath;
  43 + //裁剪图片为4张
  44 + $cosService = new CosService();
  45 + $images = [];
  46 + $data = $cosService->cropAndUploadToCOS($url);
  47 + if(!empty($data)){
  48 + foreach ($data as $item){
  49 + $images[] = ['url'=>$item,'alt'=>''];
  50 + }
  51 + }
  52 + $images = array_merge($images,$info['images']);
  53 + $aiVideoAutoLogModel->edit(['images'=>$images,'result'=>json_encode($this->param,true)],['id'=>$info['id']]);
  54 + }
  55 + }catch (\Exception $e){
  56 + Log::channel('ai_video')->info('上传图片失败'.$e->getMessage());
43 } 57 }
44 -  
45 $this->response('success'); 58 $this->response('success');
46 } 59 }
47 } 60 }
@@ -144,7 +144,6 @@ class CosService @@ -144,7 +144,6 @@ class CosService
144 if(!$body_str){ 144 if(!$body_str){
145 return ''; 145 return '';
146 } 146 }
147 -  
148 try { 147 try {
149 $cosClient->putObject([ 148 $cosClient->putObject([
150 'Bucket' => $cos['bucket'], 149 'Bucket' => $cos['bucket'],
@@ -421,6 +420,8 @@ class CosService @@ -421,6 +420,8 @@ class CosService
421 // 6. 循环裁剪并上传 420 // 6. 循环裁剪并上传
422 $resultPaths = []; 421 $resultPaths = [];
423 $index = 0; 422 $index = 0;
  423 + $cos = config('filesystems.disks.cos');
  424 +
424 for ($y = 0; $y < 2; $y++) { 425 for ($y = 0; $y < 2; $y++) {
425 for ($x = 0; $x < 2; $x++) { 426 for ($x = 0; $x < 2; $x++) {
426 $crop = imagecreatetruecolor($halfWidth, $halfHeight); 427 $crop = imagecreatetruecolor($halfWidth, $halfHeight);
@@ -438,7 +439,7 @@ class CosService @@ -438,7 +439,7 @@ class CosService
438 'Body' => fopen($tempCropped, 'rb'), 439 'Body' => fopen($tempCropped, 'rb'),
439 ]); 440 ]);
440 // 返回相对路径 441 // 返回相对路径
441 - $resultPaths[] = $objectKey; 442 + $resultPaths[] = $cos['cdn1'].'/'.$objectKey;
442 unlink($tempCropped); 443 unlink($tempCropped);
443 } 444 }
444 } 445 }