Files
sam-api/app/Models/Tenants/Department.php
kent 638e87b05d feat: 급여 관리 API 및 더미 시더 확장
- 급여 관리 API 추가 (SalaryController, SalaryService, Salary 모델)
  - 급여 목록/상세/등록/수정/삭제
  - 상태 변경 (scheduled/completed)
  - 일괄 상태 변경
  - 통계 조회
- 더미 시더 확장
  - 근태, 휴가, 부서, 사용자 시더 추가
  - 기존 시더 tenant_id/created_by/updated_by 필드 추가
- 부서 서비스 개선 (tree 조회 기능 추가)
- 카드 서비스 수정

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-25 03:48:32 +09:00

69 lines
1.9 KiB
PHP

<?php
namespace App\Models\Tenants;
use App\Models\Members\User;
use App\Models\Permissions\PermissionOverride;
use App\Models\Tenants\Pivots\DepartmentUser;
use App\Traits\ModelTrait;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\Permission\Traits\HasRoles;
class Department extends Model
{
use HasRoles, ModelTrait, SoftDeletes; // 부서도 권한/역할을 가짐
protected $table = 'departments';
protected $guarded = ['id'];
protected $casts = [
'tenant_id' => 'int',
'parent_id' => 'int',
'is_active' => 'bool',
'sort_order' => 'int',
];
protected $hidden = [
'deleted_by', 'deleted_at',
];
// 스파티 가드명(프로젝트 설정에 맞게 조정)
protected string $guard_name = 'web';
/** 상위/하위 부서 */
public function parent(): BelongsTo
{
return $this->belongsTo(self::class, 'parent_id');
}
public function children()
{
return $this->hasMany(self::class, 'parent_id');
}
/** 부서-사용자 N:N (추가 컬럼 포함 Pivot) */
public function users()
{
return $this->belongsToMany(User::class, 'department_user')
->using(DepartmentUser::class)
->withTimestamps()
->withPivot(['tenant_id', 'is_primary', 'joined_at', 'left_at']);
}
/** 부서의 권한 오버라이드(DENY/임시허용) */
public function permissionOverrides(): MorphMany
{
return $this->morphMany(PermissionOverride::class, 'model');
}
/** 부서-사용자 매핑 로우들(피벗 테이블의 레코드들) */
public function departmentUsers()
{
return $this->hasMany(DepartmentUser::class, 'department_id');
}
}