I am having a problem wrapping my brain around how to implement the following (maybe I'm just burnt out!) :
The company I am making this web site for allows users to refer
other people to the site, and get paid for it. The problem I am having, is how to write the logic for this - and I am wondering if my database design is 'correct'.
Here's the database structures :
table 'users'
id (user's id - primary)
name
pw
etc.. etc...
(extensive table, but the id is the only really necessary part of the paymet/referral tracking)
table 'refs' (user referrals)
id (pri key)
user_id (id of the user who is SIGNED UP)
parent (id of the user who referred this user)
table 'payments'
id
user_id
amount (amount of payment)
paid (enum Y/N - has this amount been paid yet?)
ref_id (referral that this payment pertains to)
I don't even know if ref_id is necessary on 'payments'.....
But here is where I am having the logic problem :
For example :
User1 has an account, and refers User2 (receives credit for signup - $0.01)
User2 signs up User3 and User4.
(User2 gets credit - $0.01 each user....
BUT User1 now needs to get paid for this as well because
User30->parent = User2->parent = User1
Any help is GREATLY appreciated. If anyone is willing to help me, but needs more clarification, let me know.