It's a little better and a little worse than you doubt.
First of all, if you cast a spell without casting defensively, you get one attack of opportunity from each single enemy that has you in its threat range, unless they've already done an AoO in that round.
This means several different things.
One AoO per enemy, but only if he's near
First of all, anyone willing to punish you for trying to cast needs to have you in melee range and to wield a weapon (or have the improved unarmed strike feat).
Several enemies could satisfy these conditions and each one gets the possibility to use his once-per-turn extra attack on you.
This means you can usually step back to avoid AoOs. Unless the movement also nets you some AoOs (which you can avoid by taking a 5ft step only or by making tumble checks.
While this is a basic and awesome tactic, there are situations where you don't want to step back, like if the spell you need to cast is a touch range one.
The enemy goes first
Second, yes, the attack happens before you complete your action. It means the attack can disrupt your casting by damaging you while you're casting a spell, just like if the enemy prepared against you casting a spell but is a free action (and thus a gain in the action economy).
This does not mean the enemy goes first in the initiative count. Unless he has the Combat Reflexes feat a character can't make AoOs while flat-footed.
This means you, as a spellcaster, should not normally worry about AoOs if you win initiative. But you're not usually in the threat range of any enemy when that happens, right?
One AoO only between your turn and the next one
Third, they need to choose if they want to make the AoO on you or on someone else, should the opportunity arise. You could trick them into attacking you to let the barbarian run amongst them with no risk... or the opposite (provided the second one of you acts before the enemy turn, when he recharges his AoOs).
It's worth noting that the Combat Reflexes feat allows a character more AoOs between their turns and this can nullify such a ruse.
The usual solution
There's another way to avoid AoO for spellcasting and it's called casting defensively. You just declare you're casting defensively and you don't provoke AoOs anymore. You need to pass a concentration check to successfully cast the spell. The DC is manageable and your modifiers should be high so this is the safe and intended way to do it.
Bonus info: if you need to cast a touch spell remember you can get your move action between the casting and the delivery. This means you cast it outside melee threat range, then move in.