Yes, it can be done, theoretically, under certain "boundary conditions".
A smartphone with USB micro-B port should support the standard OTG function, with ID pin that controls the data direction of the smartphone. This standard function also simultaneously controls the direction of VBUS: in host role the VBUS is supplied (therefore no charging), and in device mode the phone will accept charge.
If you need to have the roles "mixed" up (get the phone to be charged while in host mode), the phone must support this feature called "accessory charging mode". The mode should be engaged if the ID pin impedance to ground is 20k or 120k.
So the upstream link must conform to "accessory charger mode". This is regarding the second part of the question.
Regarding the first part, you have to have a sizable MCU like 32-bit STM32, with two (!) USB OTG controllers (since you indicate the bottom link as "USB Upstream/Downstream" as well. This means that MCU must have FOUR controllers, two of HOST type, and TWO of device type. I am not sure if such a monster does exist.
For the "upstream" OTG link you will need to have two GPIOs to control the state of ID pin (grounded, floating, or 120k), which will need some analogish circuitry. To transmit this information from your MCU to phone, you will need a proprietary 5-wire cable, with ID pin connection. These cables only exist for automated testers. And then write software to control the mode.
Then you will need to write a ton of bridging software to manipulate all four controllers in accord, and channel the data. You will need to decide on (invent and implement) internal communication protocols, depending to what extent do you want the devices to be transparent to standard USB framework. So one-two years of work for a team of USB architect, a hardware engineer, and a software engineer, and you are done. Good luck.