Borussia Dortmund went behind three times before coming back to beat Bayer 4-3 in a Bundesliga thriller.