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.

42 lines
966 B

6 years ago
6 years ago
  1. <?php
  2. namespace App\Model\v3;
  3. use App\Model\Model;
  4. use Hyperf\Database\Model\Builder;
  5. use Hyperf\Database\Model\SoftDeletes;
  6. class Category extends Model
  7. {
  8. use SoftDeletes;
  9. protected $table = 'lanzu_category';
  10. protected $appends = [
  11. 'goods_types',
  12. 'cover_url'
  13. ];
  14. protected function boot(): void
  15. {
  16. parent::boot();
  17. static::addGlobalScope('status', function (Builder $builder) {
  18. $builder->where(['status' => 1])->orderBy('sort', 'desc');
  19. });
  20. }
  21. public function getGoodsTypesAttribute()
  22. {
  23. return self::query()->where(['parent_id' => $this->attributes['id']])->orderBy('sort', 'desc')->get()->toArray();
  24. }
  25. public function getCoverUrlAttribute()
  26. {
  27. $url = $this->attributes['cover_img'];
  28. if(strripos($url,"http") === false){
  29. return config('alioss.img_host').'/'.$url;
  30. }else{
  31. return $url;
  32. }
  33. }
  34. }