| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
- namespace App\Module\Farm\Services;
- use App\Module\Farm\Dtos\TeamInfoDto;
- use App\Module\Farm\Logics\TeamLogic;
- use Illuminate\Support\Collection;
- use Illuminate\Support\Facades\Log;
- /**
- * 团队管理服务
- */
- class TeamService
- {
- /**
- * 获取用户团队信息
- *
- * @param int $userId
- * @return TeamInfoDto|null
- */
- public static function getTeamInfo(int $userId): ?TeamInfoDto
- {
- try {
- $teamLogic = new TeamLogic();
- return $teamLogic->getTeamInfo($userId);
- } catch (\Exception $e) {
- Log::error('获取用户团队信息失败', [
- 'user_id' => $userId,
- 'error' => $e->getMessage(),
- 'trace' => $e->getTraceAsString()
- ]);
-
- return null;
- }
- }
-
- /**
- * 添加推荐关系
- *
- * @param int $userId
- * @param int $referrerId
- * @return bool
- */
- public static function addReferral(int $userId, int $referrerId): bool
- {
- try {
- $teamLogic = new TeamLogic();
- return $teamLogic->addReferral($userId, $referrerId);
- } catch (\Exception $e) {
- Log::error('添加推荐关系失败', [
- 'user_id' => $userId,
- 'referrer_id' => $referrerId,
- 'error' => $e->getMessage(),
- 'trace' => $e->getTraceAsString()
- ]);
-
- return false;
- }
- }
-
- /**
- * 更新用户达人信息
- *
- * @param int $userId
- * @return bool
- */
- public static function updateTalentInfo(int $userId): bool
- {
- try {
- $teamLogic = new TeamLogic();
- return $teamLogic->updateTalentInfo($userId);
- } catch (\Exception $e) {
- Log::error('更新达人信息失败', [
- 'user_id' => $userId,
- 'error' => $e->getMessage(),
- 'trace' => $e->getTraceAsString()
- ]);
-
- return false;
- }
- }
-
- /**
- * 获取用户的团队收益记录
- *
- * @param int $userId
- * @param int $limit
- * @return Collection
- */
- public static function getTeamProfits(int $userId, int $limit = 100): Collection
- {
- try {
- $teamLogic = new TeamLogic();
- return $teamLogic->getTeamProfits($userId, $limit);
- } catch (\Exception $e) {
- Log::error('获取用户团队收益记录失败', [
- 'user_id' => $userId,
- 'limit' => $limit,
- 'error' => $e->getMessage(),
- 'trace' => $e->getTraceAsString()
- ]);
-
- return collect();
- }
- }
- }
|