CVS will pay $315 million to resolve a federal lawsuit alleging the pharmacy giant unlawfully dispensed medically unnecessary opioid prescriptions.