In Laravel in want do distribute commission by loop if user have any sponsor user
i am creating level Plan (MLM) for distribution of commission to sponsored user up to 5 /10 level
here is my code i am able to do thing i want but i this there will be easier and cleaner way to do this and this is hardcore for 10 level .
i want to create dynamic where. i can change level a and this calculation work for that specific level.
plz help me thanks in advance
this is my controller
$sponser= DB::table('customers')->where('customers_id', '=', $request->customers_id)->value('sponsor_id');
// $isMember = ;
if (!empty($sponser)) {
$percentage = 4;
$price = $products_data->final_price;
$comm = ($price * $percentage )/ 100;
DB::table('ref_commissions')->insert([
'user_id' => $sponser,
'order_id' => $orders_id,
'percent' => $percentage,
'commission' => $comm,
]);
$sponser2= DB::table('customers')->where('user_id', '=', $sponser)->value('sponsor_id');
if (!empty($sponser2)) {
DB::table('ref_commissions')->insert([
'user_id' => $sponser2,
'order_id' => $orders_id,
'percent' => $percentage,
'commission' => $comm,
]);
$sponser3= DB::table('customers')->where('user_id', '=', $sponser2)->value('sponsor_id');
if (!empty($sponser3)) {
DB::table('ref_commissions')->insert([
'user_id' => $sponser3,
'order_id' => $orders_id,
'percent' => $percentage,
'commission' => $comm,
]);
$sponser4= DB::table('customers')->where('user_id', '=', $sponser3)->value('sponsor_id');
if (!empty($sponser4)) {
DB::table('ref_commissions')->insert([
'user_id' => $sponser4,
'order_id' => $orders_id,
'percent' => $percentage,
'commission' => $comm,
]);
$sponser5= DB::table('customers')->where('user_id', '=', $sponser4)->value('sponsor_id');
if (!empty($sponser5)) {
DB::table('ref_commissions')->insert([
'user_id' => $sponser5,
'order_id' => $orders_id,
'percent' => $percentage,
'commission' => $comm,
]);
$sponser6= DB::table('customers')->where('user_id', '=', $sponser5)->value('sponsor_id');
if (!empty($sponser5)) {
DB::table('ref_commissions')->insert([
'user_id' => $sponser6,
'order_id' => $orders_id,
'percent' => $percentage,
'commission' => $comm,
]);
$sponser7= DB::table('customers')->where('user_id', '=', $sponser6)->value('sponsor_id');
if (!empty($sponser5)) {
DB::table('ref_commissions')->insert([
'user_id' => $sponser7,
'order_id' => $orders_id,
'percent' => $percentage,
'commission' => $comm,
]);
$sponser8= DB::table('customers')->where('user_id', '=', $sponser7)->value('sponsor_id');
if (!empty($sponser5)) {
DB::table('ref_commissions')->insert([
'user_id' => $sponser8,
'order_id' => $orders_id,
'percent' => $percentage,
'commission' => $comm,
]);
$sponser9= DB::table('customers')->where('user_id', '=', $sponser8)->value('sponsor_id');
if (!empty($sponser5)) {
DB::table('ref_commissions')->insert([
'user_id' => $sponser9,
'order_id' => $orders_id,
'percent' => $percentage,
'commission' => $comm,
]);
}
//10 Level
}
//9 Level
}
//8 level
}
//7 level
}
//6 level
}
// 5 level
}
//4 level
}
//3 level
}
//2 level
}
// 1 level
from Laravel Questions and Answers https://laravelquestions.com/laravel/in-laravel-in-want-do-distribute-commission-by-loop-if-user-have-any-sponsor-user/
via Lzo Media
No comments:
Post a Comment