FarmConfigService.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. namespace App\Module\Farm\Services;
  3. use App\Module\Farm\Logics\FarmConfigLogic;
  4. use Illuminate\Support\Facades\Log;
  5. /**
  6. * 农场配置服务类
  7. */
  8. class FarmConfigService
  9. {
  10. /**
  11. * 获取配置值
  12. *
  13. * @param string $configKey 配置键
  14. * @param mixed $defaultValue 默认值
  15. * @return mixed
  16. */
  17. public static function getConfigValue(string $configKey, $defaultValue = null)
  18. {
  19. try {
  20. $logic = new FarmConfigLogic();
  21. return $logic->getConfigValue($configKey, $defaultValue);
  22. } catch (\Exception $e) {
  23. Log::error('获取农场配置失败', [
  24. 'config_key' => $configKey,
  25. 'error' => $e->getMessage(),
  26. 'trace' => $e->getTraceAsString()
  27. ]);
  28. return $defaultValue;
  29. }
  30. }
  31. /**
  32. * 设置配置值
  33. *
  34. * @param string $configKey 配置键
  35. * @param mixed $value 配置值
  36. * @return bool
  37. */
  38. public static function setConfigValue(string $configKey, $value): bool
  39. {
  40. try {
  41. $logic = new FarmConfigLogic();
  42. return $logic->setConfigValue($configKey, $value);
  43. } catch (\Exception $e) {
  44. Log::error('设置农场配置失败', [
  45. 'config_key' => $configKey,
  46. 'value' => $value,
  47. 'error' => $e->getMessage(),
  48. 'trace' => $e->getTraceAsString()
  49. ]);
  50. return false;
  51. }
  52. }
  53. /**
  54. * 获取所有配置
  55. *
  56. * @return array
  57. */
  58. public static function getAllConfigs(): array
  59. {
  60. try {
  61. $logic = new FarmConfigLogic();
  62. return $logic->getAllConfigs();
  63. } catch (\Exception $e) {
  64. Log::error('获取所有农场配置失败', [
  65. 'error' => $e->getMessage(),
  66. 'trace' => $e->getTraceAsString()
  67. ]);
  68. return [];
  69. }
  70. }
  71. /**
  72. * 清除所有配置缓存
  73. *
  74. * @return void
  75. */
  76. public static function clearCache(): void
  77. {
  78. try {
  79. $logic = new FarmConfigLogic();
  80. $logic->clearCache();
  81. } catch (\Exception $e) {
  82. Log::error('清除农场配置缓存失败', [
  83. 'error' => $e->getMessage(),
  84. 'trace' => $e->getTraceAsString()
  85. ]);
  86. }
  87. }
  88. /**
  89. * 获取农场初始化奖励组ID
  90. *
  91. * @return int
  92. */
  93. public static function getInitRewardGroupId(): int
  94. {
  95. try {
  96. $logic = new FarmConfigLogic();
  97. return $logic->getInitRewardGroupId();
  98. } catch (\Exception $e) {
  99. Log::error('获取农场初始化奖励组ID失败', [
  100. 'error' => $e->getMessage(),
  101. 'trace' => $e->getTraceAsString()
  102. ]);
  103. return 0;
  104. }
  105. }
  106. /**
  107. * 设置农场初始化奖励组ID
  108. *
  109. * @param int $groupId 奖励组ID
  110. * @return bool
  111. */
  112. public static function setInitRewardGroupId(int $groupId): bool
  113. {
  114. try {
  115. $logic = new FarmConfigLogic();
  116. return $logic->setInitRewardGroupId($groupId);
  117. } catch (\Exception $e) {
  118. Log::error('设置农场初始化奖励组ID失败', [
  119. 'group_id' => $groupId,
  120. 'error' => $e->getMessage(),
  121. 'trace' => $e->getTraceAsString()
  122. ]);
  123. return false;
  124. }
  125. }
  126. }