The near-unanimous conclusion that "What can I do you for?" is basically a joke and a play on words seems to be incorrect. While the writers of Allo Allo and IT Crowd might well have employed it to that effect, having sat through the film Shane earlier today, it appears that this was standard usage (at least) in 1953 and likely in
AlabamaWyoming in the 1800s which is the setting for the story. The film is based on a novel of the same name.
According to a transcript of the dialogue, the following are all questions asked either by shopkeepers or bartenders:
Anything I can do you for?
- I came to get wire for Joe Starrett.
- I've been holding wire for Starrett for quite a spell.
A whole bunch came in. They brought their women to protect them.
- My jars come yet?
- Howdy, Starrett. What can I do you for?
Hello, Torrey. Something I can do you for?
- A jug. It's the Fourth.
- Come in, come in.
- Jug. And a whiskey.
A record studio owner from the movie "O Brother, Where art thou?" asks a similar question. This film is set in Mississippi in the 1930s.
The phrase "What can I do you for?" also has an entry in the book, Slang American style: more than 10,000 ways to talk the talk:
What can I do you for? interrog. "How can I help you?"; "How can I serve you?"
You can also hear it in the TV show, Dexter (Season 2, Episode 5, ~36 minutes), where a barman in Florida asks the eponymous protagonist the same question. He replies with, "Beer, whatever's on tap". There is no innuendo or any jocular overtones to the conversation.