In this paper, we study a (3+1)-dimensional generalized shallow water wave equation with variable coefficients, which describes the flow below a pressure surface in a fluid. We give the Kadomtsev–Petviashvili hierarchy reduction and construct the multi-soliton solutions and semi-rational solutions in terms of the Gramian. For the multi-soliton solutions, we conclude that: (1) affects the directions for the two solitons to move; (2) there is the periodic interaction of the two solitons when is a periodic function and (3) the magnitudes of the velocities for the two solitons increase as the amplitude of the periodic function increases, where represents the perturbed effect, indicates the dispersion effect and t is an independent variable. For the first-order semi-rational solutions, we see that: (1) the fission with and fusion with appear; (2) there is the periodic interaction when is a periodic function; (3) the magnitude of the velocity for the soliton increases as the amplitude of the periodic function increases and (4) the lump becomes narrower as the amplitude of the periodic function decreases, where indicates the perturbed effect.