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

68 lines
1.7 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 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. 'on_sale_text',
  15. 'is_infinite_text'
  16. ];
  17. protected $casts = [
  18. 'details_imgs'=>'array',
  19. 'tags'=>'array',
  20. 'spec'=>'array',
  21. ];
  22. public static $_onSale = ['否','是'];
  23. public static $_isInfinite = ['关闭','开启'];
  24. public function getCoverImgUrlAttribute($value)
  25. {
  26. $value = $value ? $value : $this->cover_img;
  27. return $this->imageUrl($value);
  28. }
  29. public function getOnSaleTextAttribute($value)
  30. {
  31. $value = $value ? $value : $this->on_sale;
  32. return isset(self::$_onSale[$value]) ? self::$_onSale[$value] : '';
  33. }
  34. public function getIsInfiniteTextAttribute($value)
  35. {
  36. $value = $value ? $value : $this->is_infinite;
  37. return isset(self::$_isInfinite[$value]) ? self::$_isInfinite[$value] : '';
  38. }
  39. public function ImageBanners(){
  40. return $this->hasMany('\App\Models\v3\GoodsBanners','goods_id','id')->where('type',1);
  41. }
  42. public function VideoBanners(){
  43. return $this->hasMany('\App\Models\v3\GoodsBanners','goods_id','id')->where('type',2);
  44. }
  45. /**
  46. * 处理旧图片
  47. * @param $value
  48. * @return string
  49. */
  50. public function imageUrl($value)
  51. {
  52. if(strripos($value,"http") === false){
  53. return env('OSS_IMG_HOST').'/'.$value;
  54. }else{
  55. return $value;
  56. }
  57. }
  58. }