2025-07-23 15:41:01 +09:00
|
|
|
<?php
|
|
|
|
|
|
2025-07-29 13:00:25 +09:00
|
|
|
namespace App\Models\Tenants;
|
2025-07-23 15:41:01 +09:00
|
|
|
|
2025-08-21 09:50:15 +09:00
|
|
|
use App\Models\Commons\File;
|
2025-07-29 16:04:28 +09:00
|
|
|
use App\Models\Members\User;
|
2025-07-29 13:00:25 +09:00
|
|
|
use App\Models\Members\UserRole;
|
|
|
|
|
use App\Models\Members\UserTenant;
|
2025-08-21 18:38:27 +09:00
|
|
|
use App\Models\Permissions\Role;
|
2025-07-29 13:00:25 +09:00
|
|
|
use App\Traits\ModelTrait;
|
2025-07-23 15:41:01 +09:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
|
|
2025-08-21 09:50:15 +09:00
|
|
|
/**
|
|
|
|
|
* @mixin IdeHelperTenant
|
|
|
|
|
*/
|
2025-07-23 15:41:01 +09:00
|
|
|
class Tenant extends Model
|
|
|
|
|
{
|
2025-07-26 14:25:45 +09:00
|
|
|
use SoftDeletes, ModelTrait;
|
2025-07-23 15:41:01 +09:00
|
|
|
|
|
|
|
|
protected $fillable = [
|
2025-08-14 17:20:28 +09:00
|
|
|
'company_name',
|
2025-07-23 15:41:01 +09:00
|
|
|
'code',
|
|
|
|
|
'email',
|
|
|
|
|
'phone',
|
|
|
|
|
'address',
|
2025-08-14 17:20:28 +09:00
|
|
|
'business_num',
|
|
|
|
|
'corp_reg_no',
|
|
|
|
|
'ceo_name',
|
|
|
|
|
'homepage',
|
|
|
|
|
'fax',
|
|
|
|
|
'logo',
|
|
|
|
|
'admin_memo',
|
|
|
|
|
'options',
|
2025-07-23 15:41:01 +09:00
|
|
|
'tenant_st_code',
|
|
|
|
|
'billing_tp_code',
|
|
|
|
|
];
|
|
|
|
|
|
2025-08-14 00:55:08 +09:00
|
|
|
protected $guarded = [
|
|
|
|
|
'id',
|
|
|
|
|
'created_at',
|
|
|
|
|
'updated_at',
|
|
|
|
|
'deleted_at',
|
|
|
|
|
'plan_id',
|
|
|
|
|
'subscription_id',
|
|
|
|
|
];
|
|
|
|
|
|
2025-07-23 15:41:01 +09:00
|
|
|
protected $casts = [
|
|
|
|
|
'trial_ends_at' => 'datetime',
|
|
|
|
|
'expires_at' => 'datetime',
|
|
|
|
|
'last_paid_at' => 'datetime',
|
|
|
|
|
'max_users' => 'integer',
|
2025-09-30 14:35:26 +09:00
|
|
|
'options' => 'array',
|
2025-08-14 00:55:08 +09:00
|
|
|
'created_at' => 'datetime',
|
|
|
|
|
'updated_at' => 'datetime',
|
|
|
|
|
'deleted_at' => 'datetime',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected $hidden = [
|
|
|
|
|
'deleted_at',
|
2025-07-23 15:41:01 +09:00
|
|
|
];
|
|
|
|
|
|
2025-09-30 14:35:26 +09:00
|
|
|
/**
|
|
|
|
|
* 활성화된 테넌트만 조회하는 스코프
|
|
|
|
|
*/
|
|
|
|
|
public function scopeActive($query)
|
|
|
|
|
{
|
|
|
|
|
return $query->whereIn('tenant_st_code', ['trial', 'active']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 테넌트가 활성 상태인지 확인
|
|
|
|
|
*/
|
|
|
|
|
public function isActive(): bool
|
|
|
|
|
{
|
|
|
|
|
return in_array($this->tenant_st_code, ['trial', 'active']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 테넌트가 트라이얼 상태인지 확인
|
|
|
|
|
*/
|
|
|
|
|
public function isTrial(): bool
|
|
|
|
|
{
|
|
|
|
|
return $this->tenant_st_code === 'trial';
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-23 15:41:01 +09:00
|
|
|
// 관계 정의 (예시)
|
|
|
|
|
public function plan()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Plan::class, 'plan_id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function subscription()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Subscription::class, 'subscription_id');
|
|
|
|
|
}
|
2025-07-26 01:23:02 +09:00
|
|
|
|
|
|
|
|
public function userTenants()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(UserTenant::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function users()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany(User::class, 'user_tenants');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function roles()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Role::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function userRoles()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(UserRole::class);
|
|
|
|
|
}
|
2025-07-29 13:00:25 +09:00
|
|
|
|
|
|
|
|
public function files()
|
|
|
|
|
{
|
|
|
|
|
return $this->morphMany(File::class, 'fileable');
|
|
|
|
|
}
|
2025-07-23 15:41:01 +09:00
|
|
|
}
|