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']) {