Surface enhanced Raman scattering (SERS) sensors with excellent sensitivity, stability and repeatability are essential for the ultrasensitive analysis of trace targets. In this study, a SERS sensor was developed using a photonic heterostructure composed of Au nanoparticles (AuNPs) & Zeolitic Imidazolate Framework-8 photonic crystals (ZIF-8 PCs). The sensor aims to enrich and detect organic dyes and pesticides, with enhanced detection capabilities achieved through adjustments in AuNPs content and the band-edge effects of ZIF-8 PCs. The sensor exhibited excellent performances in detecting 4-mercaptobenzoic acid. The detection limit was 1 × 10–12 mol·L−1, with a relative standard deviation of 5.0 % and the enhancement factor of 1.439 × 1011. Furthermore, the self-enrichment function of the sensor was verified through molecular dynamics simulations. This validation enabled the SERS sensor to be effectively utilized for the analysis of Rhodamine 6 G (R6G), methylene blue (MB), Thiabendazole (TBZ) and Parathion-methyl (PTM) without complex pretreatment. The detection limits achieved were 1 × 10–12 for R6G and MB, and 1 × 10–11 mol·L−1 for TBZ and PTM, respectively. This study presented an effective strategy for constructing high-performance SERS sensors, elucidated the mechanism of analyte enrichment and achieved the detection of samples in natural lake water, which offers a new option for on-site monitoring of contaminants with a portable Raman spectroscopy.