Using first-principles method, we studied the electronic structures, work functions and electron affinities of the GaN(0001), Ga(Mg)N(0001), AlGa(Mg)N(0001), and Cs adsorbed AlGa(Mg)N(0001) surfaces. A method was offered to calculate the surface electron affinity using work function. The results show that Al 3s has a strong appeal to N 2s, which enhances the orbital hybridization of Mg s and N p states, and increases doping concentration. The interaction between Mg and N atoms enhanced by Al doping leads to the increase of surface dipole moment. AlGa(Mg)N(0001)’s work function is the smallest in comparison with that of GaN(0001) and GaMgN(0001) surfaces. After Cs adsorption on AlGa(Mg)N(0001) surface, the transfer of Cs6s electrons to Ga atoms in the outermost layer enhances the dipole moment pointing to outside and decreases the work function of the system, the negative electron affinity achieves.