How to add commission when a new referral switch to premium user

I have a site which have normal and paid user. Paid user can earn money by clicking on ads and by referring people.
Both normal and paid user can invite their friends with email.

My table structure is: usrid, name. email, pass, ref_id, premium(booleon)

where ref_id is the usrid of the person through which this user created account.
If B creates through A, and C through B and so on. I want to pay some commission money to A up to level 7 users.
I didn’t create any column for money because i am in doubt how to add money is A when he get referrals or subreferrals(referrals of referral)

How to do that. I can provide more information if require for answer this problem.

if B creates through A, you populate B ref_id with A id., if C creates through B you populate C ref_id with B id. To pay A up to the seven referral, You select 7 B referral in ascending order and pay A commission on that. Just like that and the process continues for other members

thanks for your reply. I asked i want to pay whenever user signup through the referral link and switch to premium account.

And i am paying A for level 7 referrals that means:

1.All direct referrals of A
2. All referrals of B
3. All referrals of C
4. All referrals of D
And this will go to F.

Then it will called 7 levels.

Which type of code should i use and table structure.