作者 张关杰

Merge branch 'develop' of http://47.244.231.31:8099/zhl/globalso-v6 into bate

... ... @@ -37,7 +37,7 @@ class CustomModuleContentController extends BaseController
$data = $this->getAllCategoryName();
foreach ($lists['list'] as $k=>$v){
$v['category_name'] = $this->categoryName($v['category_id'],$data);
$v['image_link'] = getImageUrl($v['image']);
$v['image_link'] = getImageUrl($v['image'],$this->user['project_location'],$this->user['storage_type']);
$v['operator_name'] = (new User())->getName($v['operator_id']);
$lists['list'][$k] = $v;
}
... ...
... ... @@ -25,7 +25,7 @@ class WebSettingImageController extends BaseController
public function lists(WebSettingImage $webSettingImage){
$list = $webSettingImage->list([],'id',['id','image','type']);
foreach ($list as $k=>$v){
$v['image'] = getImageUrl($v['image']);
$v['image'] = getImageUrl($v['image'],$this->user['project_location'],$this->user['storage_type']);
$list[$k] = $v;
}
$this->response('success',Code::SUCCESS,$list);
... ...
... ... @@ -5,6 +5,7 @@ namespace App\Http\Controllers\File;
use App\Enums\Common\Code;
use App\Models\File\File;
use App\Models\Project\Project;
use App\Services\AmazonS3Service;
use App\Services\CosService;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Http\JsonResponse;
... ... @@ -125,10 +126,9 @@ class FileController
$cosService = new CosService();
$cosService->uploadFile($files,$this->path,$fileName);
}else{
$res = $files->move($url,$fileName);
if ($res === false) {
return $this->response($files->getError(), Code::USER_ERROR);
}
//TODO::上传亚马逊
$amazonS3Service = new AmazonS3Service();
$amazonS3Service->uploadFiles($files,$this->path,$fileName);
}
$this->saveMysql($fileModel,$files->getSize(),$files->getClientOriginalExtension(),$fileName,$hash,$this->upload_location,$files->getMimeType(),$name);
$this->response('资源',Code::SUCCESS,$this->responseData($this->path.'/'.$fileName, $name));
... ... @@ -165,7 +165,9 @@ class FileController
$cosService = new CosService();
$cosService->uploadFile($files, $this->path, $fileName);
} else {
$res = $files->move($url, $fileName);
//TODO::上传亚马逊
$amazonS3Service = new AmazonS3Service();
$res = $amazonS3Service->uploadFiles($files,$this->path,$fileName);
if ($res === false) {
return [
'message' => $files->getError(),
... ... @@ -238,10 +240,9 @@ class FileController
$cosService = new CosService();
$cosService->uploadFile($files,$this->path,$fileName);
}else{
$res = $files->move($url,$fileName);
if ($res === false) {
return $this->response($files->getError(), Code::USER_ERROR);
}
//TODO::上传亚马逊
$amazonS3Service = new AmazonS3Service();
$amazonS3Service->uploadFiles($files,$this->path,$fileName);
}
$size = $file->getSize();
$mime = $file->getMimeType();
... ...
... ... @@ -7,6 +7,7 @@ use App\Http\Controllers\Controller;
use App\Http\Controllers\type;
use App\Models\File\Image as ImageModel;
use App\Models\Project\Project;
use App\Services\AmazonS3Service;
use App\Services\CosService;
use App\Services\TencentCosService;
use Illuminate\Http\Exceptions\HttpResponseException;
... ... @@ -204,7 +205,9 @@ class ImageController extends Controller
$cosService = new CosService();
$cosService->uploadFile($files,$this->path,$fileName);
}else{
$files->move($url,$fileName);
//TODO::上传亚马逊
$amazonS3Service = new AmazonS3Service();
$amazonS3Service->uploadFiles($files,$this->path,$fileName);
}
$this->saveMysql($imageModel,$files->getSize(),$image_type,$fileName,$hash,$this->upload_location,$files->getMimeType(), $name);
return $this->response('图片资源',Code::SUCCESS,$this->responseData($this->path.'/'.$fileName, $name));
... ... @@ -282,7 +285,9 @@ class ImageController extends Controller
$cosService = new CosService();
$cosService->uploadFile($file,$this->path,$fileName);
}else{
$file->move($url,$fileName);
//TODO::上传亚马逊
$amazonS3Service = new AmazonS3Service();
$amazonS3Service->uploadFiles($files,$this->path,$fileName);
}
//批量存储
$this->saveMysql($imageModel,$file->getSize(),$image_type,$fileName,$hash,$this->upload_location,$file->getMimeType(),$name);
... ...
... ... @@ -39,7 +39,7 @@ class CustomModuleContentLogic extends BaseLogic
if($info === false){
$this->fail('当前数据不存在或已被删除');
}
$info['image'] = getImageUrl($info['image']);
$info['image'] = getImageUrl($info['image'],$this->user['project_location'],$this->user['storage_type']);
$info['extend'] = $this->getExtendInfo($info['module_id'],$info['id']);
return $this->success($info);
}
... ... @@ -86,14 +86,14 @@ class CustomModuleContentLogic extends BaseLogic
$arr = json_decode($info['values']);
foreach ($arr as $k1=>$v1){
$v1 = (array)$v1;
$v1['url'] = getImageUrl($v1['url']);
$v1['url'] = getImageUrl($v1['url'],$this->user['project_location'],$this->user['storage_type']);
$arr[$k1] = $v1;
}
$v['values'] = $arr;
}elseif($v['type'] == 4){
$arr1 = json_decode($info['values']);
foreach ($arr1 as $k1=>$v1){
$v1 = getFileUrl($v1);
$v1 = getFileUrl($v1,$this->user['project_location'],$this->user['storage_type']);
$arr1[$k1] = $v1;
}
$v['values'] = $arr1;
... ...
... ... @@ -32,7 +32,7 @@ class CategoryLogic extends BaseLogic
foreach ($data as &$v){
$v['url'] = $this->user['domain'] . $v['route'] ;
$v['product_num'] = Category::getProductNum($v['id']);
$v['image_link'] = getImageUrl($v['image']);
$v['image_link'] = getImageUrl($v['image'],$this->user['project_location'],$this->user['storage_type']);
}
if(!$map){
$data = Arr::listToTree($data);
... ...
... ... @@ -15,10 +15,10 @@ class AmazonS3Service
{
// 替换为你自己的 AWS 访问密钥、区域和存储桶名称
protected $s3;
protected $accessKeyId = '';//key
protected $secretAccessKey = '';//密匙
protected $region = '';//地址
protected $bucket = '';//桶子
protected $accessKeyId = 'AKIAU6YKND7SAWIKBXCZ';//key
protected $secretAccessKey = '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';//密匙
protected $region = 's3://arn:aws:s3:us-west-2:340934860772:accesspoint/globalso-v6';//地址
protected $bucket = 'arn:aws:s3:::globalso-v6';//桶子
public function __construct()
{
... ... @@ -40,13 +40,15 @@ class AmazonS3Service
* @method :post
* @time :2024/1/23 9:20
*/
public function uploadFiles($localFilePath, $s3Key)
public function uploadFiles(&$files, $s3Key,$filename ,$binary = false)
{
$key = $s3Key.'/'.$filename;
$Body = $binary ? $files : fopen($files->getRealPath(), 'r');
try {
$result = $this->s3->putObject([
'Bucket' => $this->bucket,
'Key' => $s3Key,
'SourceFile' => $localFilePath,
'Key' => $key,
'SourceFile' => $Body,
'ACL' => 'public-read', // 设置图片为公共可读,可根据需求修改
]);
return $result['ObjectURL'];
... ...