2022-07-26 20:05:14 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
2022-07-28 13:46:08 +08:00
|
|
|
use App\Models\traits\Filter;
|
|
|
|
|
|
2022-07-26 20:05:14 +08:00
|
|
|
class Goods extends Model
|
|
|
|
|
{
|
2022-07-28 13:46:08 +08:00
|
|
|
use Filter;
|
|
|
|
|
|
2022-07-28 16:06:15 +08:00
|
|
|
//查询字段
|
|
|
|
|
public $fieldSearchable = [
|
2022-07-28 17:08:05 +08:00
|
|
|
'goods_title',
|
2022-07-28 16:06:15 +08:00
|
|
|
'type_id',
|
|
|
|
|
'brand_id',
|
|
|
|
|
];
|
|
|
|
|
|
2022-08-09 20:05:19 +08:00
|
|
|
protected $fillable = [
|
|
|
|
|
'title',
|
|
|
|
|
'img_url',
|
|
|
|
|
'type_id',
|
|
|
|
|
'brand_id',
|
|
|
|
|
'goods_code',
|
|
|
|
|
];
|
2022-08-03 16:41:15 +08:00
|
|
|
|
2022-08-16 18:24:56 +08:00
|
|
|
public function getImgUrlAttribute($value)
|
|
|
|
|
{
|
2022-08-17 16:21:07 +08:00
|
|
|
if (0 === strpos($value, 'ju8hn6/erp/shop')) {
|
2022-08-16 18:24:56 +08:00
|
|
|
$value = config('filesystems.disks.aliyun.url') . $value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $value;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-28 13:46:08 +08:00
|
|
|
/**
|
|
|
|
|
* 多规格
|
|
|
|
|
*/
|
|
|
|
|
public function skus()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(GoodsSku::class, 'goods_id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function brand()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasOne(GoodsBrand::class, 'id', 'brand_id');
|
|
|
|
|
}
|
2022-07-26 20:05:14 +08:00
|
|
|
|
2022-07-28 13:46:08 +08:00
|
|
|
public function type()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasOne(GoodsType::class, 'id', 'type_id');
|
|
|
|
|
}
|
2022-07-26 20:05:14 +08:00
|
|
|
}
|