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.

49 lines
1.1 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <?php
  2. namespace App\Model\v3;
  3. use App\Constants\v3\OssThumbnail;
  4. use App\Model\Model;
  5. use App\Service\v3\Interfaces\AttachmentServiceInterface;
  6. use Hyperf\Database\Model\Builder;
  7. use Hyperf\Database\Model\SoftDeletes;
  8. use Hyperf\Di\Annotation\Inject;
  9. class Category extends Model
  10. {
  11. use SoftDeletes;
  12. /**
  13. * @Inject
  14. * @var AttachmentServiceInterface
  15. */
  16. protected $attachmentService;
  17. protected $table = 'lanzu_category';
  18. protected $appends = [
  19. 'cover_url'
  20. ];
  21. protected function boot(): void
  22. {
  23. parent::boot();
  24. static::addGlobalScope('status', function (Builder $builder) {
  25. $builder->where(['status' => 1])->orderBy('sort', 'desc');
  26. });
  27. }
  28. public function getCoverUrlAttribute()
  29. {
  30. return $this->attachmentService->switchImgToAliOss($this->attributes['cover_img'], OssThumbnail::THUMBNAIL_100_Q90);
  31. }
  32. public function goodsTypes()
  33. {
  34. return $this->hasMany(self::class, 'parent_id', 'id')->with('goodsCategory');
  35. }
  36. public function goodsCategory()
  37. {
  38. return $this->hasMany(GoodsCategory::class, 'category_id', 'id');
  39. }
  40. }