Many fixes
This commit is contained in:
@@ -66,7 +66,7 @@ class EventManager
|
||||
private function getModulesConfig(): \Config\BusinessModules
|
||||
{
|
||||
if ($this->modulesConfig === null) {
|
||||
$this->modulesConfig = new \Config\BusinessModules();
|
||||
$this->modulesConfig = config('BusinessModules');
|
||||
}
|
||||
|
||||
return $this->modulesConfig;
|
||||
@@ -144,7 +144,9 @@ class EventManager
|
||||
}
|
||||
|
||||
// Если модуль отключен глобально, не подписываемся
|
||||
if (empty($modulesConfig->modules[$this->moduleCode]['enabled'])) {
|
||||
// Проверяем наличие поля enabled (опционально)
|
||||
if (isset($modulesConfig->modules[$this->moduleCode]['enabled']) &&
|
||||
empty($modulesConfig->modules[$this->moduleCode]['enabled'])) {
|
||||
log_message(
|
||||
'info',
|
||||
"EventManager: Module '{$this->moduleCode}' is disabled globally"
|
||||
|
||||
@@ -2,393 +2,377 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Config\BusinessModules;
|
||||
use App\Models\OrganizationSubscriptionModel;
|
||||
use CodeIgniter\Config\BaseConfig;
|
||||
|
||||
/**
|
||||
* Сервис для работы с подписками на модули
|
||||
* Сервис для работы с подписками организаций на модули
|
||||
*
|
||||
* Предоставляет API для проверки статуса подписок,
|
||||
* активации модулей и управления триальными периодами.
|
||||
* Предоставляет API для проверки доступности модулей,
|
||||
* управления подписками и получения информации о модулях.
|
||||
*/
|
||||
class ModuleSubscriptionService
|
||||
{
|
||||
protected OrganizationSubscriptionModel $subscriptionModel;
|
||||
protected BusinessModules $modulesConfig;
|
||||
protected ?int $activeOrgId = null;
|
||||
/**
|
||||
* Конфигурация модулей (базовые значения)
|
||||
*/
|
||||
protected array $modulesConfig = [
|
||||
'base' => [
|
||||
'name' => 'Базовый модуль',
|
||||
'description' => 'Основные функции',
|
||||
'price_monthly' => 0,
|
||||
'price_yearly' => 0,
|
||||
'trial_days' => 0,
|
||||
],
|
||||
'crm' => [
|
||||
'name' => 'CRM',
|
||||
'description' => 'Управление клиентами и сделками',
|
||||
'price_monthly' => 990,
|
||||
'price_yearly' => 9900,
|
||||
'trial_days' => 14,
|
||||
],
|
||||
'booking' => [
|
||||
'name' => 'Бронирования',
|
||||
'description' => 'Управление бронированиями',
|
||||
'price_monthly' => 1490,
|
||||
'price_yearly' => 14900,
|
||||
'trial_days' => 14,
|
||||
],
|
||||
'tasks' => [
|
||||
'name' => 'Задачи',
|
||||
'description' => 'Управление задачами',
|
||||
'price_monthly' => 790,
|
||||
'price_yearly' => 7900,
|
||||
'trial_days' => 14,
|
||||
],
|
||||
'proof' => [
|
||||
'name' => 'Proof',
|
||||
'description' => 'Согласование документов',
|
||||
'price_monthly' => 590,
|
||||
'price_yearly' => 5900,
|
||||
'trial_days' => 14,
|
||||
],
|
||||
];
|
||||
|
||||
public function __construct(
|
||||
?OrganizationSubscriptionModel $subscriptionModel = null,
|
||||
?BusinessModules $modulesConfig = null
|
||||
) {
|
||||
$this->subscriptionModel = $subscriptionModel ?? new OrganizationSubscriptionModel();
|
||||
$this->modulesConfig = $modulesConfig ?? config('BusinessModules');
|
||||
protected $db;
|
||||
protected string $moduleSettingsTable = 'module_settings';
|
||||
protected string $subscriptionsTable = 'organization_subscriptions';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->db = \Config\Database::connect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Получение активного ID организации из сессии
|
||||
* Получение базовой конфигурации модуля
|
||||
*/
|
||||
protected function getActiveOrgId(): ?int
|
||||
public function getModuleConfig(string $moduleCode): ?array
|
||||
{
|
||||
if ($this->activeOrgId === null) {
|
||||
$this->activeOrgId = session()->get('active_org_id') ?? 0;
|
||||
return $this->modulesConfig[$moduleCode] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Получение всех модулей (с учётом переопределений из БД)
|
||||
*/
|
||||
public function getAllModules(): array
|
||||
{
|
||||
$modules = $this->modulesConfig;
|
||||
|
||||
$builder = $this->db->table($this->moduleSettingsTable);
|
||||
$settings = $builder->get()->getResultArray();
|
||||
|
||||
foreach ($settings as $setting) {
|
||||
$code = $setting['module_code'];
|
||||
if (isset($modules[$code])) {
|
||||
if (!empty($setting['name'])) {
|
||||
$modules[$code]['name'] = $setting['name'];
|
||||
}
|
||||
if (isset($setting['description']) && $setting['description'] !== '') {
|
||||
$modules[$code]['description'] = $setting['description'];
|
||||
}
|
||||
if (isset($setting['price_monthly'])) {
|
||||
$modules[$code]['price_monthly'] = (int) $setting['price_monthly'];
|
||||
}
|
||||
if (isset($setting['price_yearly'])) {
|
||||
$modules[$code]['price_yearly'] = (int) $setting['price_yearly'];
|
||||
}
|
||||
if (isset($setting['trial_days'])) {
|
||||
$modules[$code]['trial_days'] = (int) $setting['trial_days'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->activeOrgId ?: null;
|
||||
return $modules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверка активности модуля для текущей организации
|
||||
*
|
||||
* @param string $moduleCode Код модуля (crm, booking, tasks, proof)
|
||||
* @param int|null $organizationId ID организации (null = из сессии)
|
||||
* @return bool
|
||||
* Проверка активности модуля для организации
|
||||
*/
|
||||
public function isModuleActive(string $moduleCode, ?int $organizationId = null): bool
|
||||
{
|
||||
$orgId = $organizationId ?? $this->getActiveOrgId();
|
||||
|
||||
if (!$orgId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Базовый модуль всегда активен
|
||||
if ($moduleCode === 'base') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->subscriptionModel->isModuleActive($orgId, $moduleCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверка что модуль доступен (активен или в триале)
|
||||
*
|
||||
* @param string $moduleCode
|
||||
* @param int|null $organizationId
|
||||
* @return bool
|
||||
*/
|
||||
public function isModuleAvailable(string $moduleCode, ?int $organizationId = null): bool
|
||||
{
|
||||
$orgId = $organizationId ?? $this->getActiveOrgId();
|
||||
|
||||
$orgId = $organizationId ?? session()->get('active_org_id');
|
||||
if (!$orgId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Базовый модуль всегда доступен
|
||||
if ($moduleCode === 'base') {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Проверяем подписку
|
||||
$subscription = $this->subscriptionModel->getSubscription($orgId, $moduleCode);
|
||||
|
||||
$subscription = $this->getSubscription($orgId, $moduleCode);
|
||||
if (!$subscription) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Активен или в триале
|
||||
return in_array($subscription['status'], ['trial', 'active'], true);
|
||||
return $subscription['status'] === 'active';
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверка что модуль в триальном периоде
|
||||
*
|
||||
* @param string $moduleCode
|
||||
* @param int|null $organizationId
|
||||
* @return bool
|
||||
* Проверка доступности модуля (активен или в триале)
|
||||
*/
|
||||
public function isInTrial(string $moduleCode, ?int $organizationId = null): bool
|
||||
public function isModuleAvailable(string $moduleCode, ?int $organizationId = null): bool
|
||||
{
|
||||
// Базовый модуль не имеет триала
|
||||
if ($moduleCode === 'base') {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
$orgId = $organizationId ?? $this->getActiveOrgId();
|
||||
|
||||
$orgId = $organizationId ?? session()->get('active_org_id');
|
||||
if (!$orgId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->subscriptionModel->isInTrial($orgId, $moduleCode);
|
||||
$subscription = $this->getSubscription($orgId, $moduleCode);
|
||||
if (!$subscription) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return in_array($subscription['status'], ['active', 'trial'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверка что триал истекает скоро (для показа уведомлений)
|
||||
*
|
||||
* @param string $moduleCode
|
||||
* @param int $daysThreshold Порог в днях
|
||||
* @param int|null $organizationId
|
||||
* @return bool
|
||||
* Получение подписки организации на модуль
|
||||
*/
|
||||
public function isTrialExpiringSoon(
|
||||
public function getSubscription(int $organizationId, string $moduleCode): ?array
|
||||
{
|
||||
$builder = $this->db->table($this->subscriptionsTable);
|
||||
return $builder->where('organization_id', $organizationId)
|
||||
->where('module_code', $moduleCode)
|
||||
->get()
|
||||
->getRowArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Получение всех подписок организации
|
||||
*/
|
||||
public function getOrganizationSubscriptions(int $organizationId): array
|
||||
{
|
||||
$builder = $this->db->table($this->subscriptionsTable);
|
||||
return $builder->where('organization_id', $organizationId)
|
||||
->orderBy('created_at', 'DESC')
|
||||
->get()
|
||||
->getResultArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Получение всех активных модулей организации
|
||||
*/
|
||||
public function getActiveModules(int $organizationId): array
|
||||
{
|
||||
$builder = $this->db->table($this->subscriptionsTable);
|
||||
$subscriptions = $builder->where('organization_id', $organizationId)
|
||||
->whereIn('status', ['active', 'trial'])
|
||||
->get()
|
||||
->getResultArray();
|
||||
|
||||
$modules = array_column($subscriptions, 'module_code');
|
||||
$modules[] = 'base';
|
||||
|
||||
return array_unique($modules);
|
||||
}
|
||||
|
||||
/**
|
||||
* Создание/обновление подписки
|
||||
*/
|
||||
public function upsertSubscription(
|
||||
int $organizationId,
|
||||
string $moduleCode,
|
||||
int $daysThreshold = 3,
|
||||
?int $organizationId = null
|
||||
string $status = 'active',
|
||||
?int $days = null
|
||||
): bool {
|
||||
if (!$this->isInTrial($moduleCode, $organizationId)) {
|
||||
return false;
|
||||
$existing = $this->getSubscription($organizationId, $moduleCode);
|
||||
|
||||
$data = [
|
||||
'organization_id' => $organizationId,
|
||||
'module_code' => $moduleCode,
|
||||
'status' => $status,
|
||||
'expires_at' => $days > 0 ? date('Y-m-d H:i:s', strtotime("+{$days} days")) : null,
|
||||
'updated_at' => date('Y-m-d H:i:s'),
|
||||
];
|
||||
|
||||
if ($existing) {
|
||||
return $this->db->table($this->subscriptionsTable)
|
||||
->where('id', $existing['id'])
|
||||
->update($data);
|
||||
}
|
||||
|
||||
$orgId = $organizationId ?? $this->getActiveOrgId();
|
||||
$daysLeft = $this->subscriptionModel->getDaysUntilExpire($orgId, $moduleCode);
|
||||
|
||||
return $daysLeft !== null && $daysLeft <= $daysThreshold && $daysLeft > 0;
|
||||
$data['created_at'] = date('Y-m-d H:i:s');
|
||||
return $this->db->table($this->subscriptionsTable)->insert($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Получение дней до окончания подписки/триала
|
||||
*
|
||||
* @param string $moduleCode
|
||||
* @param int|null $organizationId
|
||||
* @return int|null Количество дней или null если не активна
|
||||
* Удаление подписки
|
||||
*/
|
||||
public function getDaysUntilExpire(string $moduleCode, ?int $organizationId = null): ?int
|
||||
public function deleteSubscription(int $subscriptionId): bool
|
||||
{
|
||||
$orgId = $organizationId ?? $this->getActiveOrgId();
|
||||
|
||||
if (!$orgId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->subscriptionModel->getDaysUntilExpire($orgId, $moduleCode);
|
||||
return $this->db->table($this->subscriptionsTable)
|
||||
->where('id', $subscriptionId)
|
||||
->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Получение информации о модуле из конфигурации
|
||||
*
|
||||
* @param string $moduleCode
|
||||
* @return array|null
|
||||
* Запуск триала для модуля
|
||||
*/
|
||||
public function getModuleInfo(string $moduleCode): ?array
|
||||
public function startTrial(int $organizationId, string $moduleCode, int $trialDays = 14): bool
|
||||
{
|
||||
return $this->modulesConfig->getModule($moduleCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Получение всех доступных модулей для организации
|
||||
*
|
||||
* @param int|null $organizationId
|
||||
* @return array Список кодов модулей
|
||||
*/
|
||||
public function getActiveModules(?int $organizationId = null): array
|
||||
{
|
||||
$orgId = $organizationId ?? $this->getActiveOrgId();
|
||||
|
||||
if (!$orgId) {
|
||||
return ['base'];
|
||||
}
|
||||
|
||||
$activeModules = $this->subscriptionModel->getActiveModules($orgId);
|
||||
|
||||
// Всегда добавляем базовый модуль
|
||||
$activeModules[] = 'base';
|
||||
|
||||
return array_unique($activeModules);
|
||||
}
|
||||
|
||||
/**
|
||||
* Запуск триального периода для модуля
|
||||
*
|
||||
* @param string $moduleCode
|
||||
* @param int|null $organizationId
|
||||
* @param int $trialDays
|
||||
* @return bool
|
||||
*/
|
||||
public function startTrial(
|
||||
string $moduleCode,
|
||||
?int $organizationId = null,
|
||||
int $trialDays = 14
|
||||
): bool {
|
||||
$orgId = $organizationId ?? $this->getActiveOrgId();
|
||||
|
||||
if (!$orgId) {
|
||||
$config = $this->getModuleConfig($moduleCode);
|
||||
if (!$config || $config['trial_days'] <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Проверяем что модуль существует
|
||||
if (!$this->modulesConfig->exists($moduleCode)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Проверяем что модуль платный
|
||||
$moduleInfo = $this->modulesConfig->getModule($moduleCode);
|
||||
if (!$moduleInfo || $moduleInfo['trial_days'] <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Проверяем что триал ещё не был использован
|
||||
if ($this->subscriptionModel->isInTrial($orgId, $moduleCode)) {
|
||||
return false; // Уже в триале
|
||||
}
|
||||
|
||||
// Проверяем что нет активной подписки
|
||||
if ($this->isModuleActive($moduleCode, $orgId)) {
|
||||
return false; // Уже активна
|
||||
}
|
||||
|
||||
return (bool) $this->subscriptionModel->startTrial(
|
||||
$orgId,
|
||||
return $this->upsertSubscription(
|
||||
$organizationId,
|
||||
$moduleCode,
|
||||
$moduleInfo['trial_days']
|
||||
'trial',
|
||||
$trialDays
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Активация платной подписки (для ручного включения или после платежа)
|
||||
*
|
||||
* @param string $moduleCode
|
||||
* @param int $months
|
||||
* @param int|null $organizationId
|
||||
* @return bool
|
||||
* Активация подписки
|
||||
*/
|
||||
public function activate(
|
||||
string $moduleCode,
|
||||
int $months = 1,
|
||||
?int $organizationId = null
|
||||
): bool {
|
||||
$orgId = $organizationId ?? $this->getActiveOrgId();
|
||||
|
||||
if (!$orgId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Проверяем что модуль существует
|
||||
if (!$this->modulesConfig->exists($moduleCode)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->subscriptionModel->activate($orgId, $moduleCode, $months);
|
||||
public function activate(int $organizationId, string $moduleCode, int $months = 1): bool
|
||||
{
|
||||
return $this->upsertSubscription(
|
||||
$organizationId,
|
||||
$moduleCode,
|
||||
'active',
|
||||
$months * 30
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Отмена подписки
|
||||
*
|
||||
* @param string $moduleCode
|
||||
* @param int|null $organizationId
|
||||
* @return bool
|
||||
*/
|
||||
public function cancel(string $moduleCode, ?int $organizationId = null): bool
|
||||
public function cancel(int $organizationId, string $moduleCode): bool
|
||||
{
|
||||
$orgId = $organizationId ?? $this->getActiveOrgId();
|
||||
|
||||
if (!$orgId) {
|
||||
$existing = $this->getSubscription($organizationId, $moduleCode);
|
||||
if (!$existing) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->subscriptionModel->cancel($orgId, $moduleCode);
|
||||
return $this->db->table($this->subscriptionsTable)
|
||||
->where('id', $existing['id'])
|
||||
->update(['status' => 'cancelled', 'updated_at' => date('Y-m-d H:i:s')]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверка доступа к функции модуля
|
||||
*
|
||||
* @param string $moduleCode
|
||||
* @param string $feature Опционально - конкретная фича
|
||||
* @return bool
|
||||
* Получение всех подписок (для суперадмина)
|
||||
*/
|
||||
public function canUseModule(string $moduleCode, string $feature = ''): bool
|
||||
public function getAllSubscriptions(): array
|
||||
{
|
||||
if (!$this->isModuleActive($moduleCode)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Для триальных версий могут быть ограничения на некоторые фичи
|
||||
if ($this->isInTrial($moduleCode)) {
|
||||
// Проверяем доступность фичи в триале
|
||||
// (можно расширить через конфигурацию)
|
||||
}
|
||||
|
||||
return true;
|
||||
$builder = $this->db->table($this->subscriptionsTable);
|
||||
return $builder
|
||||
->select('organization_subscriptions.*, organizations.name as organization_name')
|
||||
->join('organizations', 'organizations.id = organization_subscriptions.organization_id')
|
||||
->orderBy('organization_subscriptions.created_at', 'DESC')
|
||||
->get()
|
||||
->getResultArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Получение статуса подписки для отображения в UI
|
||||
*
|
||||
* @param string $moduleCode
|
||||
* @param int|null $organizationId
|
||||
* @return array
|
||||
* Статистика по модулям (для суперадмина)
|
||||
*/
|
||||
public function getSubscriptionStatus(
|
||||
public function getModuleStats(): array
|
||||
{
|
||||
$stats = [];
|
||||
$modules = $this->getAllModules();
|
||||
|
||||
foreach ($modules as $code => $module) {
|
||||
$activeCount = $this->db->table($this->subscriptionsTable)
|
||||
->where('module_code', $code)
|
||||
->where('status', 'active')
|
||||
->countAllResults();
|
||||
|
||||
$trialCount = $this->db->table($this->subscriptionsTable)
|
||||
->where('module_code', $code)
|
||||
->where('status', 'trial')
|
||||
->countAllResults();
|
||||
|
||||
$stats[$code] = [
|
||||
'name' => $module['name'],
|
||||
'active' => $activeCount,
|
||||
'trial' => $trialCount,
|
||||
];
|
||||
}
|
||||
|
||||
return $stats;
|
||||
}
|
||||
|
||||
/**
|
||||
* Сохранение настроек модуля
|
||||
*/
|
||||
public function saveModuleSettings(
|
||||
string $moduleCode,
|
||||
?int $organizationId = null
|
||||
): array {
|
||||
$orgId = $organizationId ?? $this->getActiveOrgId();
|
||||
?string $name = null,
|
||||
?string $description = null,
|
||||
?int $priceMonthly = null,
|
||||
?int $priceYearly = null,
|
||||
?int $trialDays = null
|
||||
): bool {
|
||||
$existing = $this->db->table($this->moduleSettingsTable)
|
||||
->where('module_code', $moduleCode)
|
||||
->get()
|
||||
->getRowArray();
|
||||
|
||||
$moduleInfo = $this->modulesConfig->getModule($moduleCode);
|
||||
$subscription = $orgId
|
||||
? $this->subscriptionModel->getSubscription($orgId, $moduleCode)
|
||||
: null;
|
||||
|
||||
$status = 'unavailable';
|
||||
$daysLeft = null;
|
||||
$message = '';
|
||||
|
||||
if ($moduleCode === 'base') {
|
||||
$status = 'active';
|
||||
$message = 'Базовый модуль';
|
||||
} elseif (!$subscription) {
|
||||
if ($moduleInfo && $moduleInfo['trial_days'] > 0) {
|
||||
$status = 'trial_available';
|
||||
$message = 'Доступен триал ' . $moduleInfo['trial_days'] . ' дней';
|
||||
} else {
|
||||
$status = 'locked';
|
||||
$message = 'Приобретите модуль';
|
||||
}
|
||||
} elseif ($subscription['status'] === 'trial') {
|
||||
$daysLeft = $this->subscriptionModel->getDaysUntilExpire($orgId, $moduleCode);
|
||||
if ($daysLeft && $daysLeft > 0) {
|
||||
$status = 'trial';
|
||||
$message = "Триал: {$daysLeft} дн.";
|
||||
} else {
|
||||
$status = 'expired';
|
||||
$message = 'Триал истёк';
|
||||
}
|
||||
} elseif ($subscription['status'] === 'active') {
|
||||
$daysLeft = $this->subscriptionModel->getDaysUntilExpire($orgId, $moduleCode);
|
||||
$status = 'active';
|
||||
$message = $daysLeft ? "Осталось {$daysLeft} дн." : 'Активна';
|
||||
} elseif (in_array($subscription['status'], ['expired', 'cancelled'])) {
|
||||
$status = 'expired';
|
||||
$message = 'Подписка завершена';
|
||||
}
|
||||
|
||||
return [
|
||||
'status' => $status,
|
||||
'message' => $message,
|
||||
'days_left' => $daysLeft,
|
||||
'module' => $moduleInfo,
|
||||
'subscription' => $subscription,
|
||||
$data = [
|
||||
'module_code' => $moduleCode,
|
||||
'updated_at' => date('Y-m-d H:i:s'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Получение цены модуля
|
||||
*
|
||||
* @param string $moduleCode
|
||||
* @param string $period
|
||||
* @return int
|
||||
*/
|
||||
public function getPrice(string $moduleCode, string $period = 'monthly'): int
|
||||
{
|
||||
return $this->modulesConfig->getPrice($moduleCode, $period);
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверка что пользователь может управлять подписками организации
|
||||
*
|
||||
* @param int|null $organizationId
|
||||
* @return bool
|
||||
*/
|
||||
public function canManageSubscriptions(?int $organizationId = null): bool
|
||||
{
|
||||
$orgId = $organizationId ?? $this->getActiveOrgId();
|
||||
|
||||
if (!$orgId) {
|
||||
return false;
|
||||
if ($name !== null) {
|
||||
$data['name'] = $name;
|
||||
}
|
||||
if ($description !== null) {
|
||||
$data['description'] = $description;
|
||||
}
|
||||
if ($priceMonthly !== null) {
|
||||
$data['price_monthly'] = $priceMonthly;
|
||||
}
|
||||
if ($priceYearly !== null) {
|
||||
$data['price_yearly'] = $priceYearly;
|
||||
}
|
||||
if ($trialDays !== null) {
|
||||
$data['trial_days'] = $trialDays;
|
||||
}
|
||||
|
||||
// Проверяем права через AccessService
|
||||
return service('access')->canManageModules();
|
||||
if ($existing) {
|
||||
return $this->db->table($this->moduleSettingsTable)
|
||||
->where('id', $existing['id'])
|
||||
->update($data);
|
||||
}
|
||||
|
||||
$data['created_at'] = date('Y-m-d H:i:s');
|
||||
$data['is_active'] = 1;
|
||||
return $this->db->table($this->moduleSettingsTable)->insert($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Получение настроек модуля
|
||||
*/
|
||||
public function getModuleSettings(string $moduleCode): ?array
|
||||
{
|
||||
return $this->db->table($this->moduleSettingsTable)
|
||||
->where('module_code', $moduleCode)
|
||||
->get()
|
||||
->getRowArray();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user