You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.1 KiB
50 lines
1.1 KiB
<?php
|
|
|
|
namespace App\Model\v3;
|
|
|
|
use App\Constants\v3\OssThumbnail;
|
|
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 = [
|
|
'cover_url'
|
|
];
|
|
|
|
protected function boot(): void
|
|
{
|
|
parent::boot();
|
|
static::addGlobalScope('status', function (Builder $builder) {
|
|
$builder->where(['status' => 1])->orderBy('sort', 'desc');
|
|
});
|
|
}
|
|
|
|
public function getCoverUrlAttribute()
|
|
{
|
|
return $this->attachmentService->switchImgToAliOss($this->attributes['cover_img'], OssThumbnail::THUMBNAIL_100_Q90);
|
|
}
|
|
|
|
public function goodsTypes()
|
|
{
|
|
return $this->hasMany(self::class, 'parent_id', 'id')->with('goodsCategory');
|
|
}
|
|
|
|
public function goodsCategory()
|
|
{
|
|
return $this->hasMany(GoodsCategory::class, 'category_id', 'id');
|
|
}
|
|
}
|