TeamService.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace App\Module\Farm\Services;
  3. use App\Module\Farm\Dtos\TeamInfoDto;
  4. use App\Module\Farm\Logics\TeamLogic;
  5. use Illuminate\Support\Collection;
  6. use Illuminate\Support\Facades\Log;
  7. /**
  8. * 团队管理服务
  9. */
  10. class TeamService
  11. {
  12. /**
  13. * 获取用户团队信息
  14. *
  15. * @param int $userId
  16. * @return TeamInfoDto|null
  17. */
  18. public static function getTeamInfo(int $userId): ?TeamInfoDto
  19. {
  20. try {
  21. $teamLogic = new TeamLogic();
  22. return $teamLogic->getTeamInfo($userId);
  23. } catch (\Exception $e) {
  24. Log::error('获取用户团队信息失败', [
  25. 'user_id' => $userId,
  26. 'error' => $e->getMessage(),
  27. 'trace' => $e->getTraceAsString()
  28. ]);
  29. return null;
  30. }
  31. }
  32. /**
  33. * 添加推荐关系
  34. *
  35. * @param int $userId
  36. * @param int $referrerId
  37. * @return bool
  38. */
  39. public static function addReferral(int $userId, int $referrerId): bool
  40. {
  41. try {
  42. $teamLogic = new TeamLogic();
  43. return $teamLogic->addReferral($userId, $referrerId);
  44. } catch (\Exception $e) {
  45. Log::error('添加推荐关系失败', [
  46. 'user_id' => $userId,
  47. 'referrer_id' => $referrerId,
  48. 'error' => $e->getMessage(),
  49. 'trace' => $e->getTraceAsString()
  50. ]);
  51. return false;
  52. }
  53. }
  54. /**
  55. * 更新用户达人信息
  56. *
  57. * @param int $userId
  58. * @return bool
  59. */
  60. public static function updateTalentInfo(int $userId): bool
  61. {
  62. try {
  63. $teamLogic = new TeamLogic();
  64. return $teamLogic->updateTalentInfo($userId);
  65. } catch (\Exception $e) {
  66. Log::error('更新达人信息失败', [
  67. 'user_id' => $userId,
  68. 'error' => $e->getMessage(),
  69. 'trace' => $e->getTraceAsString()
  70. ]);
  71. return false;
  72. }
  73. }
  74. /**
  75. * 获取用户的团队收益记录
  76. *
  77. * @param int $userId
  78. * @param int $limit
  79. * @return Collection
  80. */
  81. public static function getTeamProfits(int $userId, int $limit = 100): Collection
  82. {
  83. try {
  84. $teamLogic = new TeamLogic();
  85. return $teamLogic->getTeamProfits($userId, $limit);
  86. } catch (\Exception $e) {
  87. Log::error('获取用户团队收益记录失败', [
  88. 'user_id' => $userId,
  89. 'limit' => $limit,
  90. 'error' => $e->getMessage(),
  91. 'trace' => $e->getTraceAsString()
  92. ]);
  93. return collect();
  94. }
  95. }
  96. }