CVS reached a $315 million settlement Tuesday to resolve allegations that it illegally filled prescriptions for opioids and other controlled substances for over a decade and then sought payments for many of those invalid prescriptions from federal healthcare programs.