Animals will not lose happiness until they are outside past 7PM, but they will start losing happiness if have already put them inside before then (starting at 6PM).
Thus, if you put your animals inside prior to 6PM, your animals will begin losing happiness then, because you are still awake.
Regarding the wild animal attacks, from the wiki section on this subject, it seems like the "wild animal attack" check is only performed overnight. It doesn't matter when the door is closed, so long as it is closed.
After the player goes to sleep, any events that will happen during the night (such as Bundle events) are calculated as normal. If no events are due to occur, there will be a 50% chance that the game will attempt to start a wild animal attack event. If this event proceeds, the game will go through all buildings to find a barn or coop that has their doors closed and has animals left outside.
However, from this, it sounds like this check is only done to see if any animals have been left outside and have their housing door closed behind them.
I've seen other threads that claim that leaving the doors open will not result in a wild animal attack, like this one:
I always leave the doors open. No reason not to really. If there's a downside to it, I've not noticed it. On the other hand, I hear you can potentially trap your animals outside leaving them vulnerable to wolves if you close them before they've gone in.
Another thread says something similar:
There is pretty much no downside. I leave it open all the time.
The only downside might be that goats supposedly don't like it, but mine are at 5 hearts for years now. It might take a bit longer to get them to 5 hearts though, but I didn't notice since I couldn't compare it