- 급여 관리 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>
111 lines
2.8 KiB
PHP
111 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Members;
|
|
|
|
use App\Models\Commons\File;
|
|
use App\Models\Tenants\Tenant;
|
|
use App\Models\Tenants\TenantUserProfile;
|
|
use App\Traits\ModelTrait;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Laravel\Sanctum\HasApiTokens;
|
|
use Spatie\Permission\Traits\HasRoles;
|
|
|
|
/**
|
|
* @mixin IdeHelperUser
|
|
*/
|
|
class User extends Authenticatable
|
|
{
|
|
use HasApiTokens, HasRoles, ModelTrait, Notifiable, SoftDeletes;
|
|
|
|
protected $guard_name = 'api'; // ★ 중요: 권한/역할 가드 통일
|
|
|
|
protected $fillable = [
|
|
'user_id',
|
|
'name',
|
|
'email',
|
|
'phone',
|
|
'password',
|
|
'options',
|
|
'profile_photo_path',
|
|
];
|
|
|
|
protected $casts = [
|
|
'email_verified_at' => 'datetime',
|
|
'last_login_at' => 'datetime',
|
|
'options' => 'array',
|
|
'deleted_at' => 'datetime',
|
|
'password' => 'hashed', // ← 이걸 쓰면 자동 해싱
|
|
];
|
|
|
|
protected $hidden = [
|
|
'password', 'remember_token',
|
|
'two_factor_secret', 'two_factor_recovery_codes', 'two_factor_confirmed_at',
|
|
'deleted_at',
|
|
];
|
|
|
|
protected $appends = [
|
|
'has_account',
|
|
];
|
|
|
|
/**
|
|
* 시스템 계정(비밀번호) 보유 여부
|
|
*/
|
|
public function getHasAccountAttribute(): bool
|
|
{
|
|
return ! empty($this->password);
|
|
}
|
|
|
|
public function userTenants()
|
|
{
|
|
return $this->hasMany(UserTenant::class);
|
|
}
|
|
|
|
public function userTenant()
|
|
{
|
|
return $this->hasOne(UserTenant::class)->where('is_default', 1);
|
|
}
|
|
|
|
public function userRoles()
|
|
{
|
|
return $this->hasMany(UserRole::class);
|
|
}
|
|
|
|
public function userTenantById($tenantId)
|
|
{
|
|
return $this->hasOne(UserTenant::class)->where('tenant_id', $tenantId);
|
|
}
|
|
|
|
public function files()
|
|
{
|
|
return $this->morphMany(File::class, 'fileable');
|
|
}
|
|
|
|
public function tenantsMembership(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(Tenant::class, 'user_tenants', 'user_id', 'tenant_id')
|
|
->as('membership') // pivot 대신 membership으로 표기
|
|
->withPivot(['is_active', 'is_default', 'joined_at', 'left_at', 'deleted_at'])
|
|
->wherePivotNull('deleted_at'); // 소프트삭제 제외
|
|
}
|
|
|
|
/**
|
|
* 테넌트별 사용자 프로필 (전체)
|
|
*/
|
|
public function tenantProfiles()
|
|
{
|
|
return $this->hasMany(TenantUserProfile::class);
|
|
}
|
|
|
|
/**
|
|
* 현재 테넌트의 사용자 프로필
|
|
* 주의: 조회 시 tenant_id 조건 추가 필요
|
|
*/
|
|
public function tenantProfile()
|
|
{
|
|
return $this->hasOne(TenantUserProfile::class);
|
|
}
|
|
}
|