Answer the question
In order to leave comments, you need to log in
How to store referral accruals?
There is a balance_transaction table, where the income from balance replenishment and expenses from order payments are recorded. The user table has a balance field so that you do not have to recalculate the balance every time.
You need to add a referral program, interest accruals will drip from the orders of attracted customers. Referral accruals are part of the main balance of the client, they can be spent on paying for goods, but the client can also withdraw referral accruals to his wallet.
The referral_transaction table was added, with the fields order_id (to account for the receipt of % of accruals from orders) and withdrawal_id (to account for the expense from withdrawals of ref charges).
The referral_balance field has been added to the user table, which reflects the current amount of referral charges.
1. Do I need to record the receipt of referral accruals in the balance_transaction table? To display the total balance while summing the user.balance and user.referral_balance fields.
2. How to be in a situation when, for example, user.balance = 10 r, user.referral_balance = 50 r, and the order is 40 r? Write in balance_transaction an expense of 10 rubles, and in referral_transaction an expense of 30 rubles? Wouldn't there be confusion later with such a division of payment for the order?
Answer the question
In order to leave comments, you need to log in
I would put a trigger on referral_transaction upon transition to the "approved" status so that an entry is added to balance_transaction. And summarized only balance_transaction.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question