GameConsumeGroupRepository.php 990 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace App\Module\Game\Repositories;
  3. use App\Module\Game\Models\GameConsumeGroup;
  4. use Dcat\Admin\Repositories\EloquentRepository;
  5. /**
  6. * 消耗组仓库
  7. *
  8. * 提供消耗组数据的访问和操作功能。
  9. * 该类是消耗组模块与后台管理系统的桥梁,用于处理消耗组数据的CRUD操作。
  10. */
  11. class GameConsumeGroupRepository extends EloquentRepository
  12. {
  13. /**
  14. * 模型类名
  15. *
  16. * @var string
  17. */
  18. protected $eloquentClass = GameConsumeGroup::class;
  19. /**
  20. * 根据编码获取消耗组
  21. *
  22. * @param string $code
  23. * @return GameConsumeGroup|null
  24. */
  25. public function findByCode(string $code): ?GameConsumeGroup
  26. {
  27. return GameConsumeGroup::where('code', $code)->first();
  28. }
  29. /**
  30. * 获取所有消耗组的编码和名称
  31. *
  32. * @return array
  33. */
  34. public function getCodesAndNames(): array
  35. {
  36. return GameConsumeGroup::pluck('name', 'code')->toArray();
  37. }
  38. }