fix : 카테고리, 제품등록, BOM등록 API (일부 개발 - BOM 추가 작업 필요)
This commit is contained in:
@@ -2,29 +2,92 @@
|
||||
|
||||
namespace App\Models\Products;
|
||||
|
||||
use App\Traits\BelongsToTenant;
|
||||
use App\Traits\ModelTrait;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use App\Traits\ModelTrait;
|
||||
use App\Traits\BelongsToTenant;
|
||||
|
||||
class ProductComponent extends Model
|
||||
{
|
||||
use SoftDeletes, BelongsToTenant, ModelTrait;
|
||||
use SoftDeletes, ModelTrait, BelongsToTenant;
|
||||
|
||||
protected $table = 'product_components';
|
||||
|
||||
protected $fillable = [
|
||||
'tenant_id','parent_product_id','child_product_id',
|
||||
'quantity','sort_order','is_default',
|
||||
'created_by','updated_by'
|
||||
'tenant_id',
|
||||
'parent_product_id',
|
||||
'ref_type',
|
||||
'child_product_id',
|
||||
'material_id',
|
||||
'quantity',
|
||||
'sort_order',
|
||||
'is_default',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'quantity' => 'decimal:4',
|
||||
'sort_order' => 'integer',
|
||||
'is_default' => 'boolean',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
'deleted_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function parent() { return $this->belongsTo(Product::class, 'parent_product_id'); }
|
||||
public function child() { return $this->belongsTo(Product::class, 'child_product_id'); }
|
||||
protected $hidden = [
|
||||
'deleted_at',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 상위 제품 (모델/제품)
|
||||
*/
|
||||
public function parentProduct()
|
||||
{
|
||||
return $this->belongsTo(Product::class, 'parent_product_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 하위 제품 (ref_type = PRODUCT일 때만 의미 있음)
|
||||
*/
|
||||
public function childProduct()
|
||||
{
|
||||
return $this->belongsTo(Product::class, 'child_product_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 하위 자재 (ref_type = MATERIAL일 때만 의미 있음)
|
||||
*/
|
||||
public function material()
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Materials\Material::class, 'material_id');
|
||||
}
|
||||
|
||||
// ---------------------------------------------------
|
||||
// 🔎 Query Scopes
|
||||
// ---------------------------------------------------
|
||||
|
||||
/**
|
||||
* 제품 BOM 아이템만
|
||||
*/
|
||||
public function scopeProducts($query)
|
||||
{
|
||||
return $query->where('ref_type', 'PRODUCT');
|
||||
}
|
||||
|
||||
/**
|
||||
* 자재 BOM 아이템만
|
||||
*/
|
||||
public function scopeMaterials($query)
|
||||
{
|
||||
return $query->where('ref_type', 'MATERIAL');
|
||||
}
|
||||
|
||||
/**
|
||||
* 특정 상위 제품의 BOM
|
||||
*/
|
||||
public function scopeForParent($query, int $parentProductId)
|
||||
{
|
||||
return $query->where('parent_product_id', $parentProductId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user