I think that whenever we feel some kind of happiness or pleasure it is always related with improving our chances of survival, that might be temporarily or in long term, might be of only of an individual or his/her relatives or all human beings or all living beings as a whole.
I find that a sense happiness or pleasure is linked with the survival (might not be true as it's based on personal observation). We crave for things like attention & being cared, beauty & physical health, power (& money). Attaining them gives us a sense of pleasure, and these things improves the chances of our survival. People having power & money dont die out of scarcity. People having beauty & physical health get to pass their genes more often(keeping whole human history in mind). Dogs developed their behaviour around humans so as to get more attention & care thus improving their chances of survival. We also feel happy helping other people, we feel happy making more friends. But there is no simple answer to this one as we also have tendencies to hurt ourselves and some people derive pleasure in hurting others.
So is pleasure or happiness evolutionarily programmed into us to better our chances of survival?