正在显示
3 个修改的文件
包含
39 行增加
和
18 行删除
| @@ -3,6 +3,7 @@ | @@ -3,6 +3,7 @@ | ||
| 3 | namespace App\Http\Logic\Aside\Project; | 3 | namespace App\Http\Logic\Aside\Project; |
| 4 | 4 | ||
| 5 | use App\Enums\Common\Code; | 5 | use App\Enums\Common\Code; |
| 6 | +use App\Events\CopyImageFile; | ||
| 6 | use App\Events\CopyProject; | 7 | use App\Events\CopyProject; |
| 7 | use App\Exceptions\AsideGlobalException; | 8 | use App\Exceptions\AsideGlobalException; |
| 8 | use App\Models\Com\NoticeLog; | 9 | use App\Models\Com\NoticeLog; |
| @@ -162,6 +163,13 @@ class ProjectLogic extends BaseLogic | @@ -162,6 +163,13 @@ class ProjectLogic extends BaseLogic | ||
| 162 | return $this->success(); | 163 | return $this->success(); |
| 163 | } | 164 | } |
| 164 | 165 | ||
| 166 | + public function syncImageFile($location){ | ||
| 167 | + if($location == 2){ | ||
| 168 | + CopyImageFile::dispatch(['project_id'=>$this->param['project_id']]); | ||
| 169 | + } | ||
| 170 | + return $this->success(); | ||
| 171 | + } | ||
| 172 | + | ||
| 165 | /** | 173 | /** |
| 166 | * @remark :保存项目 | 174 | * @remark :保存项目 |
| 167 | * @name :setExtendType | 175 | * @name :setExtendType |
| @@ -330,7 +338,7 @@ class ProjectLogic extends BaseLogic | @@ -330,7 +338,7 @@ class ProjectLogic extends BaseLogic | ||
| 330 | $config['filter_mobiles'] = Arr::a2s(!empty($config['filter_mobiles']) ? $config['filter_mobiles'] : []); | 338 | $config['filter_mobiles'] = Arr::a2s(!empty($config['filter_mobiles']) ? $config['filter_mobiles'] : []); |
| 331 | $config['filter_names'] = Arr::a2s(!empty($config['filter_names']) ? $config['filter_names'] : []); | 339 | $config['filter_names'] = Arr::a2s(!empty($config['filter_names']) ? $config['filter_names'] : []); |
| 332 | $config['black_ips'] = $config['black_ips'] ?? ''; | 340 | $config['black_ips'] = $config['black_ips'] ?? ''; |
| 333 | - | 341 | + |
| 334 | $model = InquiryFilterConfig::where('project_id', $config['project_id'])->first(); | 342 | $model = InquiryFilterConfig::where('project_id', $config['project_id'])->first(); |
| 335 | if(!$model){ | 343 | if(!$model){ |
| 336 | $model = new InquiryFilterConfig(); | 344 | $model = new InquiryFilterConfig(); |
| @@ -5,6 +5,9 @@ namespace App\Listeners; | @@ -5,6 +5,9 @@ namespace App\Listeners; | ||
| 5 | use App\Events\CopyImageFile; | 5 | use App\Events\CopyImageFile; |
| 6 | use App\Events\UpdateHtml; | 6 | use App\Events\UpdateHtml; |
| 7 | use App\Jobs\updateHtmlJob; | 7 | use App\Jobs\updateHtmlJob; |
| 8 | +use App\Models\File\File as FileModel; | ||
| 9 | +use App\Models\File\Image as ImageModel; | ||
| 10 | +use App\Services\AmazonS3Service; | ||
| 8 | use Illuminate\Contracts\Queue\ShouldQueue; | 11 | use Illuminate\Contracts\Queue\ShouldQueue; |
| 9 | 12 | ||
| 10 | class CopyImageFileListener implements ShouldQueue | 13 | class CopyImageFileListener implements ShouldQueue |
| @@ -23,16 +26,28 @@ class CopyImageFileListener implements ShouldQueue | @@ -23,16 +26,28 @@ class CopyImageFileListener implements ShouldQueue | ||
| 23 | public function handle(CopyImageFile $event) | 26 | public function handle(CopyImageFile $event) |
| 24 | { | 27 | { |
| 25 | $this->param = $event->data; | 28 | $this->param = $event->data; |
| 26 | - } | ||
| 27 | - | ||
| 28 | - /** | ||
| 29 | - * @remark :同步图片文件到亚马逊 | ||
| 30 | - * @name :uploadImageFile | ||
| 31 | - * @author :lyh | ||
| 32 | - * @method :post | ||
| 33 | - * @time :2024/1/26 10:15 | ||
| 34 | - */ | ||
| 35 | - public function uploadImageFile(){ | ||
| 36 | - | 29 | + $imageModel = new ImageModel(); |
| 30 | + //获取当前项目的所有图片 | ||
| 31 | + $imageList = $imageModel->list(['project_id'=>$this->param['project_id'],'is_cos'=>1],'id',['id','path','is_cos']); | ||
| 32 | + if(!empty($imageList)){ | ||
| 33 | + $amazonS3Service = new AmazonS3Service(); | ||
| 34 | + foreach ($imageList as $k => $v){ | ||
| 35 | + $amazonS3Service->syncImageFiles(getImageUrl($v['path'])); | ||
| 36 | + $imageModel->edit(['is_cos'=>0],['id'=>$v['id']]); | ||
| 37 | + } | ||
| 38 | + } | ||
| 39 | + @file_put_contents(storage_path('logs/lyh_error.log'), var_export('图片:'.$v['id'], true) . PHP_EOL, FILE_APPEND); | ||
| 40 | + sleep(2); | ||
| 41 | + $fileModel = new FileModel(); | ||
| 42 | + $fileList = $fileModel->list(['project_id'=>$this->param['project_id'],'is_cos'=>1],'id',['id','path','is_cos']); | ||
| 43 | + if(!empty($fileList)){ | ||
| 44 | + $amazonS3Service = new AmazonS3Service(); | ||
| 45 | + foreach ($fileList as $k => $v){ | ||
| 46 | + $amazonS3Service->syncImageFiles(getImageUrl($v['path'])); | ||
| 47 | + $fileList->edit(['is_cos'=>0],['id'=>$v['id']]); | ||
| 48 | + } | ||
| 49 | + } | ||
| 50 | + @file_put_contents(storage_path('logs/lyh_error.log'), var_export('文件:'.$v['id'], true) . PHP_EOL, FILE_APPEND); | ||
| 51 | + return true; | ||
| 37 | } | 52 | } |
| 38 | } | 53 | } |
| @@ -64,7 +64,7 @@ class AmazonS3Service | @@ -64,7 +64,7 @@ class AmazonS3Service | ||
| 64 | * @method :post | 64 | * @method :post |
| 65 | * @time :2024/1/23 9:20 | 65 | * @time :2024/1/23 9:20 |
| 66 | */ | 66 | */ |
| 67 | - public function SyncImageFiles($files) | 67 | + public function syncImageFiles($files) |
| 68 | { | 68 | { |
| 69 | $key = str_replace_url($files); | 69 | $key = str_replace_url($files); |
| 70 | $body = $files; | 70 | $body = $files; |
| @@ -72,13 +72,11 @@ class AmazonS3Service | @@ -72,13 +72,11 @@ class AmazonS3Service | ||
| 72 | $result = $this->s3->putObject([ | 72 | $result = $this->s3->putObject([ |
| 73 | 'Bucket' => $this->bucket, | 73 | 'Bucket' => $this->bucket, |
| 74 | 'Key' => $key, | 74 | 'Key' => $key, |
| 75 | - 'Body' => fopen($body, 'rb'), | 75 | + 'Body' => file_get_contents($body), |
| 76 | ]); | 76 | ]); |
| 77 | - | ||
| 78 | - echo '文件成功上传到S3!'; | 77 | + return $result['ObjectURL']; |
| 79 | } catch (AwsException $e) { | 78 | } catch (AwsException $e) { |
| 80 | - echo '上传文件到S3时发生错误:' . $e->getMessage(); | ||
| 81 | - return false; | 79 | + return '上传文件到S3时发生错误:' . $e->getMessage(); |
| 82 | } | 80 | } |
| 83 | } | 81 | } |
| 84 | } | 82 | } |
-
请 注册 或 登录 后发表评论