What is the difference between work function, ionization potential and electron affinity in a semiconductor? What do they physically mean?

I have read the definitions in books like Sze, Streetman, Kittel etc but all of them give mathematical treatment. For example, work function is given as energy required to take out an electron from fermi level and electron affinity as energy required to take out an electron from bottom of conduction band to vacuum. But what do they physically mean?

Are these happening at the surface only or in the bulk as well? For silicon substrate, how does it work? Are the concepts defined in solid state? Also, electron affinity has a definition in chemistry as amount of energy released when an electron is added to a neutral atom or molecule to form a negative ion. How does it relate to solid state physics?