I don't think the photons lose energy just by travel, but because they hit other atoms,ions, electrons and so many other things. As a result of those scattering processes, it results in an energy transfer between the particles and the energy of the photon eventually gets transferred to say the atmosphere, its particles and the earth in the form of heat etc.
Imagine of photons would lose energy just by moving in vacuum, then we would probably receive no light from the sun, as the sun is like 90million kms away and we should be a dark planet
Also do not confuse with classical newtons laws of losing kinetic energy (1/2mv^2) as a particle moves and the velocity decreases, because that is not applicable here entirely, as the light can both behave as a particle(e.g when photons hits an atom and scattering occurs) or as a wave(when it moves). (one of the drawbacks of classical newtons laws is its not completely valid for microscopic entities).