With the rapid development of the distributed generation technology on the user side, it has become an important development trend to improve the reliability and economy of the community energy consumption by configuring the energy storage. In the context of the sharing economy, this paper proposes an optimal operation strategy for the distributed photovoltaic communities under a two-layer structure. First, the upper layer is a shared centralized energy storage operation mode based on the Stackelberg game for multiple communities, which realizes the charging and discharging decisions of the centralized shared energy storage and the dynamic optimization of the sharing prices for energy storage service. The various factors such as the similarities between the photovoltaic output and the total load of the alliance, the sizes of the net output and the correlation of the net output are considered comprehensively to improve the Shapley value,through which the additional benefits of the alliance are distributed reasonably. The simulation results show that the proposed method is beneficial to improving the consumption rate of the distributed power generation, reducing the energy consumption costsof the communities, and realizing the reasonable distribution of the energy sharing benefits. © 2023 Power System Technology Press. All rights reserved.