Analytical solutions to a class of nonlinear Schrödinger equations with -like potentials