GodTempService.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace App\Module\Game\Services;
  3. use App\Module\Game\Dtos\GodChangeTempDto;
  4. use App\Module\Game\Logics\GodTemp;
  5. use Illuminate\Support\Facades\Log;
  6. /**
  7. * 神像临时数据服务类
  8. *
  9. * 提供神像临时数据相关的服务方法,用于外部调用
  10. */
  11. class GodTempService
  12. {
  13. /**
  14. * 获取用户的神像变更临时数据
  15. *
  16. * @param int $userId 用户ID
  17. * @return GodChangeTempDto[] 用户的神像变更数据
  18. */
  19. public static function getUserGodChanges(int $userId): array
  20. {
  21. try {
  22. return GodTemp::getUserGodChanges($userId);
  23. } catch (\Exception $e) {
  24. Log::error('获取用户神像变更临时数据失败', [
  25. 'error' => $e->getMessage(),
  26. 'user_id' => $userId,
  27. ]);
  28. return [];
  29. }
  30. }
  31. /**
  32. * 获取用户特定神像类型的变更临时数据
  33. *
  34. * @param int $userId 用户ID
  35. * @param int $godType 神像类型
  36. * @return GodChangeTempDto|null 神像变更数据,不存在时返回null
  37. */
  38. public static function getUserGodChange(int $userId, int $godType): ?GodChangeTempDto
  39. {
  40. try {
  41. return GodTemp::getUserGodChange($userId, $godType);
  42. } catch (\Exception $e) {
  43. Log::error('获取用户特定神像变更临时数据失败', [
  44. 'error' => $e->getMessage(),
  45. 'user_id' => $userId,
  46. 'god_type' => $godType,
  47. ]);
  48. return null;
  49. }
  50. }
  51. /**
  52. * 清除用户的神像变更临时数据
  53. *
  54. * @param int $userId 用户ID
  55. * @return void
  56. */
  57. public static function clearUserGodChanges(int $userId): void
  58. {
  59. try {
  60. GodTemp::clearUserGodChanges($userId);
  61. } catch (\Exception $e) {
  62. Log::error('清除用户神像变更临时数据失败', [
  63. 'error' => $e->getMessage(),
  64. 'user_id' => $userId,
  65. ]);
  66. }
  67. }
  68. /**
  69. * 清除用户特定神像类型的变更临时数据
  70. *
  71. * @param int $userId 用户ID
  72. * @param int $godType 神像类型
  73. * @return void
  74. */
  75. public static function clearUserGodChange(int $userId, int $godType): void
  76. {
  77. try {
  78. GodTemp::clearUserGodChange($userId, $godType);
  79. } catch (\Exception $e) {
  80. Log::error('清除用户特定神像变更临时数据失败', [
  81. 'error' => $e->getMessage(),
  82. 'user_id' => $userId,
  83. 'god_type' => $godType,
  84. ]);
  85. }
  86. }
  87. }