链街Dcat后台
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.

54 lines
1.2 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <?php
  2. namespace App\Models\v3;
  3. use Dcat\Admin\Traits\HasDateTimeFormatter;
  4. use Illuminate\Database\Eloquent\SoftDeletes;
  5. use Illuminate\Database\Eloquent\Model;
  6. class Goods extends Model
  7. {
  8. use HasDateTimeFormatter;
  9. use SoftDeletes;
  10. protected $table = 'lanzu_goods';
  11. protected $dateFormat = 'U';
  12. protected $appends = [
  13. 'cover_img_url',
  14. ];
  15. protected $casts = [
  16. 'details_imgs'=>'array',
  17. 'tags'=>'array',
  18. 'spec'=>'array',
  19. ];
  20. public function getCoverImgUrlAttribute($value)
  21. {
  22. $value = $value ? $value : $this->cover_img;
  23. return $this->imageUrl($value);
  24. }
  25. public function ImageBanners(){
  26. return $this->hasMany('\App\Models\v3\GoodsBanners','goods_id','id')->where('type',1);
  27. }
  28. public function VideoBanners(){
  29. return $this->hasMany('\App\Models\v3\GoodsBanners','goods_id','id')->where('type',2);
  30. }
  31. /**
  32. * 处理旧图片
  33. * @param $value
  34. * @return string
  35. */
  36. public function imageUrl($value)
  37. {
  38. if(strripos($value,"http") === false){
  39. return env('OSS_IMG_HOST').'/'.$value;
  40. }else{
  41. return $value;
  42. }
  43. }
  44. }