getUserLands($userId); } catch (\Exception $e) { Log::error('获取用户土地失败', [ 'user_id' => $userId, 'error' => $e->getMessage(), 'trace' => $e->getTraceAsString() ]); return collect(); } } /** * 根据土地ID获取土地信息 * * @param int $landId 土地ID * @return LandInfoDto|null */ public static function getLandById(int $landId): ?LandInfoDto { try { $land = FarmLand::find($landId); if (!$land) { return null; } return LandInfoDto::fromModel($land); } catch (\Exception $e) { Log::error('根据ID获取土地信息失败', [ 'land_id' => $landId, 'error' => $e->getMessage(), 'trace' => $e->getTraceAsString() ]); return null; } } /** * 根据用户id和土地id获取土地信息 * * @param int $userId 用户ID * @param int $landId 土地ID * @return LandInfoDto|null */ public static function getUserLand(int $userId, int $landId): ?LandInfoDto { try { $land = FarmLand::where('user_id', $userId) ->where('id', $landId) ->first(); if (!$land) { return null; } return LandInfoDto::fromModel($land); } catch (\Exception $e) { Log::error('获取用户土地信息失败', [ 'user_id' => $userId, 'land_id' => $landId, 'error' => $e->getMessage(), 'trace' => $e->getTraceAsString() ]); return null; } } /** * 获取用户指定位置的土地 * * @param int $userId * @param int $position * @return LandInfoDto|null */ public static function getUserLandByPosition(int $userId, int $position): ?LandInfoDto { try { $landLogic = new LandLogic(); return $landLogic->getUserLandByPosition($userId, $position); } catch (\Exception $e) { Log::error('获取用户指定位置土地失败', [ 'user_id' => $userId, 'position' => $position, 'error' => $e->getMessage(), 'trace' => $e->getTraceAsString() ]); return null; } } /** * 升级土地 * * @param int $userId * @param int $landId * @param int $targetType * @return bool */ public static function upgradeLand(int $userId, int $landId, int $targetType ): bool { try { $landLogic = new LandLogic(); return $landLogic->upgradeLand($userId, $landId, $targetType); } catch (\Exception $e) { Log::error('升级土地失败', [ 'user_id' => $userId, 'land_id' => $landId, 'target_type' => $targetType, 'error' => $e->getMessage(), 'trace' => $e->getTraceAsString() ]); return false; } } /** * 获取可用的升级路径 * * @param int $userId 用户ID * @param int $landId 土地ID * @param int|null $toType 目标土地类型ID(可选) * @return FarmLandUpgradeConfig[] */ public static function getAvailableUpgradePaths(int $userId, int $landId, ?int $toType = null): array { try { $landLogic = new LandLogic(); return $landLogic->getAvailableUpgradePaths($userId, $landId, $toType); } catch (\Exception $e) { Log::error('获取可用升级路径失败', [ 'user_id' => $userId, 'land_id' => $landId, 'to_type' => $toType, 'error' => $e->getMessage(), 'trace' => $e->getTraceAsString() ]); return []; } } /** * 获取用户所有可收获的土地 * * @param int $userId 用户ID * @return Collection|LandInfoDto[] */ public static function getHarvestableLands(int $userId): Collection { try { $landLogic = new LandLogic(); return $landLogic->getHarvestableLands($userId); } catch (\Exception $e) { Log::error('获取可收获土地失败', [ 'user_id' => $userId, 'error' => $e->getMessage(), 'trace' => $e->getTraceAsString() ]); return collect(); } } /** * 获取用户所有空闲的土地 * * @param int $userId 用户ID * @return Collection|LandInfoDto[] */ public static function getIdleLands(int $userId): Collection { try { $landLogic = new LandLogic(); return $landLogic->getIdleLands($userId); } catch (\Exception $e) { Log::error('获取空闲土地失败', [ 'user_id' => $userId, 'error' => $e->getMessage(), 'trace' => $e->getTraceAsString() ]); return collect(); } } /** * 获取用户所有有作物的土地 * * @param int $userId 用户ID * @return Collection|LandInfoDto[] */ public static function getLandsWithCrops(int $userId): Collection { try { $landLogic = new LandLogic(); return $landLogic->getLandsWithCrops($userId); } catch (\Exception $e) { Log::error('获取有作物的土地失败', [ 'user_id' => $userId, 'error' => $e->getMessage(), 'trace' => $e->getTraceAsString() ]); return collect(); } } }