| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- <?php
- namespace App\Module\Game\Services;
- use App\Module\Game\Enums\GameConfigGroup;
- use App\Module\Game\Logics\GameConfigLogic;
- /**
- * 游戏配置服务层
- */
- class GameConfigService
- {
- /**
- * 获取用户日志系统配置
- */
- public static function getUserLogConfig(): array
- {
- return [
- 'enabled' => GameConfigLogic::getBool('user_log.enabled', true),
- 'auto_collect_enabled' => GameConfigLogic::getBool('user_log.auto_collect_enabled', true),
- 'max_records_per_run' => GameConfigLogic::getInt('user_log.max_records_per_run', 1000),
- 'collection_interval' => GameConfigLogic::getInt('user_log.collection_interval', 2),
- 'retention_days' => GameConfigLogic::getInt('user_log.retention_days', 30),
- 'auto_cleanup' => GameConfigLogic::getBool('user_log.auto_cleanup', true),
- ];
- }
- /**
- * 获取奖励系统配置
- */
- public static function getRewardConfig(): array
- {
- return [
- 'enabled' => GameConfigLogic::getBool('reward.enabled', true),
- 'max_reward_per_group' => GameConfigLogic::getInt('reward.max_reward_per_group', 100),
- 'log_retention_days' => GameConfigLogic::getInt('reward.log_retention_days', 90),
- ];
- }
- /**
- * 获取条件系统配置
- */
- public static function getConditionConfig(): array
- {
- return [
- 'enabled' => GameConfigLogic::getBool('condition.enabled', true),
- 'cache_ttl' => GameConfigLogic::getInt('condition.cache_ttl', 300),
- ];
- }
- /**
- * 获取消耗系统配置
- */
- public static function getConsumeConfig(): array
- {
- return [
- 'enabled' => GameConfigLogic::getBool('consume.enabled', true),
- 'strict_mode' => GameConfigLogic::getBool('consume.strict_mode', true),
- ];
- }
- /**
- * 获取系统配置
- */
- public static function getSystemConfig(): array
- {
- return [
- 'debug_mode' => GameConfigLogic::getBool('system.debug_mode', false),
- 'maintenance_mode' => GameConfigLogic::getBool('system.maintenance_mode', false),
- 'cache_enabled' => GameConfigLogic::getBool('system.cache_enabled', true),
- 'cache_ttl' => GameConfigLogic::getInt('system.cache_ttl', 3600),
- ];
- }
- /**
- * 检查用户日志系统是否启用
- */
- public static function isUserLogEnabled(): bool
- {
- return GameConfigLogic::getBool('user_log.enabled', true);
- }
- /**
- * 检查是否允许自动收集用户日志
- */
- public static function isAutoCollectEnabled(): bool
- {
- return GameConfigLogic::getBool('user_log.auto_collect_enabled', true);
- }
- /**
- * 检查奖励系统是否启用
- */
- public static function isRewardEnabled(): bool
- {
- return GameConfigLogic::getBool('reward.enabled', true);
- }
- /**
- * 检查条件系统是否启用
- */
- public static function isConditionEnabled(): bool
- {
- return GameConfigLogic::getBool('condition.enabled', true);
- }
- /**
- * 检查消耗系统是否启用
- */
- public static function isConsumeEnabled(): bool
- {
- return GameConfigLogic::getBool('consume.enabled', true);
- }
- /**
- * 检查是否为调试模式
- */
- public static function isDebugMode(): bool
- {
- return GameConfigLogic::getBool('system.debug_mode', false);
- }
- /**
- * 检查是否为维护模式
- */
- public static function isMaintenanceMode(): bool
- {
- return GameConfigLogic::getBool('system.maintenance_mode', false);
- }
- /**
- * 检查缓存是否启用
- */
- public static function isCacheEnabled(): bool
- {
- return GameConfigLogic::getBool('system.cache_enabled', true);
- }
- /**
- * 获取用户日志最大处理记录数
- */
- public static function getUserLogMaxRecords(): int
- {
- return GameConfigLogic::getInt('user_log.max_records_per_run', 1000);
- }
- /**
- * 获取用户日志收集间隔
- */
- public static function getUserLogInterval(): int
- {
- return GameConfigLogic::getInt('user_log.collection_interval', 2);
- }
- /**
- * 获取用户日志保留天数
- */
- public static function getUserLogRetentionDays(): int
- {
- return GameConfigLogic::getInt('user_log.retention_days', 30);
- }
- /**
- * 获取奖励日志保留天数
- */
- public static function getRewardLogRetentionDays(): int
- {
- return GameConfigLogic::getInt('reward.log_retention_days', 90);
- }
- /**
- * 检查指定收集器是否启用
- */
- public static function isCollectorEnabled(string $collectorName): bool
- {
- $key = "user_log.collector.{$collectorName}.enabled";
- return GameConfigLogic::getBool($key, true);
- }
- /**
- * 获取所有收集器的启用状态
- */
- public static function getCollectorStates(): array
- {
- return [
- 'fund' => self::isCollectorEnabled('fund'),
- 'item' => self::isCollectorEnabled('item'),
- 'farm_harvest' => self::isCollectorEnabled('farm_harvest'),
- 'farm_upgrade' => self::isCollectorEnabled('farm_upgrade'),
- 'point' => self::isCollectorEnabled('point'),
- ];
- }
- /**
- * 批量设置收集器启用状态
- */
- public static function setCollectorStates(array $states): bool
- {
- foreach ($states as $collectorName => $enabled) {
- $key = "user_log.collector.{$collectorName}.enabled";
- if (!GameConfigLogic::setBool($key, $enabled)) {
- return false;
- }
- }
- return true;
- }
- /**
- * 获取条件缓存时间
- */
- public static function getConditionCacheTtl(): int
- {
- return GameConfigLogic::getInt('condition.cache_ttl', 300);
- }
- /**
- * 获取系统缓存时间
- */
- public static function getSystemCacheTtl(): int
- {
- return GameConfigLogic::getInt('system.cache_ttl', 3600);
- }
- /**
- * 设置用户日志自动收集状态
- */
- public static function setAutoCollectEnabled(bool $enabled): bool
- {
- return GameConfigLogic::set('user_log.auto_collect_enabled', $enabled);
- }
- /**
- * 设置调试模式
- */
- public static function setDebugMode(bool $enabled): bool
- {
- return GameConfigLogic::set('system.debug_mode', $enabled);
- }
- /**
- * 设置维护模式
- */
- public static function setMaintenanceMode(bool $enabled): bool
- {
- return GameConfigLogic::set('system.maintenance_mode', $enabled);
- }
- /**
- * 获取分组配置
- */
- public static function getGroupConfig(GameConfigGroup $group): array
- {
- return GameConfigLogic::getGroupConfigs($group);
- }
- /**
- * 清除配置缓存
- */
- public static function clearCache(?string $key = null): void
- {
- GameConfigLogic::clearCache($key);
- }
- /**
- * 获取所有配置
- */
- public static function getAllConfigs(): array
- {
- return GameConfigLogic::getAllConfigs();
- }
- }
|