- CASCADE FK → 독립 엔티티 + entity_relationships 링크 테이블 - 독립 API 10개 추가 (섹션/필드/BOM CRUD, clone, usage) - SectionTemplate 모델 제거 → ItemSection.is_template 통합 - 페이지-섹션, 섹션-필드, 섹션-BOM 링크/언링크 API 14개 추가 - Swagger 문서 업데이트
68 lines
1.9 KiB
PHP
68 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Services\ItemMaster;
|
|
|
|
use App\Models\ItemMaster\CustomTab;
|
|
use App\Models\ItemMaster\ItemMasterField;
|
|
use App\Models\ItemMaster\ItemPage;
|
|
use App\Models\ItemMaster\ItemSection;
|
|
use App\Models\ItemMaster\UnitOption;
|
|
use App\Services\Service;
|
|
|
|
class ItemMasterService extends Service
|
|
{
|
|
/**
|
|
* 초기화 데이터 로드
|
|
*
|
|
* - pages (섹션/필드 중첩)
|
|
* - sectionTemplates (is_template=true인 섹션)
|
|
* - masterFields
|
|
* - customTabs (columnSetting 포함)
|
|
* - unitOptions
|
|
*/
|
|
public function init(): array
|
|
{
|
|
$tenantId = $this->tenantId();
|
|
|
|
// 1. 페이지 (섹션 → 필드 중첩) - 템플릿 제외
|
|
$pages = ItemPage::with([
|
|
'sections' => function ($query) {
|
|
$query->nonTemplates()->orderBy('order_no');
|
|
},
|
|
'sections.fields' => function ($query) {
|
|
$query->orderBy('order_no');
|
|
},
|
|
'sections.bomItems',
|
|
])
|
|
->where('tenant_id', $tenantId)
|
|
->where('is_active', 1)
|
|
->get();
|
|
|
|
// 2. 섹션 템플릿 (is_template=true인 섹션)
|
|
$sectionTemplates = ItemSection::templates()
|
|
->where('tenant_id', $tenantId)
|
|
->with(['fields', 'bomItems'])
|
|
->get();
|
|
|
|
// 3. 마스터 필드
|
|
$masterFields = ItemMasterField::where('tenant_id', $tenantId)->get();
|
|
|
|
// 4. 커스텀 탭 (컬럼 설정 포함)
|
|
$customTabs = CustomTab::with('columnSetting')
|
|
->where('tenant_id', $tenantId)
|
|
->orderBy('order_no')
|
|
->get();
|
|
|
|
// 5. 단위 옵션
|
|
$unitOptions = UnitOption::where('tenant_id', $tenantId)->get();
|
|
|
|
return [
|
|
'pages' => $pages,
|
|
'sectionTemplates' => $sectionTemplates,
|
|
'masterFields' => $masterFields,
|
|
'customTabs' => $customTabs,
|
|
'unitOptions' => $unitOptions,
|
|
];
|
|
}
|
|
}
|