| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- namespace App\Module\Farm\Repositories;
- use App\Module\Farm\Models\FarmHouseConfig;
- use Dcat\Admin\Repositories\EloquentRepository;
- /**
- * 房屋等级配置仓库
- *
- * 提供房屋等级配置数据的访问和操作功能。
- * 该类是房屋等级配置模块与后台管理系统的桥梁,用于处理房屋等级配置数据的CRUD操作。
- */
- class FarmHouseConfigRepository extends EloquentRepository
- {
- /**
- * 模型类名
- *
- * @var string
- */
- protected $eloquentClass = FarmHouseConfig::class;
- /**
- * 根据等级获取房屋配置
- *
- * @param int $level
- * @return FarmHouseConfig|null
- */
- public function findByLevel(int $level): ?FarmHouseConfig
- {
- return FarmHouseConfig::where('level', $level)->first();
- }
- /**
- * 获取最大房屋等级
- *
- * @return int
- */
- public function getMaxLevel(): int
- {
- return FarmHouseConfig::max('level') ?? 1;
- }
- /**
- * 获取需要降级检查的房屋等级配置
- *
- * @return array
- */
- public function findNeedDowngradeCheck(): array
- {
- return FarmHouseConfig::whereNotNull('downgrade_days')
- ->where('level', '>', 1)
- ->pluck('downgrade_days', 'level')
- ->toArray();
- }
- /**
- * 获取下一级房屋配置
- *
- * @param int $currentLevel
- * @return FarmHouseConfig|null
- */
- public function findNextLevel(int $currentLevel): ?FarmHouseConfig
- {
- return FarmHouseConfig::where('level', $currentLevel + 1)->first();
- }
- }
|