Hi sxfx,
I understand that your phone keeps restarting randomly or sometimes it just shuts down. You've come to the right place for some help.
Below is an article that will provide you steps to help fix the issue you are having with the phone. Give those steps a try.
If your iOS device restarts or displays the Apple logo or a spinning gear unexpectedly
If the steps didn't resolve the restarting I would recommend contacting Apple Support directly.
Get Support
Hope this helps you resolve the issue and that you have a wonderful day!
-Dallen