| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- <?php
- namespace App\Module\Farm\Services;
- use App\Module\Farm\Logics\FarmConfigLogic;
- use Illuminate\Support\Facades\Log;
- /**
- * 农场配置服务类
- */
- class FarmConfigService
- {
- /**
- * 获取配置值
- *
- * @param string $configKey 配置键
- * @param mixed $defaultValue 默认值
- * @return mixed
- */
- public static function getConfigValue(string $configKey, $defaultValue = null)
- {
- try {
- $logic = new FarmConfigLogic();
- return $logic->getConfigValue($configKey, $defaultValue);
- } catch (\Exception $e) {
- Log::error('获取农场配置失败', [
- 'config_key' => $configKey,
- 'error' => $e->getMessage(),
- 'trace' => $e->getTraceAsString()
- ]);
- return $defaultValue;
- }
- }
- /**
- * 设置配置值
- *
- * @param string $configKey 配置键
- * @param mixed $value 配置值
- * @return bool
- */
- public static function setConfigValue(string $configKey, $value): bool
- {
- try {
- $logic = new FarmConfigLogic();
- return $logic->setConfigValue($configKey, $value);
- } catch (\Exception $e) {
- Log::error('设置农场配置失败', [
- 'config_key' => $configKey,
- 'value' => $value,
- 'error' => $e->getMessage(),
- 'trace' => $e->getTraceAsString()
- ]);
- return false;
- }
- }
- /**
- * 获取所有配置
- *
- * @return array
- */
- public static function getAllConfigs(): array
- {
- try {
- $logic = new FarmConfigLogic();
- return $logic->getAllConfigs();
- } catch (\Exception $e) {
- Log::error('获取所有农场配置失败', [
- 'error' => $e->getMessage(),
- 'trace' => $e->getTraceAsString()
- ]);
- return [];
- }
- }
- /**
- * 清除所有配置缓存
- *
- * @return void
- */
- public static function clearCache(): void
- {
- try {
- $logic = new FarmConfigLogic();
- $logic->clearCache();
- } catch (\Exception $e) {
- Log::error('清除农场配置缓存失败', [
- 'error' => $e->getMessage(),
- 'trace' => $e->getTraceAsString()
- ]);
- }
- }
- /**
- * 获取农场初始化奖励组ID
- *
- * @return int
- */
- public static function getInitRewardGroupId(): int
- {
- try {
- $logic = new FarmConfigLogic();
- return $logic->getInitRewardGroupId();
- } catch (\Exception $e) {
- Log::error('获取农场初始化奖励组ID失败', [
- 'error' => $e->getMessage(),
- 'trace' => $e->getTraceAsString()
- ]);
- return 0;
- }
- }
- /**
- * 设置农场初始化奖励组ID
- *
- * @param int $groupId 奖励组ID
- * @return bool
- */
- public static function setInitRewardGroupId(int $groupId): bool
- {
- try {
- $logic = new FarmConfigLogic();
- return $logic->setInitRewardGroupId($groupId);
- } catch (\Exception $e) {
- Log::error('设置农场初始化奖励组ID失败', [
- 'group_id' => $groupId,
- 'error' => $e->getMessage(),
- 'trace' => $e->getTraceAsString()
- ]);
- return false;
- }
- }
- }
|