Thanks for your query.Based on the facts that you have posted it appears that you have acquired infection of the foreskin.(Posthatitis)due to fungal infection
Have you checked your blood sugar levels recently. Please get your blood sugar levels done on empty stomach and 2 hours after lunch to rule out Diabetes
Take some antibiotics like Doxycycline along with anti fungal medication Fluconazole
twice daily for 5 days. Aplply topical anti fungal gel like Meconazole over foreskin .
This should get cured in a week
If you are not able to retract your foreskin completely you may need to get circumcised by a qualified General Surgeon