It is correct that others warn you about the solenoid issue. If you are fine with DIY, then you can actually get a great deal with
any K30 or K50, if it has developed what is called ABF:
Further information here:
A LITTLE BIT OF HISTORY: Development of the solenoid in Pentax cameras - PentaxForums.com
which shows you that a new (but more expensive) K70 will hardly have that problem.
Tutoriala how to repair:
Do-It-Yourself - PentaxForums.com
The K5 does indeed have a superior body to the K30 and no solenoid but it isn't as good in low light.
Also it isn't prepared for KAF4 and has no Focus-Peaking in LiveView, something very useful for macro which you use.
I'd say the K30, K50 are as good, have better AF, KAF4 and Focus-Peaking (Same goes for the K-S1, K-S2 and K70)
But the K5 is more sturdy, better built. The K5II and particular the K5IIs are fantastic in low-light, even better than the K3 imo (I have both).
But I never ever came across any K30 or K50 having the slightest problems with their body!
So on a tight budget and if able to apply DIY, yes, go for a K30 or K50 but with ABF and repair it yourself!
Then you have enough money for lenses.
Macro and 2:1:
As you have practive, the SMC Pentax 50/1,7 is a great lens, no matter if the manual M, the A-Version of the F50/1,7 or FA50/1,7.
If you purchase one day a real 1:1 50mm Macro, the Sigma 50/2,8 EX is possibly the cheapest to find.
With a Vivitar 2x Macro Focusing Teleconverter you get real 2:1 Macro with A-contact but no AF.
There are AF Macro Teleconverters by Kenco, but more expensive.
Shuttercount: Very much depends how the camera was used.
Of course a low shuttercount will allow you a better sleep.
A great lens to use with the K30/50/3 but not the K5-Series:
55-300 PLM! Fantastic lens.
The K30 needs this firmware:
Running K-50 firmware on K-30 - PentaxForums.com
The sensor of the K5-Series and K30/50 are the same, not just similar. But the K5IIs has no AA-filter.
The light sensitive f2,8 sensors came with the K5II, you find them in the K-S2 and K-70 as well.
But somehow this 15MP Sensor has some magic.
And yet, a higher resolution sensor will give you that extra headroom for Macro as well.