SeedService.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. namespace App\Module\Farm\Services;
  3. use App\Module\Farm\Logics\SeedLogic;
  4. use App\Module\Farm\Models\FarmSeed;
  5. use Illuminate\Support\Collection;
  6. use Illuminate\Support\Facades\Log;
  7. /**
  8. * 种子管理服务
  9. */
  10. class SeedService
  11. {
  12. /**
  13. * 获取所有种子
  14. *
  15. * @return Collection
  16. */
  17. public static function getAllSeeds(): Collection
  18. {
  19. try {
  20. $seedLogic = new SeedLogic();
  21. return $seedLogic->getAllSeeds();
  22. } catch (\Exception $e) {
  23. Log::error('获取所有种子失败', [
  24. 'error' => $e->getMessage(),
  25. 'trace' => $e->getTraceAsString()
  26. ]);
  27. return collect();
  28. }
  29. }
  30. /**
  31. * 获取指定类型的种子
  32. *
  33. * @param int $type
  34. * @return Collection
  35. */
  36. public static function getSeedsByType(int $type): Collection
  37. {
  38. try {
  39. $seedLogic = new SeedLogic();
  40. return $seedLogic->getSeedsByType($type);
  41. } catch (\Exception $e) {
  42. Log::error('获取指定类型种子失败', [
  43. 'type' => $type,
  44. 'error' => $e->getMessage(),
  45. 'trace' => $e->getTraceAsString()
  46. ]);
  47. return collect();
  48. }
  49. }
  50. /**
  51. * 获取种子详情
  52. *
  53. * @param int $seedId
  54. * @return FarmSeed|null
  55. */
  56. public static function getSeedDetail(int $seedId): ?FarmSeed
  57. {
  58. try {
  59. $seedLogic = new SeedLogic();
  60. return $seedLogic->getSeedDetail($seedId);
  61. } catch (\Exception $e) {
  62. Log::error('获取种子详情失败', [
  63. 'seed_id' => $seedId,
  64. 'error' => $e->getMessage(),
  65. 'trace' => $e->getTraceAsString()
  66. ]);
  67. return null;
  68. }
  69. }
  70. /**
  71. * 获取种子的产出配置
  72. *
  73. * @param int $seedId
  74. * @return Collection
  75. */
  76. public static function getSeedOutputs(int $seedId): Collection
  77. {
  78. try {
  79. $seedLogic = new SeedLogic();
  80. return $seedLogic->getSeedOutputs($seedId);
  81. } catch (\Exception $e) {
  82. Log::error('获取种子产出配置失败', [
  83. 'seed_id' => $seedId,
  84. 'error' => $e->getMessage(),
  85. 'trace' => $e->getTraceAsString()
  86. ]);
  87. return collect();
  88. }
  89. }
  90. /**
  91. * 根据物品ID获取种子
  92. *
  93. * @param int $itemId
  94. * @return FarmSeed|null
  95. */
  96. public static function getSeedByItemId(int $itemId): ?FarmSeed
  97. {
  98. try {
  99. $seedLogic = new SeedLogic();
  100. return $seedLogic->getSeedByItemId($itemId);
  101. } catch (\Exception $e) {
  102. Log::error('根据物品ID获取种子失败', [
  103. 'item_id' => $itemId,
  104. 'error' => $e->getMessage(),
  105. 'trace' => $e->getTraceAsString()
  106. ]);
  107. return null;
  108. }
  109. }
  110. }