| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- namespace App\Module\Farm\Services;
- use App\Module\Farm\Dtos\FarmInfoDto;
- use App\Module\Farm\Logics\FarmLogic;
- use Illuminate\Support\Facades\Log;
- /**
- * 农场基础服务
- */
- class FarmService
- {
- /**
- * 获取用户农场信息
- *
- * @param int $userId
- * @return FarmInfoDto|null
- */
- public static function getFarmInfo(int $userId): ?FarmInfoDto
- {
- try {
- $farmLogic = new FarmLogic();
- return $farmLogic->getFarmInfo($userId);
- } catch (\Exception $e) {
- Log::error('获取用户农场信息失败', [
- 'user_id' => $userId,
- 'error' => $e->getMessage(),
- 'trace' => $e->getTraceAsString()
- ]);
- return null;
- }
- }
- /**
- * 初始化用户农场
- *
- * @param int $userId
- * @return FarmInfoDto|null
- */
- public static function initializeFarm(int $userId): ?FarmInfoDto
- {
- try {
- $farmLogic = new FarmLogic();
- return $farmLogic->initializeFarm($userId);
- } catch (\Exception $e) {
- Log::error('初始化用户农场失败', [
- 'user_id' => $userId,
- 'error' => $e->getMessage(),
- 'trace' => $e->getTraceAsString()
- ]);
- return null;
- }
- }
- }
|