erp/app/Models/Goods.php

53 lines
930 B
PHP
Raw Normal View History

<?php
namespace App\Models;
2022-07-28 13:46:08 +08:00
use App\Models\traits\Filter;
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
public function getImgUrlAttribute($value)
{
if (false !== strpos($value, 'ju8hn6/erp/shop')) {
$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-28 13:46:08 +08:00
public function type()
{
return $this->hasOne(GoodsType::class, 'id', 'type_id');
}
}