Theory of Mössbauer effect in intermediate-valence compounds