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

55 lines
1.2 KiB

<?php
namespace App\Models;
use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Model;
use App\Models\Store as StoreModel;
class Goods extends Model
{
use HasDateTimeFormatter;
use SoftDeletes;
protected $table = 'lanzu_goods';
protected $dateFormat = 'U';
protected $appends = [
'cover_img_url',
];
protected $casts = [
'details_imgs'=>'array',
'tags'=>'array',
'spec'=>'array',
];
public function getCoverImgUrlAttribute($value)
{
$value = $value ? $value : $this->cover_img;
return $this->imageUrl($value);
}
public function ImageBanners(){
return $this->hasMany('\App\Models\GoodsBanners','goods_id','id')->where('type',1);
}
public function VideoBanners(){
return $this->hasMany('\App\Models\GoodsBanners','goods_id','id')->where('type',2);
}
/**
* 处理旧图片
* @param $value
* @return string
*/
public function imageUrl($value)
{
if(strripos($value,"http") === false){
return env('OSS_IMG_HOST').'/'.$value;
}else{
return $value;
}
}
}