| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- namespace App\Module\Farm\Services;
- use App\Module\Farm\Logics\SeedLogic;
- use App\Module\Farm\Models\FarmSeed;
- use Illuminate\Support\Collection;
- use Illuminate\Support\Facades\Log;
- /**
- * 种子管理服务
- */
- class SeedService
- {
- /**
- * 获取所有种子
- *
- * @return Collection
- */
- public static function getAllSeeds(): Collection
- {
- try {
- $seedLogic = new SeedLogic();
- return $seedLogic->getAllSeeds();
- } catch (\Exception $e) {
- Log::error('获取所有种子失败', [
- 'error' => $e->getMessage(),
- 'trace' => $e->getTraceAsString()
- ]);
-
- return collect();
- }
- }
-
- /**
- * 获取指定类型的种子
- *
- * @param int $type
- * @return Collection
- */
- public static function getSeedsByType(int $type): Collection
- {
- try {
- $seedLogic = new SeedLogic();
- return $seedLogic->getSeedsByType($type);
- } catch (\Exception $e) {
- Log::error('获取指定类型种子失败', [
- 'type' => $type,
- 'error' => $e->getMessage(),
- 'trace' => $e->getTraceAsString()
- ]);
-
- return collect();
- }
- }
-
- /**
- * 获取种子详情
- *
- * @param int $seedId
- * @return FarmSeed|null
- */
- public static function getSeedDetail(int $seedId): ?FarmSeed
- {
- try {
- $seedLogic = new SeedLogic();
- return $seedLogic->getSeedDetail($seedId);
- } catch (\Exception $e) {
- Log::error('获取种子详情失败', [
- 'seed_id' => $seedId,
- 'error' => $e->getMessage(),
- 'trace' => $e->getTraceAsString()
- ]);
-
- return null;
- }
- }
-
- /**
- * 获取种子的产出配置
- *
- * @param int $seedId
- * @return Collection
- */
- public static function getSeedOutputs(int $seedId): Collection
- {
- try {
- $seedLogic = new SeedLogic();
- return $seedLogic->getSeedOutputs($seedId);
- } catch (\Exception $e) {
- Log::error('获取种子产出配置失败', [
- 'seed_id' => $seedId,
- 'error' => $e->getMessage(),
- 'trace' => $e->getTraceAsString()
- ]);
-
- return collect();
- }
- }
-
- /**
- * 根据物品ID获取种子
- *
- * @param int $itemId
- * @return FarmSeed|null
- */
- public static function getSeedByItemId(int $itemId): ?FarmSeed
- {
- try {
- $seedLogic = new SeedLogic();
- return $seedLogic->getSeedByItemId($itemId);
- } catch (\Exception $e) {
- Log::error('根据物品ID获取种子失败', [
- 'item_id' => $itemId,
- 'error' => $e->getMessage(),
- 'trace' => $e->getTraceAsString()
- ]);
-
- return null;
- }
- }
- }
|