erp/app/Models/GoodsSku.php

75 lines
1.3 KiB
PHP
Raw Normal View History

<?php
namespace App\Models;
2022-07-28 16:06:15 +08:00
use App\Models\traits\Filter;
class GoodsSku extends Model
{
2022-07-28 16:06:15 +08:00
use Filter;
//查询字段
public $fieldSearchable = [
2022-07-28 17:08:05 +08:00
'sku_title',
2022-07-28 16:06:15 +08:00
'status',
];
2022-07-28 13:46:08 +08:00
/**
* 不可批量赋值的属性。为空则所有熟悉都可以批量赋值
*
* @var array
*/
2022-08-09 20:05:19 +08:00
protected $fillable = [
'goods_id',
'title',
'sku_code',
'status',
'num',
'stock',
'cost',
'two_days_ago_num',
'yesterday_num',
'reference_price',
'reserve',
];
2022-07-28 16:06:15 +08:00
protected $hidden = ['created_at'];
2022-07-28 13:46:08 +08:00
2022-07-28 17:08:05 +08:00
/**
* 获取状态
*
* @param string $value
* @return string
*/
public function getStatusAttribute($value)
{
$map = [
0 => '下架',
1 => '在售',
2 => '预警',
];
return $map[$value];
}
2022-07-28 13:46:08 +08:00
/**
* 此规格从属于一个商品
*/
public function goods()
{
return $this->hasOne(Goods::class, 'id', 'goods_id');
}
2022-07-28 17:08:05 +08:00
/**
* 此规格每日记录
*/
public function daily()
{
return $this->hasOne(DailyStockRecord::class, 'sku_id', 'id');
}
2022-08-06 16:38:04 +08:00
public function order()
{
return $this->hasOne(BusinessOrderItem::class, 'external_sku_id', 'id');
}
}