diff --git a/app/common/controller/UsedCarController.php b/app/common/controller/UsedCarController.php index 08a9d0b..936ccd8 100644 --- a/app/common/controller/UsedCarController.php +++ b/app/common/controller/UsedCarController.php @@ -97,8 +97,10 @@ class UsedCarController extends BaseController $images = explode(',', $data['images']); $ossService = new OssService(); $images_pull = []; + //图片压缩参数 resize,w_1200:最大宽度1200px,quality,Q_50:图片质量如压缩到50%,format,webp:自动转 WebP + $process = 'image/resize,w_1000/quality,Q_60/format,webp'; foreach ($images as $image){ - $images_pull[] = $ossService->generatePrivateUrl($image); + $images_pull[] = $ossService->generatePrivateUrlResize($image,3600,$process); } $data['images_pull'] = $images_pull; diff --git a/app/common/service/OssService.php b/app/common/service/OssService.php index 1aacc1c..502d641 100644 --- a/app/common/service/OssService.php +++ b/app/common/service/OssService.php @@ -57,6 +57,20 @@ class OssService return $this->ossClient->signUrl($this->bucket, $objectKey, $expireTime); } + /** + * 生成图片的私有访问 URL + * @param string $objectKey + * @return string + */ + public function generatePrivateUrlResize($objectKey, $expireTime = 3600,$process = 'x-oss-process='.'image/resize,w_1200/quality,Q_50/format,webp') + { + // 生成 OSS 私有 URL(有效期为 3600 秒) + return $this->ossClient->signUrl($this->bucket, $objectKey, $expireTime,'GET', + [ + 'x-oss-process' => $process + ]); + } + /** * 删除 OSS 上的文件 * @param string $objectKey OSS上存储的对象名称 diff --git a/app/common/service/UsedCarService.php b/app/common/service/UsedCarService.php index 89cc54d..c3ea068 100644 --- a/app/common/service/UsedCarService.php +++ b/app/common/service/UsedCarService.php @@ -61,7 +61,7 @@ class UsedCarService if (isset($p['scene']) && $p['scene'] == 'self') { $config['where']['user_id'] = $request->user['id']; - $config['where']['role'] = $request->user['role']; + unset($config['where']['role']); unset( $config['where']['status']); }