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

70 lines
1.8 KiB

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