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

<?php
namespace App\Models\v3;
use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Model;
class GoodsActivity extends Model
{
use HasDateTimeFormatter;
use SoftDeletes;
protected $table = 'lanzu_goods_activity';
protected $dateFormat = 'U';
protected $appends = [
'cover_img_url',
'on_sale_text',
'is_infinite_text',
'can_use_coupon_text',
'expire_time_text'
];
protected $casts = [
'details_imgs'=>'array',
// 'tags'=>'array',
// 'market_ids'=>'array',
'spec'=>'array',
];
public static $_type = ['flash_sale'=>'秒杀','group_buy'=>'团购','new_product'=>'新品'];
public static $_onSale = ['否','是'];
public static $_isInfinite = ['关闭','开启'];
public static $_canUseCoupon = ['否','是'];
public function getCoverImgUrlAttribute($value)
{
$value = $value ? $value : $this->cover_img;
return $this->imageUrl($value);
}
public function getTypeTextAttribute($value)
{
$value = $value ? $value : $this->type;
return isset(self::$_isInfinite[$value]) ? self::$_isInfinite[$value] : '';
}
public function getOnSaleTextAttribute($value)
{
$value = $value ? $value : $this->on_sale;
return isset(self::$_onSale[$value]) ? self::$_onSale[$value] : '';
}
public function getIsInfiniteTextAttribute($value)
{
$value = $value ? $value : $this->is_infinite;
return isset(self::$_isInfinite[$value]) ? self::$_isInfinite[$value] : '';
}
public function getCanUseCouponTextAttribute($value)
{
$value = $value ? $value : $this->can_use_coupon;
return isset(self::$_isInfinite[$value]) ? self::$_isInfinite[$value] : '';
}
public function getExpireTimeTextAttribute()
{
$value = $this->expire_time;
return empty($value) ? '' : date('Y-m-d H:i:s',$value);
}
public function ImageBanners(){
return $this->hasMany('\App\Models\v3\GoodsActivityBanners','goods_id','id')->where('type',1);
}
public function VideoBanners(){
return $this->hasMany('\App\Models\v3\GoodsActivityBanners','goods_id','id')->where('type',2);
}
public function setExpireTimeAttribute($value){
$this->attributes['expire_time'] = strtotime($value);
}
/**
* 处理旧图片
* @param $value
* @return string
*/
public function imageUrl($value)
{
if(strripos($value,"http") === false){
return env('OSS_IMG_HOST').'/'.$value;
}else{
return $value;
}
}
}