FarmService.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace App\Module\Farm\Services;
  3. use App\Module\Farm\Dtos\FarmInfoDto;
  4. use App\Module\Farm\Logics\FarmLogic;
  5. use Illuminate\Support\Facades\Log;
  6. /**
  7. * 农场基础服务
  8. */
  9. class FarmService
  10. {
  11. /**
  12. * 获取用户农场信息
  13. *
  14. * @param int $userId
  15. * @return FarmInfoDto|null
  16. */
  17. public static function getFarmInfo(int $userId): ?FarmInfoDto
  18. {
  19. try {
  20. $farmLogic = new FarmLogic();
  21. return $farmLogic->getFarmInfo($userId);
  22. } catch (\Exception $e) {
  23. Log::error('获取用户农场信息失败', [
  24. 'user_id' => $userId,
  25. 'error' => $e->getMessage(),
  26. 'trace' => $e->getTraceAsString()
  27. ]);
  28. return null;
  29. }
  30. }
  31. /**
  32. * 初始化用户农场
  33. *
  34. * @param int $userId
  35. * @return FarmInfoDto|null
  36. */
  37. public static function initializeFarm(int $userId): ?FarmInfoDto
  38. {
  39. try {
  40. $farmLogic = new FarmLogic();
  41. return $farmLogic->initializeFarm($userId);
  42. } catch (\Exception $e) {
  43. Log::error('初始化用户农场失败', [
  44. 'user_id' => $userId,
  45. 'error' => $e->getMessage(),
  46. 'trace' => $e->getTraceAsString()
  47. ]);
  48. return null;
  49. }
  50. }
  51. }