- TenantService 생성 (CRUD, 통계, 복원/영구삭제) - API Controller 구현 (HTMX 요청 감지, HTML/JSON 이중 응답) - FormRequest 검증 (StoreTenantRequest, UpdateTenantRequest) - Tenant 모델 확장 (17개 필드, 관계 설정, accessor) - Department, Menu, Role 모델 복사 (admin → mng) - Web Controller 수정 (index/create/edit 화면) - MIGRATION_PLAN.md 작성 (HTMX + API 아키텍처)
134 lines
3.0 KiB
PHP
134 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Tenants;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class Tenant extends Model
|
|
{
|
|
use SoftDeletes;
|
|
|
|
protected $table = 'tenants';
|
|
|
|
protected $fillable = [
|
|
// 기본 정보
|
|
'company_name',
|
|
'code',
|
|
'email',
|
|
'phone',
|
|
// 회사 정보
|
|
'business_num',
|
|
'corp_reg_no',
|
|
'ceo_name',
|
|
'address',
|
|
'homepage',
|
|
'fax',
|
|
// 구독 정보
|
|
'tenant_st_code',
|
|
'billing_tp_code',
|
|
'max_users',
|
|
'trial_ends_at',
|
|
'expires_at',
|
|
'last_paid_at',
|
|
// 관리 메모
|
|
'admin_memo',
|
|
];
|
|
|
|
protected $casts = [
|
|
'max_users' => 'integer',
|
|
'trial_ends_at' => 'datetime',
|
|
'expires_at' => 'datetime',
|
|
'last_paid_at' => 'datetime',
|
|
'created_at' => 'datetime',
|
|
'updated_at' => 'datetime',
|
|
'deleted_at' => 'datetime',
|
|
];
|
|
|
|
/**
|
|
* 활성 테넌트만 조회 (삭제되지 않은 모든 테넌트)
|
|
*/
|
|
public function scopeActive($query)
|
|
{
|
|
return $query->whereNull('deleted_at');
|
|
}
|
|
|
|
/**
|
|
* 관계: 사용자
|
|
*/
|
|
public function users(): HasMany
|
|
{
|
|
return $this->hasMany(User::class, 'tenant_id');
|
|
}
|
|
|
|
/**
|
|
* 관계: 부서
|
|
*/
|
|
public function departments(): HasMany
|
|
{
|
|
return $this->hasMany(\App\Models\Tenants\Department::class, 'tenant_id');
|
|
}
|
|
|
|
/**
|
|
* 관계: 메뉴
|
|
*/
|
|
public function menus(): HasMany
|
|
{
|
|
return $this->hasMany(\App\Models\Commons\Menu::class, 'tenant_id');
|
|
}
|
|
|
|
/**
|
|
* 관계: 역할
|
|
*/
|
|
public function roles(): HasMany
|
|
{
|
|
return $this->hasMany(\App\Models\Permissions\Role::class, 'tenant_id');
|
|
}
|
|
|
|
/**
|
|
* 상태 배지 색상 (Blade 뷰에서 사용)
|
|
*/
|
|
public function getStatusBadgeColorAttribute(): string
|
|
{
|
|
return match($this->tenant_st_code) {
|
|
'active' => 'success',
|
|
'trial' => 'warning',
|
|
'suspended', 'expired' => 'error',
|
|
default => 'neutral',
|
|
};
|
|
}
|
|
|
|
/**
|
|
* 상태 한글명 (Blade 뷰에서 사용)
|
|
*/
|
|
public function getStatusLabelAttribute(): string
|
|
{
|
|
return match($this->tenant_st_code) {
|
|
'trial' => '트라이얼',
|
|
'active' => '활성',
|
|
'suspended' => '정지',
|
|
'expired' => '만료',
|
|
default => $this->tenant_st_code,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* 결제 유형 한글명 (Blade 뷰에서 사용)
|
|
*/
|
|
public function getBillingTypeLabelAttribute(): ?string
|
|
{
|
|
if (!$this->billing_tp_code) {
|
|
return null;
|
|
}
|
|
|
|
return match($this->billing_tp_code) {
|
|
'monthly' => '월간',
|
|
'yearly' => '연간',
|
|
'free' => '무료',
|
|
default => $this->billing_tp_code,
|
|
};
|
|
}
|
|
}
|