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.

48 lines
1.1 KiB

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