From 7bac26deb4e770d61535b727fb29fafde396749d Mon Sep 17 00:00:00 2001 From: weigang Date: Thu, 10 Sep 2020 15:16:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E7=B1=BB=EF=BC=8C=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Model/v3/Category.php | 24 ++++++++++++------- app/Model/v3/GoodsCategory.php | 10 ++++++++ .../v3/Implementations/SearchService.php | 3 ++- 3 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 app/Model/v3/GoodsCategory.php diff --git a/app/Model/v3/Category.php b/app/Model/v3/Category.php index b877e4d..7c3eaa6 100644 --- a/app/Model/v3/Category.php +++ b/app/Model/v3/Category.php @@ -3,18 +3,27 @@ namespace App\Model\v3; use App\Model\Model; +use App\Service\v3\Interfaces\AttachmentServiceInterface; use Hyperf\Database\Model\Builder; use Hyperf\Database\Model\SoftDeletes; +use Hyperf\Di\Annotation\Inject; class Category extends Model { use SoftDeletes; + /** + * @Inject + * @var AttachmentServiceInterface + */ + protected $attachmentService; + protected $table = 'lanzu_category'; protected $appends = [ 'goods_types', - 'cover_url' + 'cover_url', + 'goods_category_ids', ]; protected function boot(): void @@ -29,15 +38,14 @@ class Category extends Model { return self::query()->where(['parent_id' => $this->attributes['id']])->orderBy('sort', 'desc')->get()->toArray(); } + + public function getGoodsCategoryIdsAttribute() + { + return GoodsCategory::query()->where(['category_id' => $this->attributes['id']])->orderBy('sort', 'desc')->pluck('id'); + } public function getCoverUrlAttribute() { - $url = $this->attributes['cover_img']; - - if(strripos($url,"http") === false){ - return config('alioss.img_host').'/'.$url; - }else{ - return $url; - } + return $this->attachmentService->switchImgToAliOss($this->attributes['cover_img']); } } \ No newline at end of file diff --git a/app/Model/v3/GoodsCategory.php b/app/Model/v3/GoodsCategory.php new file mode 100644 index 0000000..e60c54a --- /dev/null +++ b/app/Model/v3/GoodsCategory.php @@ -0,0 +1,10 @@ +where('inventory', '>', 0); if (isset($params['type_id']) && $params['type_id']) { - $builder->where(['category_id' => $params['type_id']]); + $typeIds = explode(',', $params['type_id']); + $builder->whereIn('goods_category_id', $typeIds); } if (isset($params['keyword']) && $params['keyword']) {