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(); } }