80 lines
1.7 KiB
PHP
80 lines
1.7 KiB
PHP
<?php
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class Goods extends Model
|
|
{
|
|
use SoftDeletes;
|
|
|
|
protected $table = 'goods';
|
|
|
|
protected $fillable = [
|
|
'name',
|
|
'code',
|
|
'barcode',
|
|
'category',
|
|
'unit',
|
|
'weight',
|
|
'retail_price',
|
|
'cost_price',
|
|
'stock_warning',
|
|
'type',
|
|
'custom_id',
|
|
'packaging_cost',
|
|
'shipping_packaging_cost',
|
|
'volume',
|
|
'length',
|
|
'width',
|
|
'height',
|
|
'brand_id',
|
|
'batch_management',
|
|
];
|
|
|
|
protected $casts = [
|
|
'weight' => 'decimal:2',
|
|
'retail_price' => 'decimal:2',
|
|
'cost_price' => 'decimal:2',
|
|
'packaging_cost' => 'decimal:2',
|
|
'shipping_packaging_cost' => 'decimal:2',
|
|
'volume' => 'decimal:2',
|
|
'length' => 'decimal:2',
|
|
'width' => 'decimal:2',
|
|
'height' => 'decimal:2',
|
|
'batch_management' => 'boolean',
|
|
];
|
|
|
|
/**
|
|
* 关联品牌
|
|
*/
|
|
public function brand()
|
|
{
|
|
return $this->belongsTo(Brand::class);
|
|
}
|
|
|
|
/**
|
|
* 关联供应商(多对多)
|
|
*/
|
|
public function suppliers()
|
|
{
|
|
return $this->belongsToMany(Supplier::class, 'goods_supplier');
|
|
}
|
|
|
|
/**
|
|
* 如果是组合商品,关联子商品
|
|
*/
|
|
public function comboItems()
|
|
{
|
|
return $this->hasMany(ComboItem::class, 'combo_goods_id');
|
|
}
|
|
|
|
/**
|
|
* 作为子商品时,被哪些组合商品包含
|
|
*/
|
|
public function parentCombos()
|
|
{
|
|
return $this->belongsToMany(Goods::class, 'combo_items', 'goods_id', 'combo_goods_id')
|
|
->withPivot('quantity');
|
|
}
|
|
} |