80 lines
2.0 KiB
PHP
80 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
/**
|
|
* PlanModel - Модель тарифов
|
|
*/
|
|
class PlanModel extends Model
|
|
{
|
|
protected $table = 'plans';
|
|
protected $primaryKey = 'id';
|
|
protected $useAutoIncrement = true;
|
|
protected $returnType = 'array';
|
|
protected $useSoftDeletes = false;
|
|
|
|
protected $allowedFields = [
|
|
'name',
|
|
'description',
|
|
'price',
|
|
'currency',
|
|
'billing_period',
|
|
'max_users',
|
|
'max_clients',
|
|
'max_storage',
|
|
'features',
|
|
'is_active',
|
|
'is_default',
|
|
];
|
|
|
|
protected $useTimestamps = true;
|
|
protected $createdField = 'created_at';
|
|
protected $updatedField = 'updated_at';
|
|
|
|
protected $validationRules = [
|
|
'name' => 'required|min_length[2]|max_length[100]',
|
|
'price' => 'required|numeric|greater_than_equal[0]',
|
|
'max_users' => 'required|integer|greater_than[0]',
|
|
'max_clients' => 'required|integer|greater_than[0]',
|
|
'max_storage' => 'required|integer|greater_than[0]',
|
|
];
|
|
|
|
protected $validationMessages = [
|
|
'name' => [
|
|
'required' => 'Название тарифа обязательно',
|
|
'min_length' => 'Название должно быть минимум 2 символа',
|
|
],
|
|
'price' => [
|
|
'required' => 'Цена обязательна',
|
|
'numeric' => 'Цена должна быть числом',
|
|
],
|
|
];
|
|
|
|
/**
|
|
* Получение активных тарифов
|
|
*/
|
|
public function getActivePlans()
|
|
{
|
|
return $this->where('is_active', 1)->findAll();
|
|
}
|
|
|
|
/**
|
|
* Получение тарифа по умолчанию
|
|
*/
|
|
public function getDefaultPlan()
|
|
{
|
|
return $this->where('is_default', 1)->where('is_active', 1)->first();
|
|
}
|
|
|
|
/**
|
|
* Проверка, является ли тариф системным
|
|
*/
|
|
public function isSystemPlan($planId)
|
|
{
|
|
$plan = $this->find($planId);
|
|
return $plan !== null;
|
|
}
|
|
}
|