refactor: products/materials 테이블 및 관련 코드 삭제
- products, materials, product_components 테이블 삭제 마이그레이션 - FK 제약조건 정리 (orders, order_items, material_receipts, lots) - 관련 Models 삭제: Product, Material, ProductComponent 등 - 관련 Controllers 삭제: ProductController, MaterialController, ProductBomItemController - 관련 Services 삭제: ProductService, MaterialService, ProductBomService - 관련 Requests, Swagger 파일 삭제 - 라우트 정리: /products, /materials 엔드포인트 제거 모든 품목 관리는 /items 엔드포인트로 통합됨 item_id_mappings 테이블에 ID 매핑 보존 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,115 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Products;
|
||||
|
||||
use App\Models\Materials\Material;
|
||||
use App\Traits\BelongsToTenant;
|
||||
use App\Traits\ModelTrait;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class ProductComponent extends Model
|
||||
{
|
||||
use BelongsToTenant, ModelTrait, SoftDeletes;
|
||||
|
||||
protected $table = 'product_components';
|
||||
|
||||
protected $fillable = [
|
||||
'tenant_id',
|
||||
'parent_product_id',
|
||||
'category_id',
|
||||
'category_name',
|
||||
'ref_type',
|
||||
'ref_id',
|
||||
'quantity',
|
||||
'sort_order',
|
||||
// 하이브리드 구조: 고정 필드 (범용 BOM 계산)
|
||||
'quantity_formula',
|
||||
'condition',
|
||||
// 동적 필드 (테넌트별 커스텀)
|
||||
'attributes',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'quantity' => 'decimal:6',
|
||||
'attributes' => 'array',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
'deleted_at' => 'datetime',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'deleted_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* 상위 제품 (모델/제품)
|
||||
*/
|
||||
public function parentProduct()
|
||||
{
|
||||
return $this->belongsTo(Product::class, 'parent_product_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 참조된 제품 또는 자재를 동적으로 가져오기
|
||||
* ref_type에 따라 Product 또는 Material을 반환
|
||||
*/
|
||||
public function referencedItem()
|
||||
{
|
||||
if ($this->ref_type === 'PRODUCT') {
|
||||
return $this->belongsTo(Product::class, 'ref_id');
|
||||
} elseif ($this->ref_type === 'MATERIAL') {
|
||||
return $this->belongsTo(Material::class, 'ref_id');
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 하위 제품 (ref_type = PRODUCT일 때만)
|
||||
*/
|
||||
public function product()
|
||||
{
|
||||
return $this->belongsTo(Product::class, 'ref_id')
|
||||
->where('ref_type', 'PRODUCT');
|
||||
}
|
||||
|
||||
/**
|
||||
* 하위 자재 (ref_type = MATERIAL일 때만)
|
||||
*/
|
||||
public function material()
|
||||
{
|
||||
return $this->belongsTo(Material::class, 'ref_id')
|
||||
->where('ref_type', 'MATERIAL');
|
||||
}
|
||||
|
||||
// ---------------------------------------------------
|
||||
// 🔎 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