WASHINGTON — The top legal officials in dozens of states are suing drug companies and retailers for their role in the opioid crisis, but as of June both the Republican Attorneys General Association and its Democratic counterpart were still taking hundreds of thousands of dollars from some of those companies.

RAGA, which represents 24 GOP state attorneys general, got a total of $385,000 from defendants and the pharmaceutical trade association PhRMA between Jan. 1, 2019 and June 30, 2019, according to late June filings. Walmart and PhRMA gave $130,000 apiece, Johnson & Johnson and CVS each donated $50,000 apiece, and Cardinal Health gave $25,000.

DAGA, which represents 27 officials, got a total of $365,000 from defendants and PhRMA during the same time period. The Democratic group received $125,000 from Walmart, $100,000 from Mallinckrodt Pharmaceuticals, $50,000 from PhRMA and CVS, $25,000 from Cardinal Health, and $15,000 from Walgreens.

The state attorneys general are currently negotiating multi-billion dollar settlements with the drug makers and distributors. Three attorneys general have also sued retailers, as have most of the cities and counties that have filed opioid suits.

Paul Nolette, an assistant professor of political science at Marquette University and an expert on state attorneys general, says he thinks the donations are meant to expand access. "While the companies likely realize that some sort of broader opioid settlement is inevitable at this point, the donations might help gain additional access to the AGs at a critical moment in the investigation."

Civil litigation expert Andrew Pollis of Cleveland's Case Western Reserve law school, who has been tracking the opioid lawsuits, says while there is nothing illegal about the donations, they do "raise important questions about the integrity of our political system."

DAGA declined to address the donations in a response to NBC News. "Whether it's tackling the opioid crisis and holding corporations accountable or taking care of our most vulnerable communities, Democratic attorneys general do the right thing by the law and for the people of their states, full stop," said Sean Rankin, DAGA executive director.

RAGA did not respond to requests for comment.

A PhRMA spokesperson did not respond to questions about the donations but told NBC News the group is not taking a position in the settlement talks since it steers clear of "anything that is related to companies' business transactions."

State and local officials began filing civil cases en masse against pharmaceutical manufacturers and distributors in 2017. Retailers like Walmart and Walgreens were included in a few of the state suits and most of the city and county suits because their pharmacies filled prescriptions for opioids. Nearly 2,000 of the city and county suits have been combined into a single federal case that is scheduled to go to trial in Cleveland this October.

The lawsuits filed by the state attorneys general against the opioid manufacturers, distributors and retailers are separate from the case in Ohio, but federal judge Dan Aaron Polster is trying to wrangle settlements for all of the parties involved and has invited the attorneys general to participate in settlement conversations. Polster has been overseeing settlement discussions since March 2018. PhRMA is not a defendant in any of the suits.

Giving to the RAGA and DAGA by opioid drug companies and retailers began to ramp up in 2015 as legal action became more likely, according to public filings. Donations from defendant companies to RAGA went from $177,000 in 2014 to over $600,000 by 2016. For DAGA, donations from defendant firms were $75,000 in 2014, but exceeded $600,000 in 2017.

Settlements that have already been reached give a sense of the potential impact of the upcoming Cleveland trial. In just one state, Oklahoma, two settlements and a trial verdict have already cost three drug makers more than $900 million.

Purdue Pharma, maker of OxyContin, faces civil action from at least 45 states. As NBC News reported on Aug. 27, lawyers for Purdue and the Sackler family, which owns the company, presented a negotiated settlement deal to the plaintiffs valued between $10 billion and $12 billion in late August.

However, in an email sent Saturday, two of the attorneys general negotiating the settlement said talks had stalled. According to two sources with knowledge of the discussions, most Democratic attorneys general opposed the proposed deal, while most Republicans supported it. The sources also said that the Sackler family objected to the amount of money it was asked to contribute to the settlement.

Purdue Pharma said in a statement on Monday that "negotiations continue" and the company remains "dedicated to a resolution that genuinely advances the public interest."

Purdue has not donated to RAGA or DAGA since 2018, but made more than $800,000 in donations to the two groups between 2014 and 2018.

In the past, opioid defendants have attended private events held by both RAGA and DAGA. Top RAGA donors are provided invitations to the association’s most exclusive events including its annual spring Edmund Randolph Club Retreat that was held this year in Sea Island, Georgia according to multiple people familiar with the organization’s events. The Democratic group also permits access by donors to the attorneys general at these events, but does not have a specific contribution level for access. DAGA and RAGA did not respond when asked if representatives of any defendant firms attended these events in 2019.

One of the top attorneys negotiating for the defendants in the Purdue/Sackler suit is the former Republican attorney general of Alabama, Luther Strange, who took direct campaign contributions from Purdue.

Former attorneys general are frequently hired by companies under fire to manage investigations and lawsuits and lobby attorneys general.