作者 张关杰

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

@@ -37,7 +37,7 @@ class CustomModuleContentController extends BaseController @@ -37,7 +37,7 @@ class CustomModuleContentController extends BaseController
37 $data = $this->getAllCategoryName(); 37 $data = $this->getAllCategoryName();
38 foreach ($lists['list'] as $k=>$v){ 38 foreach ($lists['list'] as $k=>$v){
39 $v['category_name'] = $this->categoryName($v['category_id'],$data); 39 $v['category_name'] = $this->categoryName($v['category_id'],$data);
40 - $v['image_link'] = getImageUrl($v['image']); 40 + $v['image_link'] = getImageUrl($v['image'],$this->user['project_location'],$this->user['storage_type']);
41 $v['operator_name'] = (new User())->getName($v['operator_id']); 41 $v['operator_name'] = (new User())->getName($v['operator_id']);
42 $lists['list'][$k] = $v; 42 $lists['list'][$k] = $v;
43 } 43 }
@@ -25,7 +25,7 @@ class WebSettingImageController extends BaseController @@ -25,7 +25,7 @@ class WebSettingImageController extends BaseController
25 public function lists(WebSettingImage $webSettingImage){ 25 public function lists(WebSettingImage $webSettingImage){
26 $list = $webSettingImage->list([],'id',['id','image','type']); 26 $list = $webSettingImage->list([],'id',['id','image','type']);
27 foreach ($list as $k=>$v){ 27 foreach ($list as $k=>$v){
28 - $v['image'] = getImageUrl($v['image']); 28 + $v['image'] = getImageUrl($v['image'],$this->user['project_location'],$this->user['storage_type']);
29 $list[$k] = $v; 29 $list[$k] = $v;
30 } 30 }
31 $this->response('success',Code::SUCCESS,$list); 31 $this->response('success',Code::SUCCESS,$list);
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\File; @@ -5,6 +5,7 @@ namespace App\Http\Controllers\File;
5 use App\Enums\Common\Code; 5 use App\Enums\Common\Code;
6 use App\Models\File\File; 6 use App\Models\File\File;
7 use App\Models\Project\Project; 7 use App\Models\Project\Project;
  8 +use App\Services\AmazonS3Service;
8 use App\Services\CosService; 9 use App\Services\CosService;
9 use Illuminate\Http\Exceptions\HttpResponseException; 10 use Illuminate\Http\Exceptions\HttpResponseException;
10 use Illuminate\Http\JsonResponse; 11 use Illuminate\Http\JsonResponse;
@@ -125,10 +126,9 @@ class FileController @@ -125,10 +126,9 @@ class FileController
125 $cosService = new CosService(); 126 $cosService = new CosService();
126 $cosService->uploadFile($files,$this->path,$fileName); 127 $cosService->uploadFile($files,$this->path,$fileName);
127 }else{ 128 }else{
128 - $res = $files->move($url,$fileName);  
129 - if ($res === false) {  
130 - return $this->response($files->getError(), Code::USER_ERROR);  
131 - } 129 + //TODO::上传亚马逊
  130 + $amazonS3Service = new AmazonS3Service();
  131 + $amazonS3Service->uploadFiles($files,$this->path,$fileName);
132 } 132 }
133 $this->saveMysql($fileModel,$files->getSize(),$files->getClientOriginalExtension(),$fileName,$hash,$this->upload_location,$files->getMimeType(),$name); 133 $this->saveMysql($fileModel,$files->getSize(),$files->getClientOriginalExtension(),$fileName,$hash,$this->upload_location,$files->getMimeType(),$name);
134 $this->response('资源',Code::SUCCESS,$this->responseData($this->path.'/'.$fileName, $name)); 134 $this->response('资源',Code::SUCCESS,$this->responseData($this->path.'/'.$fileName, $name));
@@ -165,7 +165,9 @@ class FileController @@ -165,7 +165,9 @@ class FileController
165 $cosService = new CosService(); 165 $cosService = new CosService();
166 $cosService->uploadFile($files, $this->path, $fileName); 166 $cosService->uploadFile($files, $this->path, $fileName);
167 } else { 167 } else {
168 - $res = $files->move($url, $fileName); 168 + //TODO::上传亚马逊
  169 + $amazonS3Service = new AmazonS3Service();
  170 + $res = $amazonS3Service->uploadFiles($files,$this->path,$fileName);
169 if ($res === false) { 171 if ($res === false) {
170 return [ 172 return [
171 'message' => $files->getError(), 173 'message' => $files->getError(),
@@ -238,10 +240,9 @@ class FileController @@ -238,10 +240,9 @@ class FileController
238 $cosService = new CosService(); 240 $cosService = new CosService();
239 $cosService->uploadFile($files,$this->path,$fileName); 241 $cosService->uploadFile($files,$this->path,$fileName);
240 }else{ 242 }else{
241 - $res = $files->move($url,$fileName);  
242 - if ($res === false) {  
243 - return $this->response($files->getError(), Code::USER_ERROR);  
244 - } 243 + //TODO::上传亚马逊
  244 + $amazonS3Service = new AmazonS3Service();
  245 + $amazonS3Service->uploadFiles($files,$this->path,$fileName);
245 } 246 }
246 $size = $file->getSize(); 247 $size = $file->getSize();
247 $mime = $file->getMimeType(); 248 $mime = $file->getMimeType();
@@ -7,6 +7,7 @@ use App\Http\Controllers\Controller; @@ -7,6 +7,7 @@ use App\Http\Controllers\Controller;
7 use App\Http\Controllers\type; 7 use App\Http\Controllers\type;
8 use App\Models\File\Image as ImageModel; 8 use App\Models\File\Image as ImageModel;
9 use App\Models\Project\Project; 9 use App\Models\Project\Project;
  10 +use App\Services\AmazonS3Service;
10 use App\Services\CosService; 11 use App\Services\CosService;
11 use App\Services\TencentCosService; 12 use App\Services\TencentCosService;
12 use Illuminate\Http\Exceptions\HttpResponseException; 13 use Illuminate\Http\Exceptions\HttpResponseException;
@@ -204,7 +205,9 @@ class ImageController extends Controller @@ -204,7 +205,9 @@ class ImageController extends Controller
204 $cosService = new CosService(); 205 $cosService = new CosService();
205 $cosService->uploadFile($files,$this->path,$fileName); 206 $cosService->uploadFile($files,$this->path,$fileName);
206 }else{ 207 }else{
207 - $files->move($url,$fileName); 208 + //TODO::上传亚马逊
  209 + $amazonS3Service = new AmazonS3Service();
  210 + $amazonS3Service->uploadFiles($files,$this->path,$fileName);
208 } 211 }
209 $this->saveMysql($imageModel,$files->getSize(),$image_type,$fileName,$hash,$this->upload_location,$files->getMimeType(), $name); 212 $this->saveMysql($imageModel,$files->getSize(),$image_type,$fileName,$hash,$this->upload_location,$files->getMimeType(), $name);
210 return $this->response('图片资源',Code::SUCCESS,$this->responseData($this->path.'/'.$fileName, $name)); 213 return $this->response('图片资源',Code::SUCCESS,$this->responseData($this->path.'/'.$fileName, $name));
@@ -282,7 +285,9 @@ class ImageController extends Controller @@ -282,7 +285,9 @@ class ImageController extends Controller
282 $cosService = new CosService(); 285 $cosService = new CosService();
283 $cosService->uploadFile($file,$this->path,$fileName); 286 $cosService->uploadFile($file,$this->path,$fileName);
284 }else{ 287 }else{
285 - $file->move($url,$fileName); 288 + //TODO::上传亚马逊
  289 + $amazonS3Service = new AmazonS3Service();
  290 + $amazonS3Service->uploadFiles($files,$this->path,$fileName);
286 } 291 }
287 //批量存储 292 //批量存储
288 $this->saveMysql($imageModel,$file->getSize(),$image_type,$fileName,$hash,$this->upload_location,$file->getMimeType(),$name); 293 $this->saveMysql($imageModel,$file->getSize(),$image_type,$fileName,$hash,$this->upload_location,$file->getMimeType(),$name);
@@ -39,7 +39,7 @@ class CustomModuleContentLogic extends BaseLogic @@ -39,7 +39,7 @@ class CustomModuleContentLogic extends BaseLogic
39 if($info === false){ 39 if($info === false){
40 $this->fail('当前数据不存在或已被删除'); 40 $this->fail('当前数据不存在或已被删除');
41 } 41 }
42 - $info['image'] = getImageUrl($info['image']); 42 + $info['image'] = getImageUrl($info['image'],$this->user['project_location'],$this->user['storage_type']);
43 $info['extend'] = $this->getExtendInfo($info['module_id'],$info['id']); 43 $info['extend'] = $this->getExtendInfo($info['module_id'],$info['id']);
44 return $this->success($info); 44 return $this->success($info);
45 } 45 }
@@ -86,14 +86,14 @@ class CustomModuleContentLogic extends BaseLogic @@ -86,14 +86,14 @@ class CustomModuleContentLogic extends BaseLogic
86 $arr = json_decode($info['values']); 86 $arr = json_decode($info['values']);
87 foreach ($arr as $k1=>$v1){ 87 foreach ($arr as $k1=>$v1){
88 $v1 = (array)$v1; 88 $v1 = (array)$v1;
89 - $v1['url'] = getImageUrl($v1['url']); 89 + $v1['url'] = getImageUrl($v1['url'],$this->user['project_location'],$this->user['storage_type']);
90 $arr[$k1] = $v1; 90 $arr[$k1] = $v1;
91 } 91 }
92 $v['values'] = $arr; 92 $v['values'] = $arr;
93 }elseif($v['type'] == 4){ 93 }elseif($v['type'] == 4){
94 $arr1 = json_decode($info['values']); 94 $arr1 = json_decode($info['values']);
95 foreach ($arr1 as $k1=>$v1){ 95 foreach ($arr1 as $k1=>$v1){
96 - $v1 = getFileUrl($v1); 96 + $v1 = getFileUrl($v1,$this->user['project_location'],$this->user['storage_type']);
97 $arr1[$k1] = $v1; 97 $arr1[$k1] = $v1;
98 } 98 }
99 $v['values'] = $arr1; 99 $v['values'] = $arr1;
@@ -32,7 +32,7 @@ class CategoryLogic extends BaseLogic @@ -32,7 +32,7 @@ class CategoryLogic extends BaseLogic
32 foreach ($data as &$v){ 32 foreach ($data as &$v){
33 $v['url'] = $this->user['domain'] . $v['route'] ; 33 $v['url'] = $this->user['domain'] . $v['route'] ;
34 $v['product_num'] = Category::getProductNum($v['id']); 34 $v['product_num'] = Category::getProductNum($v['id']);
35 - $v['image_link'] = getImageUrl($v['image']); 35 + $v['image_link'] = getImageUrl($v['image'],$this->user['project_location'],$this->user['storage_type']);
36 } 36 }
37 if(!$map){ 37 if(!$map){
38 $data = Arr::listToTree($data); 38 $data = Arr::listToTree($data);
@@ -15,10 +15,10 @@ class AmazonS3Service @@ -15,10 +15,10 @@ class AmazonS3Service
15 { 15 {
16 // 替换为你自己的 AWS 访问密钥、区域和存储桶名称 16 // 替换为你自己的 AWS 访问密钥、区域和存储桶名称
17 protected $s3; 17 protected $s3;
18 - protected $accessKeyId = '';//key  
19 - protected $secretAccessKey = '';//密匙  
20 - protected $region = '';//地址  
21 - protected $bucket = '';//桶子 18 + protected $accessKeyId = 'AKIAU6YKND7SAWIKBXCZ';//key
  19 + protected $secretAccessKey = 'Hwd2abya/2Icu6NMDo4YrdTqCtir1BeTuUj5kEkB';//密匙
  20 + protected $region = 's3://arn:aws:s3:us-west-2:340934860772:accesspoint/globalso-v6';//地址
  21 + protected $bucket = 'arn:aws:s3:::globalso-v6';//桶子
22 22
23 public function __construct() 23 public function __construct()
24 { 24 {
@@ -40,13 +40,15 @@ class AmazonS3Service @@ -40,13 +40,15 @@ class AmazonS3Service
40 * @method :post 40 * @method :post
41 * @time :2024/1/23 9:20 41 * @time :2024/1/23 9:20
42 */ 42 */
43 - public function uploadFiles($localFilePath, $s3Key) 43 + public function uploadFiles(&$files, $s3Key,$filename ,$binary = false)
44 { 44 {
  45 + $key = $s3Key.'/'.$filename;
  46 + $Body = $binary ? $files : fopen($files->getRealPath(), 'r');
45 try { 47 try {
46 $result = $this->s3->putObject([ 48 $result = $this->s3->putObject([
47 'Bucket' => $this->bucket, 49 'Bucket' => $this->bucket,
48 - 'Key' => $s3Key,  
49 - 'SourceFile' => $localFilePath, 50 + 'Key' => $key,
  51 + 'SourceFile' => $Body,
50 'ACL' => 'public-read', // 设置图片为公共可读,可根据需求修改 52 'ACL' => 'public-read', // 设置图片为公共可读,可根据需求修改
51 ]); 53 ]);
52 return $result['ObjectURL']; 54 return $result['ObjectURL'];