|
|
|
@ -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 |
|
|
|
@ -30,14 +39,13 @@ class Category extends Model |
|
|
|
return self::query()->where(['parent_id' => $this->attributes['id']])->orderBy('sort', 'desc')->get()->toArray(); |
|
|
|
} |
|
|
|
|
|
|
|
public function getCoverUrlAttribute() |
|
|
|
public function getGoodsCategoryIdsAttribute() |
|
|
|
{ |
|
|
|
$url = $this->attributes['cover_img']; |
|
|
|
|
|
|
|
if(strripos($url,"http") === false){ |
|
|
|
return config('alioss.img_host').'/'.$url; |
|
|
|
}else{ |
|
|
|
return $url; |
|
|
|
return GoodsCategory::query()->where(['category_id' => $this->attributes['id']])->orderBy('sort', 'desc')->pluck('id'); |
|
|
|
} |
|
|
|
|
|
|
|
public function getCoverUrlAttribute() |
|
|
|
{ |
|
|
|
return $this->attachmentService->switchImgToAliOss($this->attributes['cover_img']); |
|
|
|
} |
|
|
|
} |