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

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