| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?php
- namespace App\Module\Farm\Services;
- use App\Module\Farm\Dtos\LandInfoDto;
- use App\Module\Farm\Logics\LandLogic;
- use Illuminate\Support\Collection;
- use Illuminate\Support\Facades\Log;
- /**
- * 土地管理服务
- */
- class LandService
- {
- /**
- * 获取用户的所有土地
- *
- * @param int $userId
- * @return Collection
- */
- public static function getUserLands(int $userId): Collection
- {
- try {
- $landLogic = new LandLogic();
- return $landLogic->getUserLands($userId);
- } catch (\Exception $e) {
- Log::error('获取用户土地失败', [
- 'user_id' => $userId,
- 'error' => $e->getMessage(),
- 'trace' => $e->getTraceAsString()
- ]);
- return collect();
- }
- }
- public static function getUserLand(int $userId,int $landId)
- {
- // 根据用户id,和土地id获取土地信息
- }
- /**
- * 获取用户指定位置的土地
- *
- * @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
- * @param array $materials 消耗的材料
- * @return bool
- */
- public static function upgradeLand(int $userId, int $landId, int $targetType, array $materials): bool
- {
- try {
- $landLogic = new LandLogic();
- return $landLogic->upgradeLand($userId, $landId, $targetType, $materials);
- } 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
- * @param int $landId
- * @return array
- */
- public static function getAvailableUpgradePaths(int $userId, int $landId): array
- {
- try {
- $landLogic = new LandLogic();
- return $landLogic->getAvailableUpgradePaths($userId, $landId);
- } catch (\Exception $e) {
- Log::error('获取可用升级路径失败', [
- 'user_id' => $userId,
- 'land_id' => $landId,
- 'error' => $e->getMessage(),
- 'trace' => $e->getTraceAsString()
- ]);
- return [];
- }
- }
- }
|