FarmLandUpgradeConfigRepository.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace App\Module\Farm\Repositories;
  3. use App\Module\Farm\Models\FarmLandUpgradeConfig;
  4. use Dcat\Admin\Repositories\EloquentRepository;
  5. use Illuminate\Database\Eloquent\Collection;
  6. /**
  7. * 土地升级配置仓库
  8. *
  9. * 提供土地升级配置数据的访问和操作功能。
  10. * 该类是土地升级配置模块与后台管理系统的桥梁,用于处理土地升级配置数据的CRUD操作。
  11. */
  12. class FarmLandUpgradeConfigRepository extends EloquentRepository
  13. {
  14. /**
  15. * 模型类名
  16. *
  17. * @var string
  18. */
  19. protected $eloquentClass = FarmLandUpgradeConfig::class;
  20. /**
  21. * 获取指定起始类型的升级配置
  22. *
  23. * @param int $fromTypeId
  24. * @return Collection
  25. */
  26. public function findByFromTypeId(int $fromTypeId): Collection
  27. {
  28. return FarmLandUpgradeConfig::where('from_type_id', $fromTypeId)->get();
  29. }
  30. /**
  31. * 获取指定目标类型的升级配置
  32. *
  33. * @param int $toTypeId
  34. * @return Collection
  35. */
  36. public function findByToTypeId(int $toTypeId): Collection
  37. {
  38. return FarmLandUpgradeConfig::where('to_type_id', $toTypeId)->get();
  39. }
  40. /**
  41. * 获取指定升级路径的配置
  42. *
  43. * @param int $fromTypeId
  44. * @param int $toTypeId
  45. * @return FarmLandUpgradeConfig|null
  46. */
  47. public function findByFromAndToTypeId(int $fromTypeId, int $toTypeId): ?FarmLandUpgradeConfig
  48. {
  49. return FarmLandUpgradeConfig::where('from_type_id', $fromTypeId)
  50. ->where('to_type_id', $toTypeId)
  51. ->first();
  52. }
  53. /**
  54. * 获取所有可能的升级路径
  55. *
  56. * @return array
  57. */
  58. public function getAllUpgradePaths(): array
  59. {
  60. return FarmLandUpgradeConfig::select('from_type_id', 'to_type_id')
  61. ->get()
  62. ->map(function ($item) {
  63. return [
  64. 'from' => $item->from_type_id,
  65. 'to' => $item->to_type_id,
  66. ];
  67. })
  68. ->toArray();
  69. }
  70. }