| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <?php
- namespace App\Module\Farm\Services;
- use App\Module\Farm\Logics\BuffLogic;
- use App\Module\Farm\Models\FarmGodBuff;
- use Illuminate\Support\Collection;
- use Illuminate\Support\Facades\Log;
- /**
- * 神灵加持服务
- */
- class BuffService
- {
- /**
- * 获取用户的所有神灵加持
- *
- * @param int $userId
- * @return Collection
- */
- public static function getUserBuffs(int $userId): Collection
- {
- try {
- $buffLogic = new BuffLogic();
- return $buffLogic->getUserBuffs($userId);
- } catch (\Exception $e) {
- Log::error('获取用户神灵加持失败', [
- 'user_id' => $userId,
- 'error' => $e->getMessage(),
- 'trace' => $e->getTraceAsString()
- ]);
-
- return collect();
- }
- }
-
- /**
- * 获取用户的有效神灵加持
- *
- * @param int $userId
- * @return Collection
- */
- public static function getActiveBuffs(int $userId): Collection
- {
- try {
- $buffLogic = new BuffLogic();
- return $buffLogic->getActiveBuffs($userId);
- } catch (\Exception $e) {
- Log::error('获取用户有效神灵加持失败', [
- 'user_id' => $userId,
- 'error' => $e->getMessage(),
- 'trace' => $e->getTraceAsString()
- ]);
-
- return collect();
- }
- }
-
- /**
- * 获取用户指定类型的神灵加持
- *
- * @param int $userId
- * @param int $buffType
- * @return FarmGodBuff|null
- */
- public static function getUserBuff(int $userId, int $buffType): ?FarmGodBuff
- {
- try {
- $buffLogic = new BuffLogic();
- return $buffLogic->getUserBuff($userId, $buffType);
- } catch (\Exception $e) {
- Log::error('获取用户指定类型神灵加持失败', [
- 'user_id' => $userId,
- 'buff_type' => $buffType,
- 'error' => $e->getMessage(),
- 'trace' => $e->getTraceAsString()
- ]);
-
- return null;
- }
- }
-
- /**
- * 获取用户指定类型的有效神灵加持
- *
- * @param int $userId
- * @param int $buffType
- * @return FarmGodBuff|null
- */
- public static function getActiveUserBuff(int $userId, int $buffType): ?FarmGodBuff
- {
- try {
- $buffLogic = new BuffLogic();
- return $buffLogic->getActiveUserBuff($userId, $buffType);
- } catch (\Exception $e) {
- Log::error('获取用户指定类型有效神灵加持失败', [
- 'user_id' => $userId,
- 'buff_type' => $buffType,
- 'error' => $e->getMessage(),
- 'trace' => $e->getTraceAsString()
- ]);
-
- return null;
- }
- }
-
- /**
- * 激活神灵加持
- *
- * @param int $userId
- * @param int $buffType
- * @param int $durationHours
- * @return FarmGodBuff|null
- */
- public static function activateBuff(int $userId, int $buffType, int $durationHours): ?FarmGodBuff
- {
- try {
- $buffLogic = new BuffLogic();
- return $buffLogic->activateBuff($userId, $buffType, $durationHours);
- } catch (\Exception $e) {
- Log::error('激活神灵加持失败', [
- 'user_id' => $userId,
- 'buff_type' => $buffType,
- 'duration_hours' => $durationHours,
- 'error' => $e->getMessage(),
- 'trace' => $e->getTraceAsString()
- ]);
-
- return null;
- }
- }
- }
|