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

91 lines
2.7 KiB

  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 GoodsActivity extends Model
  7. {
  8. use HasDateTimeFormatter;
  9. use SoftDeletes;
  10. protected $table = 'lanzu_goods_activity';
  11. protected $dateFormat = 'U';
  12. protected $appends = [
  13. 'cover_img_url',
  14. 'on_sale_text',
  15. 'is_infinite_text',
  16. 'can_use_coupon_text',
  17. 'expire_time_text'
  18. ];
  19. protected $casts = [
  20. 'details_imgs'=>'array',
  21. // 'tags'=>'array',
  22. // 'market_ids'=>'array',
  23. 'spec'=>'array',
  24. ];
  25. public static $_type = ['flash_sale'=>'秒杀','group_buy'=>'团购','new_product'=>'新品'];
  26. public static $_onSale = ['否','是'];
  27. public static $_isInfinite = ['关闭','开启'];
  28. public static $_canUseCoupon = ['否','是'];
  29. public function getCoverImgUrlAttribute($value)
  30. {
  31. $value = $value ? $value : $this->cover_img;
  32. return $this->imageUrl($value);
  33. }
  34. public function getTypeTextAttribute($value)
  35. {
  36. $value = $value ? $value : $this->type;
  37. return isset(self::$_isInfinite[$value]) ? self::$_isInfinite[$value] : '';
  38. }
  39. public function getOnSaleTextAttribute($value)
  40. {
  41. $value = $value ? $value : $this->on_sale;
  42. return isset(self::$_onSale[$value]) ? self::$_onSale[$value] : '';
  43. }
  44. public function getIsInfiniteTextAttribute($value)
  45. {
  46. $value = $value ? $value : $this->is_infinite;
  47. return isset(self::$_isInfinite[$value]) ? self::$_isInfinite[$value] : '';
  48. }
  49. public function getCanUseCouponTextAttribute($value)
  50. {
  51. $value = $value ? $value : $this->can_use_coupon;
  52. return isset(self::$_isInfinite[$value]) ? self::$_isInfinite[$value] : '';
  53. }
  54. public function getExpireTimeTextAttribute()
  55. {
  56. $value = $this->expire_time;
  57. return empty($value) ? '' : date('Y-m-d H:i:s',$value);
  58. }
  59. public function ImageBanners(){
  60. return $this->hasMany('\App\Models\v3\GoodsActivityBanners','goods_id','id')->where('type',1);
  61. }
  62. public function VideoBanners(){
  63. return $this->hasMany('\App\Models\v3\GoodsActivityBanners','goods_id','id')->where('type',2);
  64. }
  65. public function setExpireTimeAttribute($value){
  66. $this->attributes['expire_time'] = strtotime($value);
  67. }
  68. /**
  69. * 处理旧图片
  70. * @param $value
  71. * @return string
  72. */
  73. public function imageUrl($value)
  74. {
  75. if(strripos($value,"http") === false){
  76. return env('OSS_IMG_HOST').'/'.$value;
  77. }else{
  78. return $value;
  79. }
  80. }
  81. }