diff --git a/app/Controller/v3/GoodsController.php b/app/Controller/v3/GoodsController.php index b3a8ff9..7846c01 100644 --- a/app/Controller/v3/GoodsController.php +++ b/app/Controller/v3/GoodsController.php @@ -54,7 +54,17 @@ class GoodsController extends BaseController //如果没有banner数据,使用商品cover图 if(count($res['banner']) == 0){ - $res['banner'] = [$res['detail']['cover_img']]; + // $res['banner'] = [$res['detail']['cover_img']]; + $res['banner'] = [[ + 'banner_url' => $res['detail']['cover_img'], + 'goods_id' => $goodsId, + 'type' => 1, + 'path' => $res['detail']['cover_img'], + 'created_at' => '', + 'updated_at' => '', + 'deleted_at' => '', + 'sort' => '', + ]]; } //如果存在用户ID则请求 购物车和收藏店铺信息 if(isset($params['user_id'])) { diff --git a/app/Model/v3/GoodsBanner.php b/app/Model/v3/GoodsBanner.php index ca0fb25..3f27542 100644 --- a/app/Model/v3/GoodsBanner.php +++ b/app/Model/v3/GoodsBanner.php @@ -2,12 +2,20 @@ namespace App\Model\v3; +use App\Constants\v3\OssThumbnail; use App\Model\Model; -use Hyperf\Database\Model\Builder; +use App\Service\v3\Interfaces\AttachmentServiceInterface; use Hyperf\Database\Model\SoftDeletes; +use Hyperf\Di\Annotation\Inject; class GoodsBanner extends Model { + + /** + * @var AttachmentServiceInterface + */ + protected $attachmentService; + use SoftDeletes; protected $table = 'lanzu_goods_banners_new'; @@ -18,11 +26,13 @@ class GoodsBanner extends Model public function getBannerUrlAttribute() { - $url = $this->attributes['path']; - if(strripos($url,"http") === false){ - return config('alioss.img_host').'/'.$url; - }else{ - return $url; - } + // $url = $this->attributes['path']; + // if(strripos($url,"http") === false){ + // return config('alioss.img_host').'/'.$url; + // }else{ + // return $url; + // } + + return $this->attachmentService->switchImgToAliOss($this->attributes['path'], OssThumbnail::THUMBNAIL_600_Q90); } } \ No newline at end of file