- 견적확정 시 업체명/현장명/담당자/연락처 필수 검증 추가 (QuoteService) - 작업지시 stats API에 by_process 공정별 카운트 반환 추가 - 작업지시 목록/상세 쿼리에 수주 개소(rootNodes) 연관 로딩 - 작업지시 품목에 sourceOrderItem.node 관계 추가 - 입고관리 완료건 수정 허용 및 재고 차이 조정 - work_order_step_progress 테이블 마이그레이션 - receivings 테이블 options 컬럼 추가 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
54 lines
1.4 KiB
PHP
54 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use Illuminate\Auth\AuthenticationException;
|
|
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
|
|
|
abstract class Service
|
|
{
|
|
/** 활성 테넌트 ID(없으면 null) */
|
|
protected function tenantIdOrNull(): ?int
|
|
{
|
|
$id = app('tenant_id');
|
|
|
|
return $id ? (int) $id : null;
|
|
}
|
|
|
|
/** 활성 테넌트 ID(없으면 400 Bad Request + i18n 메시지로 예외) */
|
|
protected function tenantId(): int
|
|
{
|
|
$id = $this->tenantIdOrNull();
|
|
if (! $id) {
|
|
// ko/error.php 의 'tenant_id' 키 사용
|
|
throw new BadRequestHttpException(__('error.tenant_id'));
|
|
}
|
|
|
|
return $id;
|
|
}
|
|
|
|
/** (선택) API 사용자 ID 필요할 때 401로 던지고 싶다면 */
|
|
protected function apiUserId(): int
|
|
{
|
|
$uid = app('api_user');
|
|
if (! $uid) {
|
|
// Handler에서 AuthenticationException은 401로 처리 중
|
|
throw new AuthenticationException(__('auth.unauthenticated'));
|
|
}
|
|
|
|
return (int) $uid;
|
|
}
|
|
|
|
/**
|
|
* 서비스 컨텍스트 설정 (다른 서비스에서 호출 시 사용)
|
|
* tenant_id, api_user를 명시적으로 설정
|
|
*/
|
|
public function setContext(int $tenantId, int $userId): self
|
|
{
|
|
app()->instance('tenant_id', $tenantId);
|
|
app()->instance('api_user', $userId);
|
|
|
|
return $this;
|
|
}
|
|
}
|