链街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.

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