I'm not sure that he sounds like a mid-life crisis, but the label is immaterial at this point. He is definitely have an affair, whether it's real or fantasy, he is feeling it.
Let's start with the beginners mindset, have you been focusing on you? Tell us about some 180's you've implemented or are working to implement, what about GAL activities?
As for having sex, doing so is not going to save your marriage, so if it's not something you want, tell him.. Don't feel like doing so is the only way to get him back, because it doesn't even help in getting him back.
M - 9 1/2 years 5/5/16 - Bomb drop - 3 week EA 10/31/16 - We sold house 01/10/18 - D Finalized