How do I prevent my iPhone from getting alerts when using Messages on my Mac?
Short of enabling Do Not Disturb on iPhone, or disabling notifications for the Messages app on iPhone (even more tedious than remembering to turn Do Not Disturb off), there is no direct way to prevent both iPhone and Mac from alerting you to the same message.

That said, I have noticed that if I am actively using Messages on Mac, after a few minutes I will start getting the messages on Mac first, and if I go to the Messages window quickly enough I will not get the alert on iPhone. Once I stop actively using Messages on Mac, the alerts on iPhone start appearing in a timely manner again. It seems to recognize which system or device you are actively using and delays notifications to the other systems/devices by a bit. The same occurs when I am using iPad - notifications on Mac and iPhone are delayed enough that if I read the message on iPad quickly enough, I will not get the notifications on the other devices.

I am not sure if the above is actually an unadvertised feature or just network delay, but it occurs consistently enough that I am quite sure there is some Apple intervention going on there.