GameConfigService.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <?php
  2. namespace App\Module\Game\Services;
  3. use App\Module\Game\Enums\GameConfigGroup;
  4. use App\Module\Game\Logics\GameConfigLogic;
  5. /**
  6. * 游戏配置服务层
  7. */
  8. class GameConfigService
  9. {
  10. /**
  11. * 获取用户日志系统配置
  12. */
  13. public static function getUserLogConfig(): array
  14. {
  15. return [
  16. 'enabled' => GameConfigLogic::getBool('user_log.enabled', true),
  17. 'auto_collect_enabled' => GameConfigLogic::getBool('user_log.auto_collect_enabled', true),
  18. 'max_records_per_run' => GameConfigLogic::getInt('user_log.max_records_per_run', 1000),
  19. 'collection_interval' => GameConfigLogic::getInt('user_log.collection_interval', 2),
  20. 'retention_days' => GameConfigLogic::getInt('user_log.retention_days', 30),
  21. 'auto_cleanup' => GameConfigLogic::getBool('user_log.auto_cleanup', true),
  22. ];
  23. }
  24. /**
  25. * 获取奖励系统配置
  26. */
  27. public static function getRewardConfig(): array
  28. {
  29. return [
  30. 'enabled' => GameConfigLogic::getBool('reward.enabled', true),
  31. 'max_reward_per_group' => GameConfigLogic::getInt('reward.max_reward_per_group', 100),
  32. 'log_retention_days' => GameConfigLogic::getInt('reward.log_retention_days', 90),
  33. ];
  34. }
  35. /**
  36. * 获取条件系统配置
  37. */
  38. public static function getConditionConfig(): array
  39. {
  40. return [
  41. 'enabled' => GameConfigLogic::getBool('condition.enabled', true),
  42. 'cache_ttl' => GameConfigLogic::getInt('condition.cache_ttl', 300),
  43. ];
  44. }
  45. /**
  46. * 获取消耗系统配置
  47. */
  48. public static function getConsumeConfig(): array
  49. {
  50. return [
  51. 'enabled' => GameConfigLogic::getBool('consume.enabled', true),
  52. 'strict_mode' => GameConfigLogic::getBool('consume.strict_mode', true),
  53. ];
  54. }
  55. /**
  56. * 获取系统配置
  57. */
  58. public static function getSystemConfig(): array
  59. {
  60. return [
  61. 'debug_mode' => GameConfigLogic::getBool('system.debug_mode', false),
  62. 'maintenance_mode' => GameConfigLogic::getBool('system.maintenance_mode', false),
  63. 'cache_enabled' => GameConfigLogic::getBool('system.cache_enabled', true),
  64. 'cache_ttl' => GameConfigLogic::getInt('system.cache_ttl', 3600),
  65. ];
  66. }
  67. /**
  68. * 检查用户日志系统是否启用
  69. */
  70. public static function isUserLogEnabled(): bool
  71. {
  72. return GameConfigLogic::getBool('user_log.enabled', true);
  73. }
  74. /**
  75. * 检查是否允许自动收集用户日志
  76. */
  77. public static function isAutoCollectEnabled(): bool
  78. {
  79. return GameConfigLogic::getBool('user_log.auto_collect_enabled', true);
  80. }
  81. /**
  82. * 检查奖励系统是否启用
  83. */
  84. public static function isRewardEnabled(): bool
  85. {
  86. return GameConfigLogic::getBool('reward.enabled', true);
  87. }
  88. /**
  89. * 检查条件系统是否启用
  90. */
  91. public static function isConditionEnabled(): bool
  92. {
  93. return GameConfigLogic::getBool('condition.enabled', true);
  94. }
  95. /**
  96. * 检查消耗系统是否启用
  97. */
  98. public static function isConsumeEnabled(): bool
  99. {
  100. return GameConfigLogic::getBool('consume.enabled', true);
  101. }
  102. /**
  103. * 检查是否为调试模式
  104. */
  105. public static function isDebugMode(): bool
  106. {
  107. return GameConfigLogic::getBool('system.debug_mode', false);
  108. }
  109. /**
  110. * 检查是否为维护模式
  111. */
  112. public static function isMaintenanceMode(): bool
  113. {
  114. return GameConfigLogic::getBool('system.maintenance_mode', false);
  115. }
  116. /**
  117. * 检查缓存是否启用
  118. */
  119. public static function isCacheEnabled(): bool
  120. {
  121. return GameConfigLogic::getBool('system.cache_enabled', true);
  122. }
  123. /**
  124. * 获取用户日志最大处理记录数
  125. */
  126. public static function getUserLogMaxRecords(): int
  127. {
  128. return GameConfigLogic::getInt('user_log.max_records_per_run', 1000);
  129. }
  130. /**
  131. * 获取用户日志收集间隔
  132. */
  133. public static function getUserLogInterval(): int
  134. {
  135. return GameConfigLogic::getInt('user_log.collection_interval', 2);
  136. }
  137. /**
  138. * 获取用户日志保留天数
  139. */
  140. public static function getUserLogRetentionDays(): int
  141. {
  142. return GameConfigLogic::getInt('user_log.retention_days', 30);
  143. }
  144. /**
  145. * 获取奖励日志保留天数
  146. */
  147. public static function getRewardLogRetentionDays(): int
  148. {
  149. return GameConfigLogic::getInt('reward.log_retention_days', 90);
  150. }
  151. /**
  152. * 检查指定收集器是否启用
  153. */
  154. public static function isCollectorEnabled(string $collectorName): bool
  155. {
  156. $key = "user_log.collector.{$collectorName}.enabled";
  157. return GameConfigLogic::getBool($key, true);
  158. }
  159. /**
  160. * 获取所有收集器的启用状态
  161. */
  162. public static function getCollectorStates(): array
  163. {
  164. return [
  165. 'fund' => self::isCollectorEnabled('fund'),
  166. 'item' => self::isCollectorEnabled('item'),
  167. 'farm_harvest' => self::isCollectorEnabled('farm_harvest'),
  168. 'farm_upgrade' => self::isCollectorEnabled('farm_upgrade'),
  169. 'point' => self::isCollectorEnabled('point'),
  170. ];
  171. }
  172. /**
  173. * 批量设置收集器启用状态
  174. */
  175. public static function setCollectorStates(array $states): bool
  176. {
  177. foreach ($states as $collectorName => $enabled) {
  178. $key = "user_log.collector.{$collectorName}.enabled";
  179. if (!GameConfigLogic::setBool($key, $enabled)) {
  180. return false;
  181. }
  182. }
  183. return true;
  184. }
  185. /**
  186. * 获取条件缓存时间
  187. */
  188. public static function getConditionCacheTtl(): int
  189. {
  190. return GameConfigLogic::getInt('condition.cache_ttl', 300);
  191. }
  192. /**
  193. * 获取系统缓存时间
  194. */
  195. public static function getSystemCacheTtl(): int
  196. {
  197. return GameConfigLogic::getInt('system.cache_ttl', 3600);
  198. }
  199. /**
  200. * 设置用户日志自动收集状态
  201. */
  202. public static function setAutoCollectEnabled(bool $enabled): bool
  203. {
  204. return GameConfigLogic::set('user_log.auto_collect_enabled', $enabled);
  205. }
  206. /**
  207. * 设置调试模式
  208. */
  209. public static function setDebugMode(bool $enabled): bool
  210. {
  211. return GameConfigLogic::set('system.debug_mode', $enabled);
  212. }
  213. /**
  214. * 设置维护模式
  215. */
  216. public static function setMaintenanceMode(bool $enabled): bool
  217. {
  218. return GameConfigLogic::set('system.maintenance_mode', $enabled);
  219. }
  220. /**
  221. * 获取分组配置
  222. */
  223. public static function getGroupConfig(GameConfigGroup $group): array
  224. {
  225. return GameConfigLogic::getGroupConfigs($group);
  226. }
  227. /**
  228. * 清除配置缓存
  229. */
  230. public static function clearCache(?string $key = null): void
  231. {
  232. GameConfigLogic::clearCache($key);
  233. }
  234. /**
  235. * 获取所有配置
  236. */
  237. public static function getAllConfigs(): array
  238. {
  239. return GameConfigLogic::getAllConfigs();
  240. }
  241. }