Zend certified PHP/Magento developer

Assign what IP should get what gateway

I have two internet modem, modem A and modem B, they get internet from different service providers

Also, I have an access point that Wi-Fi devices may connect to that.

My router is a hap lite MikroTik router, Wi-Fi access point and modem A and modem B and one PC connects to my router four ethernet ports. And Wi-Fi devices connect to Wi-Fi access point or router Wi-Fi (depends on signal strength, wifi clients may connect to Wi-Fi access point SSID or router Wi-Fi SSID)

I want to do this:
Divide devices in two group, group A and group B, all of the clients in group A should access to clients group B and vice versa, but their internet gateway is different:

Group A should connect to internet just by modem A, if modem A failed to connect to internet, group A shouldn’t have access to internet,

Group B should connect to internet by modem B, but if modem B failed to connect to internet, group B should have access to internet by modem A.

How can I do that? can I assign different gateways to different devices into the router settings!? remember that I don’t want to set any IP settings on devices, everything should be done in router side.

This is diagram