88 lines
2.5 KiB
PHP
88 lines
2.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use Database\Factories\TenantFactory;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
/**
|
|
* Тенант — клиент SaaS-портала Лидерра.
|
|
*
|
|
* Saas-уровневая модель: НЕ имеет RLS-политик (тенанты создаются и
|
|
* управляются админкой SaaS). Используется как родительский ресурс
|
|
* для всех tenant-aware моделей (User, Project, Deal и др.).
|
|
*
|
|
* Источник: db/schema.sql v8.6 §3, table `tenants`.
|
|
*
|
|
* @mixin IdeHelperTenant
|
|
*/
|
|
class Tenant extends Model
|
|
{
|
|
/** @use HasFactory<TenantFactory> */
|
|
use HasFactory, SoftDeletes;
|
|
|
|
protected $fillable = [
|
|
'subdomain',
|
|
'organization_name',
|
|
'contact_email',
|
|
'timezone',
|
|
'locale',
|
|
'current_tariff_id',
|
|
'balance_rub',
|
|
'balance_leads',
|
|
'is_trial',
|
|
'trial_leads_used',
|
|
'last_activity_at',
|
|
'last_webhook_at',
|
|
'desired_daily_numbers',
|
|
'delivered_in_month',
|
|
'api_key_limit',
|
|
'limits',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'is_trial' => 'boolean',
|
|
'balance_rub' => 'decimal:2',
|
|
'chargeback_unrecovered_rub' => 'decimal:2',
|
|
'balance_leads' => 'integer',
|
|
'trial_leads_used' => 'integer',
|
|
'desired_daily_numbers' => 'integer',
|
|
'delivered_in_month' => 'integer',
|
|
'api_key_limit' => 'integer',
|
|
// JSONB: {"max_users":5,"max_projects":10,"api_rps":60}
|
|
'limits' => 'array',
|
|
'last_activity_at' => 'datetime',
|
|
'last_webhook_at' => 'datetime',
|
|
'created_at' => 'datetime',
|
|
'updated_at' => 'datetime',
|
|
'deleted_at' => 'datetime',
|
|
];
|
|
}
|
|
|
|
/** @return HasMany<User, $this> */
|
|
public function users(): HasMany
|
|
{
|
|
return $this->hasMany(User::class);
|
|
}
|
|
|
|
/** @return HasMany<Project, $this> */
|
|
public function projects(): HasMany
|
|
{
|
|
return $this->hasMany(Project::class);
|
|
}
|
|
|
|
/** @return BelongsTo<TariffPlan, $this> */
|
|
public function tariff(): BelongsTo
|
|
{
|
|
return $this->belongsTo(TariffPlan::class, 'current_tariff_id');
|
|
}
|
|
}
|