Browse Source

图片的一些预处理

master
weigang 5 years ago
parent
commit
cc5e8a8752
  1. 28
      app/Constants/v3/OssThumbnail.php
  2. 3
      app/Model/v3/Category.php
  3. 8
      app/Model/v3/Goods.php
  4. 8
      app/Model/v3/GoodsActivity.php
  5. 4
      app/Service/v3/Implementations/AttachmentService.php
  6. 4
      app/Service/v3/Implementations/SearchService.php
  7. 2
      app/Service/v3/Implementations/UserCenterBlockService.php

28
app/Constants/v3/OssThumbnail.php

@ -10,8 +10,34 @@ use Hyperf\Constants\Annotation\Constants;
*/
class OssThumbnail extends AbstractConstants
{
/**
* @Message("thumbnail_q30")
*/
const THUMBNAIL_Q30 = '!thumbnail_q30';
/**
* @Message("thumbnail_q50")
*/
const THUMBNAIL_Q50 = '!thumbnail_q50';
/**
* @Message("thumbnail_q80")
*/
const THUMBNAIL_Q80 = '!thumbnail_q80';
/**
* @Message("thumbnail_100_q50")
*/
const THUMBNAIL_100_Q50 = '!thumbnail_100_q50';
const THUMBNAIL_100_Q90 = '!thumbnail_100_q50';
/**
* @Message("thumbnail_300_q80")
*/
const THUMBNAIL_300_Q80 = '!thumbnail_300_q80';
/**
* @Message("thumbnail_600")
*/
const THUMBNAIL_600_Q90 = '!thumbnail_600';
}

3
app/Model/v3/Category.php

@ -2,6 +2,7 @@
namespace App\Model\v3;
use App\Constants\v3\OssThumbnail;
use App\Model\Model;
use App\Service\v3\Interfaces\AttachmentServiceInterface;
use Hyperf\Database\Model\Builder;
@ -34,7 +35,7 @@ class Category extends Model
public function getCoverUrlAttribute()
{
return $this->attachmentService->switchImgToAliOss($this->attributes['cover_img']);
return $this->attachmentService->switchImgToAliOss($this->attributes['cover_img'], OssThumbnail::THUMBNAIL_100_Q90);
}
public function goodsTypes()

8
app/Model/v3/Goods.php

@ -3,6 +3,7 @@
declare (strict_types=1);
namespace App\Model\v3;
use App\Constants\v3\OssThumbnail;
use App\Constants\v3\SsdbKeys;
use App\Model\Model;
use App\Service\v3\Interfaces\AttachmentServiceInterface;
@ -89,7 +90,7 @@ class Goods extends Model
public function getCoverImgAttribute($value)
{
return $this->attachmentService->switchImgToAliOss($value);
return $this->attachmentService->switchImgToAliOss($value, OssThumbnail::THUMBNAIL_600_Q90);
}
public function getMonthSalesAttribute()
@ -117,10 +118,9 @@ class Goods extends Model
public function getDetailsImgsUrlAttribute()
{
$details_imgs = $this->details_imgs;
$img_host = config('alioss.img_host').'/';
return collect($details_imgs)->map(function($item) use ($img_host){
return $img_host . $item;
return collect($details_imgs)->map(function($item) {
return $this->attachmentService->switchImgToAliOss($item);
});
}

8
app/Model/v3/GoodsActivity.php

@ -3,6 +3,7 @@
namespace App\Model\v3;
use App\Constants\v3\Goods as GoodsConstants;
use App\Constants\v3\OssThumbnail;
use App\Constants\v3\SsdbKeys;
use App\Model\Model;
use App\Service\v3\Interfaces\AttachmentServiceInterface;
@ -89,7 +90,7 @@ class GoodsActivity extends Model
public function getCoverImgAttribute($value)
{
return $this->attachmentService->switchImgToAliOss($value);
return $this->attachmentService->switchImgToAliOss($value, OssThumbnail::THUMBNAIL_600_Q90);
}
public function store()
@ -105,10 +106,9 @@ class GoodsActivity extends Model
public function getDetailsImgsUrlAttribute()
{
$details_imgs = $this->details_imgs;
$img_host = config('alioss.img_host').'/';
return collect($details_imgs)->map(function($item) use ($img_host){
return $img_host . $item;
return collect($details_imgs)->map(function($item) {
return $this->attachmentService->switchImgToAliOss($item);
});
}
}

4
app/Service/v3/Implementations/AttachmentService.php

@ -72,7 +72,7 @@ class AttachmentService implements AttachmentServiceInterface
return $baseDir.$path;
}
public function switchImgToAliOss($path, $bucket = 'thumbnail_q50')
public function switchImgToAliOss($path, $bucket = '')
{
if (strpos($path, 'http') === false || strpos($path, 'https') === false) {
$path = config('alioss.img_host') . '/' . $path;
@ -82,6 +82,6 @@ class AttachmentService implements AttachmentServiceInterface
unset($temp[0]);
$path = config('alioss.img_host') . '/' . implode('/', $temp);
}
return $path . '!' . $bucket;
return $path . $bucket;
}
}

4
app/Service/v3/Implementations/SearchService.php

@ -18,9 +18,7 @@ class SearchService implements SearchServiceInterface
{
$builder = Goods::query()
->with(['store' => function($query) {
return $query->select(['id', 'logo', 'name']);
}])
->with(['store'])
->where(['market_id' => $params['market_id']])
->where(function ($query) {
$query->where('inventory', '>', 0)->orWhere('is_infinite', '=', 1);

2
app/Service/v3/Implementations/UserCenterBlockService.php

@ -45,7 +45,7 @@ class UserCenterBlockService implements UserCenterBlockServiceInterface
$blocks[] = [
'type' => 'store_user',
'title' => '商相关',
'title' => '商相关',
'items' => [
['name' => '商家入口', 'icon' => $img_host . 'user_icons/shop_enter.png', 'type' => 'page', 'path' => '/pages/shopLogin/shopLogin','command'=>'store_login']
]

Loading…
Cancel
Save