Semi-analytical model for planetary resonances: application to planets around single and binary stars