| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- namespace App\Module\Farm\Repositories;
- use App\Module\Farm\Models\FarmLandUpgradeConfig;
- use Dcat\Admin\Repositories\EloquentRepository;
- use Illuminate\Database\Eloquent\Collection;
- /**
- * 土地升级配置仓库
- *
- * 提供土地升级配置数据的访问和操作功能。
- * 该类是土地升级配置模块与后台管理系统的桥梁,用于处理土地升级配置数据的CRUD操作。
- */
- class FarmLandUpgradeConfigRepository extends EloquentRepository
- {
- /**
- * 模型类名
- *
- * @var string
- */
- protected $eloquentClass = FarmLandUpgradeConfig::class;
- /**
- * 获取指定起始类型的升级配置
- *
- * @param int $fromTypeId
- * @return Collection
- */
- public function findByFromTypeId(int $fromTypeId): Collection
- {
- return FarmLandUpgradeConfig::where('from_type_id', $fromTypeId)->get();
- }
- /**
- * 获取指定目标类型的升级配置
- *
- * @param int $toTypeId
- * @return Collection
- */
- public function findByToTypeId(int $toTypeId): Collection
- {
- return FarmLandUpgradeConfig::where('to_type_id', $toTypeId)->get();
- }
- /**
- * 获取指定升级路径的配置
- *
- * @param int $fromTypeId
- * @param int $toTypeId
- * @return FarmLandUpgradeConfig|null
- */
- public function findByFromAndToTypeId(int $fromTypeId, int $toTypeId): ?FarmLandUpgradeConfig
- {
- return FarmLandUpgradeConfig::where('from_type_id', $fromTypeId)
- ->where('to_type_id', $toTypeId)
- ->first();
- }
- /**
- * 获取所有可能的升级路径
- *
- * @return array
- */
- public function getAllUpgradePaths(): array
- {
- return FarmLandUpgradeConfig::select('from_type_id', 'to_type_id')
- ->get()
- ->map(function ($item) {
- return [
- 'from' => $item->from_type_id,
- 'to' => $item->to_type_id,
- ];
- })
- ->toArray();
- }
- }
|