Electron affinity is the difference between the energy level of conduction band to vacuum level. That means how much energy is needed to pump out a electron from conduction band to vacuum level.
Work-function is the difference between fermi level and vacuum level.
You can follow the following book for more details.
Semiconductor Physics And Devices: Basic Principles 4th Edition