FarmSeedOutputRepository.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace App\Module\Farm\Repositories;
  3. use App\Module\Farm\Models\FarmSeedOutput;
  4. use Dcat\Admin\Repositories\EloquentRepository;
  5. use Illuminate\Database\Eloquent\Collection;
  6. /**
  7. * 种子产出配置仓库
  8. *
  9. * 提供种子产出配置数据的访问和操作功能。
  10. * 该类是种子产出配置模块与后台管理系统的桥梁,用于处理种子产出配置数据的CRUD操作。
  11. */
  12. class FarmSeedOutputRepository extends EloquentRepository
  13. {
  14. /**
  15. * 模型类名
  16. *
  17. * @var string
  18. */
  19. protected $eloquentClass = FarmSeedOutput::class;
  20. /**
  21. * 获取种子的所有产出配置
  22. *
  23. * @param int $seedId
  24. * @return Collection
  25. */
  26. public function findBySeedId(int $seedId): Collection
  27. {
  28. return FarmSeedOutput::where('seed_id', $seedId)->get();
  29. }
  30. /**
  31. * 获取种子的默认产出配置
  32. *
  33. * @param int $seedId
  34. * @return FarmSeedOutput|null
  35. */
  36. public function findDefaultBySeedId(int $seedId): ?FarmSeedOutput
  37. {
  38. return FarmSeedOutput::where('seed_id', $seedId)
  39. ->where('is_default', true)
  40. ->first();
  41. }
  42. /**
  43. * 获取指定物品ID的产出配置
  44. *
  45. * @param int $itemId
  46. * @return Collection
  47. */
  48. public function findByItemId(int $itemId): Collection
  49. {
  50. return FarmSeedOutput::where('item_id', $itemId)->get();
  51. }
  52. /**
  53. * 获取种子的所有产出配置,按概率降序排序
  54. *
  55. * @param int $seedId
  56. * @return Collection
  57. */
  58. public function findBySeedIdOrderByProbability(int $seedId): Collection
  59. {
  60. return FarmSeedOutput::where('seed_id', $seedId)
  61. ->orderByDesc('probability')
  62. ->get();
  63. }
  64. }