Cooperation abounds in all biological systems. Spatial public goods game (PGG) serves as a baseline model when investigating the evolution of cooperation in collective interactions. Since analyzing collective interactions and dynamics in spatial structures is very complicated, a full theoretical understanding of spatial PGGs is still deficient. Here we generalize spatial PGGs in a three-layer weighted network—investment, benefit allocation, and strategy dispersal layers—which are not necessarily identical and thus cover a wide class of population structures and interaction scenarios. We provide an analytic formula that accurately predicts when cooperation is favored over defection, and that is applicable in populations of any size under weak selection. We prove that in regular networks investment and benefit allocation are essentially symmetric—that exchanging structures of investment and benefit allocation layers does not affect the evolutionary dynamics at all. The success of cooperators relies heavily on the correlation between an individual’s investment in a game and its benefit allocated from the same game. In most cases, the positive correlation, i.e., a greater investment in games with a larger share of benefits, facilitates a cooperative society. Importantly, we also show that diversifying the amounts of investment in different games or benefit allocation to different participants, if implementing improperly, might impede the global cooperation.