| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- namespace App\Module\Farm\Repositories;
- use App\Module\Farm\Models\FarmGodBuff;
- use Dcat\Admin\Repositories\EloquentRepository;
- use Illuminate\Database\Eloquent\Collection;
- /**
- * 神灵加持仓库
- *
- * 提供神灵加持数据的访问和操作功能。
- * 该类是神灵加持模块与后台管理系统的桥梁,用于处理神灵加持数据的CRUD操作。
- */
- class FarmGodBuffRepository extends EloquentRepository
- {
- /**
- * 模型类名
- *
- * @var string
- */
- protected $eloquentClass = FarmGodBuff::class;
- /**
- * 获取用户的所有神灵加持
- *
- * @param int $userId
- * @return Collection
- */
- public function findByUserId(int $userId): Collection
- {
- return FarmGodBuff::where('user_id', $userId)->get();
- }
- /**
- * 获取用户的有效神灵加持
- *
- * @param int $userId
- * @return Collection
- */
- public function findActiveByUserId(int $userId): Collection
- {
- return FarmGodBuff::where('user_id', $userId)
- ->where('expire_time', '>', now())
- ->get();
- }
- /**
- * 获取用户指定类型的神灵加持
- *
- * @param int $userId
- * @param int $buffType
- * @return FarmGodBuff|null
- */
- public function findByUserIdAndType(int $userId, int $buffType): ?FarmGodBuff
- {
- return FarmGodBuff::where('user_id', $userId)
- ->where('buff_type', $buffType)
- ->first();
- }
- /**
- * 获取用户指定类型的有效神灵加持
- *
- * @param int $userId
- * @param int $buffType
- * @return FarmGodBuff|null
- */
- public function findActiveByUserIdAndType(int $userId, int $buffType): ?FarmGodBuff
- {
- return FarmGodBuff::where('user_id', $userId)
- ->where('buff_type', $buffType)
- ->where('expire_time', '>', now())
- ->first();
- }
- /**
- * 清理过期的神灵加持
- *
- * @return int
- */
- public function deleteExpired(): int
- {
- return FarmGodBuff::where('expire_time', '<', now())->delete();
- }
- }
|