Answer the question
In order to leave comments, you need to log in
Php referral system, how to shorten the code?
I am writing a multi-level referral system with ranks. Those. 5 levels and ranks for the number of invitees, each has a different percentage of deductions. When registering, I enter the id of the inviting referral. Further, when a referral buys a package, I make deductions
$dataRef = $this->db->column('SELECT ref FROM accounts WHERE id = :id',
['id' => $data['uid']]);
if ($dataRef === false) {
return false;
}
if ($dataRef != 0) {
$refSum = round((($data['amount'] * 15) / 100), 2);
$params = [
'sum' => $refSum,
'id' => $dataRef,
];
$this->db->query('UPDATE accounts SET refBalance = refBalance + :sum WHERE id = :id', $params);
$dataRef2 = $this->db->column('SELECT ref FROM accounts WHERE id = :id', ['id' => $dataRef]);
if ($dataRef2 === 0) {
return false;
}
if ($dataRef2 != 0) {
$refSum = round((($data['amount'] * 10) / 100), 2);
$params = [
'sum' => $refSum,
'id' => $dataRef2,
];
$this->db->query('UPDATE accounts SET refBalance = refBalance + :sum WHERE id = :id', $params);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question