style: Laravel Pint 코드 포맷팅 적용
- PSR-12 스타일 가이드 준수 - 302개 파일 스타일 이슈 자동 수정 - 코드 로직 변경 없음 (포맷팅만)
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
use App\Models\Products\ProductComponent;
|
||||
use App\Services\Service;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ProductComponentResolver extends Service
|
||||
@@ -22,9 +21,12 @@ public function __construct(
|
||||
protected function productLikeTypes(): array
|
||||
{
|
||||
$all = config('products.product_like_types', []);
|
||||
$byTenant = Arr::get($all, (string)$this->tenantId, null);
|
||||
$byTenant = Arr::get($all, (string) $this->tenantId, null);
|
||||
|
||||
if (is_array($byTenant) && $byTenant) {
|
||||
return $byTenant;
|
||||
}
|
||||
|
||||
if (is_array($byTenant) && $byTenant) return $byTenant;
|
||||
return Arr::get($all, '*', ['PRODUCT']);
|
||||
}
|
||||
|
||||
@@ -41,11 +43,11 @@ protected function getLinesForParent(int $parentId): array
|
||||
->where('parent_product_id', $parentId)
|
||||
->orderBy('sort_order')->orderBy('id')
|
||||
->get([
|
||||
'id','tenant_id','parent_product_id',
|
||||
'category_id','category_name',
|
||||
'ref_type','ref_id','quantity','sort_order',
|
||||
'id', 'tenant_id', 'parent_product_id',
|
||||
'category_id', 'category_name',
|
||||
'ref_type', 'ref_id', 'quantity', 'sort_order',
|
||||
])
|
||||
->map(fn($r) => $r->getAttributes()) // ✅ 핵심 수정
|
||||
->map(fn ($r) => $r->getAttributes()) // ✅ 핵심 수정
|
||||
->all();
|
||||
|
||||
return $memo[$parentId] = $rows;
|
||||
@@ -57,22 +59,23 @@ protected function resolveNodeInfo(string $refType, int $refId): array
|
||||
if ($refType === 'PRODUCT') {
|
||||
$p = Product::query()
|
||||
->where('tenant_id', $this->tenantId)
|
||||
->find($refId, ['id','code','name','product_type','category_id']);
|
||||
if (!$p) {
|
||||
->find($refId, ['id', 'code', 'name', 'product_type', 'category_id']);
|
||||
if (! $p) {
|
||||
return [
|
||||
'id' => $refId,
|
||||
'code' => null,
|
||||
'name' => null,
|
||||
'id' => $refId,
|
||||
'code' => null,
|
||||
'name' => null,
|
||||
'product_type' => null,
|
||||
'category_id' => null,
|
||||
'category_id' => null,
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => (int) $p->id,
|
||||
'code' => $p->code,
|
||||
'name' => $p->name,
|
||||
'id' => (int) $p->id,
|
||||
'code' => $p->code,
|
||||
'name' => $p->name,
|
||||
'product_type' => $p->product_type,
|
||||
'category_id' => $p->category_id,
|
||||
'category_id' => $p->category_id,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -92,12 +95,12 @@ protected function resolveNodeInfo(string $refType, int $refId): array
|
||||
'category_id',
|
||||
]);
|
||||
|
||||
if (!$m) {
|
||||
if (! $m) {
|
||||
return [
|
||||
'id' => (int) $refId,
|
||||
'code' => null,
|
||||
'name' => null,
|
||||
'unit' => null,
|
||||
'id' => (int) $refId,
|
||||
'code' => null,
|
||||
'name' => null,
|
||||
'unit' => null,
|
||||
'category_id' => null,
|
||||
];
|
||||
}
|
||||
@@ -106,18 +109,18 @@ protected function resolveNodeInfo(string $refType, int $refId): array
|
||||
$displayName = $m->item_name ?: $m->name;
|
||||
|
||||
return [
|
||||
'id' => (int) $m->id,
|
||||
'code' => $m->material_code, // 표준 코드 필드
|
||||
'name' => $displayName, // 사용자에게 보일 이름
|
||||
'unit' => $m->unit,
|
||||
'spec' => $m->specification, // 있으면 프론트에서 활용 가능
|
||||
'id' => (int) $m->id,
|
||||
'code' => $m->material_code, // 표준 코드 필드
|
||||
'name' => $displayName, // 사용자에게 보일 이름
|
||||
'unit' => $m->unit,
|
||||
'spec' => $m->specification, // 있으면 프론트에서 활용 가능
|
||||
'category_id' => $m->category_id,
|
||||
];
|
||||
}
|
||||
|
||||
// 알 수 없는 타입 폴백
|
||||
return [
|
||||
'id' => $refId,
|
||||
'id' => $refId,
|
||||
'code' => null,
|
||||
'name' => null,
|
||||
];
|
||||
@@ -126,31 +129,31 @@ protected function resolveNodeInfo(string $refType, int $refId): array
|
||||
/**
|
||||
* 단일 제품을 루트로 트리를 생성 (재귀 / 사이클 방지 / 깊이 제한)
|
||||
*
|
||||
* @param int $productId 루트 제품 ID
|
||||
* @param int|null $maxDepth 최대 깊이(루트=0). null 이면 config default
|
||||
* @param int $productId 루트 제품 ID
|
||||
* @param int|null $maxDepth 최대 깊이(루트=0). null 이면 config default
|
||||
* @return array 트리 구조
|
||||
*/
|
||||
public function resolveTree(int $productId, ?int $maxDepth = null): array
|
||||
{
|
||||
$maxDepth = $maxDepth ?? (int)config('products.default_tree_depth', 10);
|
||||
$maxDepth = $maxDepth ?? (int) config('products.default_tree_depth', 10);
|
||||
|
||||
$root = Product::query()
|
||||
->where('tenant_id', $this->tenantId)
|
||||
->findOrFail($productId, ['id','code','name','product_type','category_id']);
|
||||
->findOrFail($productId, ['id', 'code', 'name', 'product_type', 'category_id']);
|
||||
|
||||
$visited = []; // 사이클 방지용 (product id 기준)
|
||||
|
||||
$node = [
|
||||
'type' => 'PRODUCT',
|
||||
'id' => $root->id,
|
||||
'code' => $root->code,
|
||||
'name' => $root->name,
|
||||
'type' => 'PRODUCT',
|
||||
'id' => $root->id,
|
||||
'code' => $root->code,
|
||||
'name' => $root->name,
|
||||
'product_type' => $root->product_type,
|
||||
'category_id' => $root->category_id,
|
||||
'quantity' => 1, // 루트는 수량 1로 간주
|
||||
'category' => null, // 루트는 임의
|
||||
'children' => [],
|
||||
'depth' => 0,
|
||||
'category_id' => $root->category_id,
|
||||
'quantity' => 1, // 루트는 수량 1로 간주
|
||||
'category' => null, // 루트는 임의
|
||||
'children' => [],
|
||||
'depth' => 0,
|
||||
];
|
||||
|
||||
$node['children'] = $this->resolveChildren($root->id, 0, $maxDepth, $visited);
|
||||
@@ -160,29 +163,30 @@ public function resolveTree(int $productId, ?int $maxDepth = null): array
|
||||
|
||||
/**
|
||||
* 하위 노드(들) 재귀 확장
|
||||
* @param int $parentId
|
||||
* @param int $depth
|
||||
* @param int $maxDepth
|
||||
* @param array $visited product-id 기준 사이클 방지
|
||||
* @return array
|
||||
*
|
||||
* @param array $visited product-id 기준 사이클 방지
|
||||
*/
|
||||
protected function resolveChildren(int $parentId, int $depth, int $maxDepth, array &$visited): array
|
||||
{
|
||||
// 깊이 제한
|
||||
if ($depth >= $maxDepth) return [];
|
||||
if ($depth >= $maxDepth) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$lines = $this->getLinesForParent($parentId);
|
||||
if (!$lines) return [];
|
||||
if (! $lines) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$productLike = $this->productLikeTypes();
|
||||
$children = [];
|
||||
|
||||
foreach ($lines as $line) {
|
||||
$refType = (string)$line['ref_type'];
|
||||
$refId = (int)$line['ref_id'];
|
||||
$qty = (float)$line['quantity'];
|
||||
$refType = (string) $line['ref_type'];
|
||||
$refId = (int) $line['ref_id'];
|
||||
$qty = (float) $line['quantity'];
|
||||
|
||||
if (!$refType || $refId <= 0) {
|
||||
if (! $refType || $refId <= 0) {
|
||||
// 로그 남기고 스킵
|
||||
// logger()->warning('Invalid component line', ['line' => $line]);
|
||||
continue;
|
||||
@@ -191,26 +195,26 @@ protected function resolveChildren(int $parentId, int $depth, int $maxDepth, arr
|
||||
$info = $this->resolveNodeInfo($refType, $refId);
|
||||
|
||||
$child = [
|
||||
'type' => $refType,
|
||||
'id' => $info['id'] ?? $refId,
|
||||
'code' => $info['code'] ?? null,
|
||||
'name' => $info['name'] ?? null,
|
||||
'product_type'=> $info['product_type'] ?? null,
|
||||
'type' => $refType,
|
||||
'id' => $info['id'] ?? $refId,
|
||||
'code' => $info['code'] ?? null,
|
||||
'name' => $info['name'] ?? null,
|
||||
'product_type' => $info['product_type'] ?? null,
|
||||
'category_id' => $info['category_id'] ?? null,
|
||||
'quantity' => $qty,
|
||||
'category' => [
|
||||
'id' => $line['category_id'],
|
||||
'quantity' => $qty,
|
||||
'category' => [
|
||||
'id' => $line['category_id'],
|
||||
'name' => $line['category_name'],
|
||||
],
|
||||
'sort_order' => (int)$line['sort_order'],
|
||||
'children' => [],
|
||||
'depth' => $depth + 1,
|
||||
'sort_order' => (int) $line['sort_order'],
|
||||
'children' => [],
|
||||
'depth' => $depth + 1,
|
||||
];
|
||||
|
||||
// 제품처럼 자식이 달릴 수 있는 타입이면 재귀
|
||||
if (in_array($refType, $productLike, true)) {
|
||||
// 사이클 방지: 같은 product id 재방문 금지
|
||||
$pid = (int)$child['id'];
|
||||
$pid = (int) $child['id'];
|
||||
if ($pid > 0) {
|
||||
if (isset($visited[$pid])) {
|
||||
$child['cycle'] = true; // 표식만 남기고 children 안탐
|
||||
|
||||
Reference in New Issue
Block a user