FarmSeedRepository.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace App\Module\Farm\Repositories;
  3. use App\Module\Farm\Models\FarmSeed;
  4. use Dcat\Admin\Repositories\EloquentRepository;
  5. use Illuminate\Database\Eloquent\Collection;
  6. /**
  7. * 种子配置仓库
  8. *
  9. * 提供种子配置数据的访问和操作功能。
  10. * 该类是种子配置模块与后台管理系统的桥梁,用于处理种子配置数据的CRUD操作。
  11. */
  12. class FarmSeedRepository extends EloquentRepository
  13. {
  14. /**
  15. * 模型类名
  16. *
  17. * @var string
  18. */
  19. protected $eloquentClass = FarmSeed::class;
  20. /**
  21. * 获取指定类型的种子
  22. *
  23. * @param int $type
  24. * @return Collection
  25. */
  26. public function findByType(int $type): Collection
  27. {
  28. return FarmSeed::where('type', $type)->get();
  29. }
  30. /**
  31. * 根据物品ID查找种子
  32. *
  33. * @param int $itemId
  34. * @return FarmSeed|null
  35. */
  36. public function findByItemId(int $itemId): ?FarmSeed
  37. {
  38. return FarmSeed::where('item_id', $itemId)->first();
  39. }
  40. /**
  41. * 获取所有普通种子
  42. *
  43. * @return Collection
  44. */
  45. public function findNormalSeeds(): Collection
  46. {
  47. return FarmSeed::where('type', 1)->get();
  48. }
  49. /**
  50. * 获取所有神秘种子
  51. *
  52. * @return Collection
  53. */
  54. public function findMysteriousSeeds(): Collection
  55. {
  56. return FarmSeed::where('type', 2)->get();
  57. }
  58. /**
  59. * 获取所有巨化种子
  60. *
  61. * @return Collection
  62. */
  63. public function findGiantSeeds(): Collection
  64. {
  65. return FarmSeed::where('type', 3)->get();
  66. }
  67. }