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

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