Jelly, 88 5 bytes
Æf=2+ÆfPÆf3»P Æf=2+ÆfPÆf3»P Main Link, argument is z Æf Prime factors =2 Compare the elements to two (returns 1 if it is) 3» +Æf Takes maximum Addof it3 toand the primevalue factorsfor (thuseach makingvalue allin 2sthe 3s)array P Takes the product of the whole thing Shameless port of @Emigna's 05AB1E answer but this is longer because I need to restate Æf after the addition (I think) :(Try it online!
Try it online!-3 bytes thanks to a hint from @Dennis!