作者 lyh

gx

... ... @@ -3,6 +3,7 @@
namespace App\Http\Logic\Aside\Project;
use App\Enums\Common\Code;
use App\Events\CopyImageFile;
use App\Events\CopyProject;
use App\Exceptions\AsideGlobalException;
use App\Models\Com\NoticeLog;
... ... @@ -162,6 +163,13 @@ class ProjectLogic extends BaseLogic
return $this->success();
}
public function syncImageFile($location){
if($location == 2){
CopyImageFile::dispatch(['project_id'=>$this->param['project_id']]);
}
return $this->success();
}
/**
* @remark :保存项目
* @name :setExtendType
... ... @@ -330,7 +338,7 @@ class ProjectLogic extends BaseLogic
$config['filter_mobiles'] = Arr::a2s(!empty($config['filter_mobiles']) ? $config['filter_mobiles'] : []);
$config['filter_names'] = Arr::a2s(!empty($config['filter_names']) ? $config['filter_names'] : []);
$config['black_ips'] = $config['black_ips'] ?? '';
$model = InquiryFilterConfig::where('project_id', $config['project_id'])->first();
if(!$model){
$model = new InquiryFilterConfig();
... ...
... ... @@ -5,6 +5,9 @@ namespace App\Listeners;
use App\Events\CopyImageFile;
use App\Events\UpdateHtml;
use App\Jobs\updateHtmlJob;
use App\Models\File\File as FileModel;
use App\Models\File\Image as ImageModel;
use App\Services\AmazonS3Service;
use Illuminate\Contracts\Queue\ShouldQueue;
class CopyImageFileListener implements ShouldQueue
... ... @@ -23,16 +26,28 @@ class CopyImageFileListener implements ShouldQueue
public function handle(CopyImageFile $event)
{
$this->param = $event->data;
}
/**
* @remark :同步图片文件到亚马逊
* @name :uploadImageFile
* @author :lyh
* @method :post
* @time :2024/1/26 10:15
*/
public function uploadImageFile(){
$imageModel = new ImageModel();
//获取当前项目的所有图片
$imageList = $imageModel->list(['project_id'=>$this->param['project_id'],'is_cos'=>1],'id',['id','path','is_cos']);
if(!empty($imageList)){
$amazonS3Service = new AmazonS3Service();
foreach ($imageList as $k => $v){
$amazonS3Service->syncImageFiles(getImageUrl($v['path']));
$imageModel->edit(['is_cos'=>0],['id'=>$v['id']]);
}
}
@file_put_contents(storage_path('logs/lyh_error.log'), var_export('图片:'.$v['id'], true) . PHP_EOL, FILE_APPEND);
sleep(2);
$fileModel = new FileModel();
$fileList = $fileModel->list(['project_id'=>$this->param['project_id'],'is_cos'=>1],'id',['id','path','is_cos']);
if(!empty($fileList)){
$amazonS3Service = new AmazonS3Service();
foreach ($fileList as $k => $v){
$amazonS3Service->syncImageFiles(getImageUrl($v['path']));
$fileList->edit(['is_cos'=>0],['id'=>$v['id']]);
}
}
@file_put_contents(storage_path('logs/lyh_error.log'), var_export('文件:'.$v['id'], true) . PHP_EOL, FILE_APPEND);
return true;
}
}
... ...
... ... @@ -64,7 +64,7 @@ class AmazonS3Service
* @method :post
* @time :2024/1/23 9:20
*/
public function SyncImageFiles($files)
public function syncImageFiles($files)
{
$key = str_replace_url($files);
$body = $files;
... ... @@ -72,13 +72,11 @@ class AmazonS3Service
$result = $this->s3->putObject([
'Bucket' => $this->bucket,
'Key' => $key,
'Body' => fopen($body, 'rb'),
'Body' => file_get_contents($body),
]);
echo '文件成功上传到S3!';
return $result['ObjectURL'];
} catch (AwsException $e) {
echo '上传文件到S3时发生错误:' . $e->getMessage();
return false;
return '上传文件到S3时发生错误:' . $e->getMessage();
}
}
}
... ...