| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- namespace App\Module\Farm\Repositories;
- use App\Module\Farm\Models\FarmSeedOutput;
- use Dcat\Admin\Repositories\EloquentRepository;
- use Illuminate\Database\Eloquent\Collection;
- /**
- * 种子产出配置仓库
- *
- * 提供种子产出配置数据的访问和操作功能。
- * 该类是种子产出配置模块与后台管理系统的桥梁,用于处理种子产出配置数据的CRUD操作。
- */
- class FarmSeedOutputRepository extends EloquentRepository
- {
- /**
- * 模型类名
- *
- * @var string
- */
- protected $eloquentClass = FarmSeedOutput::class;
- /**
- * 获取种子的所有产出配置
- *
- * @param int $seedId
- * @return Collection
- */
- public function findBySeedId(int $seedId): Collection
- {
- return FarmSeedOutput::where('seed_id', $seedId)->get();
- }
- /**
- * 获取种子的默认产出配置
- *
- * @param int $seedId
- * @return FarmSeedOutput|null
- */
- public function findDefaultBySeedId(int $seedId): ?FarmSeedOutput
- {
- return FarmSeedOutput::where('seed_id', $seedId)
- ->where('is_default', true)
- ->first();
- }
- /**
- * 获取指定物品ID的产出配置
- *
- * @param int $itemId
- * @return Collection
- */
- public function findByItemId(int $itemId): Collection
- {
- return FarmSeedOutput::where('item_id', $itemId)->get();
- }
- /**
- * 获取种子的所有产出配置,按概率降序排序
- *
- * @param int $seedId
- * @return Collection
- */
- public function findBySeedIdOrderByProbability(int $seedId): Collection
- {
- return FarmSeedOutput::where('seed_id', $seedId)
- ->orderByDesc('probability')
- ->get();
- }
- }
|