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

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