Analytical treatment of the structure and thermodynamics of the square-well fluid