Resource management in fog computing is a highly challenging issue. Resource constraints of fog devices, the dynamic and diverse nature of workloads such as data-intensive, computationally intensive, and latency-sensitive applications, and the unpredictability of fog computing environments make it more challenging. How to collaboratively schedule edge, and end multi-layer ubiquitous computing resources to break through single node scale and resource bottlenecks to further improve computing performance also needs to be addressed. In this paper, we leverage idle resources on the user side, and study the resource allocation problems in the D2D-assisted fog computing networks. Firstly, we use an improved Louvain algorithm to cluster users and select the D2D device with the highest priority in each cluster as the cluster head to assist fog computing, where cluster heads can act as both servers and relays. Secondly, considering that fog nodes and D2D devices have limited resources and are not obligated to share their resources for free, we propose a price incentive method to construct a three-layer Stackelberg game model that maximizes the benefits of fog nodes and cluster heads while minimizing user costs. Then, we use the Lagrange multiplier method and the Karush–Kuhn–Tucker (KKT) conditions to solve the equilibrium point of the model to achieve our goal. Finally, the simulation results show that our proposed scheme markedly decreases the overall system cost in comparison to the four benchmark schemes. Moreover, in various scenarios the total cost of our scheme consistently remains lower than the other four schemes, affirming the efficiency of the scheme proposed in this paper.