PetStealService.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace App\Module\Pet\Services;
  3. use App\Module\Pet\Logic\PetStealLogic;
  4. use App\Module\Pet\Dtos\StealResultDto;
  5. /**
  6. * 宠物偷菜服务类
  7. *
  8. * 提供宠物偷菜功能的对外接口
  9. */
  10. class PetStealService
  11. {
  12. /**
  13. * 执行偷菜操作
  14. *
  15. * @param int $stealerId 偷菜者用户ID
  16. * @param int $targetUserId 被偷者用户ID
  17. * @param int $plantId 作物ID
  18. * @param int $petId 宠物ID
  19. * @return StealResultDto 偷菜结果
  20. * @throws \Exception 偷菜失败时抛出异常
  21. */
  22. public static function stealCrop(int $stealerId, int $targetUserId, int $plantId, int $petId): StealResultDto
  23. {
  24. return PetStealLogic::stealCrop($stealerId, $targetUserId, $plantId, $petId);
  25. }
  26. /**
  27. * 检查是否可以偷菜
  28. *
  29. * @param int $stealerId 偷菜者用户ID
  30. * @param int $targetUserId 被偷者用户ID
  31. * @param int $landId 土地ID
  32. * @return array 检查结果 ['can_steal' => bool, 'reason' => string]
  33. */
  34. public static function canSteal(int $stealerId, int $targetUserId, int $landId): array
  35. {
  36. return PetStealLogic::canSteal($stealerId, $targetUserId, $landId);
  37. }
  38. /**
  39. * 获取土地的偷菜信息
  40. *
  41. * @param int $landId 土地ID
  42. * @return array 偷菜信息
  43. */
  44. public static function getStealInfo(int $landId): array
  45. {
  46. return PetStealLogic::getStealInfo($landId);
  47. }
  48. /**
  49. * 获取用户的偷菜统计
  50. *
  51. * @param int $userId 用户ID
  52. * @return array 偷菜统计信息
  53. */
  54. public static function getStealStats(int $userId): array
  55. {
  56. return PetStealLogic::getStealStats($userId);
  57. }
  58. }