Distributed renewable energy, loads, and power sources can be aggregated into virtual power plants (VPPs) to participate in energy market transactions and generate additional revenue. In order to better coordinate the transaction relationships among various entities within VPPs, this paper proposes a two-stage optimization model for VPPs that considers the user-VPP-equipment alliance. Firstly, starting from the basic structure of VPP, it is proposed to divide the alliances in VPP into two alliances: demand-side user-VPP and supply-side equipment-VPP. And a VPP optimization framework considering the cooperative game of the user-VPP-equipment alliance has been established. Then, a two-stage optimization model for VPPs was established considering the cooperative game of user-VPP-equipment alliance. The day-ahead optimization model takes economic and social benefits as the dual objectives, and the intraday optimization model aims to minimize the cost of deviation penalties. Secondly, taking into account the risk levels and comprehensive marginal benefits of various entities within the VPP, a profit distribution method combining improved Shapley values and independent risk contribution theory is adopted to allocate the total revenue of the VPP. The case results show that the operating cost has been reduced by 5.75%, the environmental cost has been reduced by 4.46%, and the total profit has increased by 29.52%. The model can improve the overall efficiency of VPPs.