I was surprised to find quite a few sites discuss the origin of this phrase – I thought it would turn out to be a colloquial phrase with no origin.
Stackexchange found several uses in the early 1900s. William F. Drannan’s novel, Thirty-one Years on the Plains and in the Mountains, and Jeff W. Hayes’ novel, Tales of the Sierras (both 1900) put the words in the mouth of Native American characters. Other novels put the phrase in the mouths of Oriental characters. In fifteen years, Anglo characters in westerns used the phrase, and it continued to spread.
Some people suggest the phrase is a literal translation from Chinese – see the comments at englishforums.
Wikipedia includes Drannan’s usage, but also found “James Campbell’s Excursions, Adventures, and Field-Sports in Ceylon (published 1843): ‘Ma-am—long time no see wife—want go to Colombo see wife.'”
“How and why did such a grammatically awkward phrase become a widely accepted part of American speech?” asks NPR. They found the first print usage to be Drannan’s novel, but also report sources that claim sailors (maybe English, maybe America) picked it up in China.
“By 1920, the phrase makes it into Good Housekeeping magazine. The novelist Raymond Chandler used it in more than one of his books,” and today is seen as American slang.