如何在laravel中获得百分比转介佣金?

时间:2017-11-08 09:06:21

标签: php sql laravel

我有这个脚本,以推荐金额为推荐人提供推荐佣金,例如每次推荐10美元。如果在网站上推荐人存款金额。 希望10%的推荐人存款金额转介给推荐人。 简单:如何配置$ ref ['balance']百分比 我已经尝试过繁殖,除以牺牲而不是工作

$refer = Auth::user()->under_reference;
        if($basic->reference_id == $refer){
            $ref['user_id'] = 0;
            $ref['reference_id'] = $basic->reference_id;
            $ref['under_reference'] = $user->reference;
            $ref['balance'] = ( $request->id * $basic->reference ) / 100;
            $ref['details'] = "Referral Invest Bonus : ".$ref['balance']."; ".$basic->currency.' Referral ID : # '.$ref['under_reference'];
            $ref['old_balance'] = $basic->admin_total;
            $ref['new_balance'] = $basic->admin_total;
            Reference::create($ref);

            //admin reference Log
            $ad['user_id'] = 0;
            $ad['balance_type'] = 5;
            $ad['balance'] = $ref['balance'];
            $ad['old_balance'] = $ref['old_balance'];
            $ad['new_balance'] = $ref['old_balance'];
            $ad['details'] = $ref['details'];
            $ad['charge'] = "Default";
            AdminBalance::create($ad);

            //admin balance log

            $ad['user_id'] = Auth::user()->id;
            $ad['balance_type'] = 2;
            $ad['balance'] = $request->id;
            $ad['old_balance'] = $basic->admin_total;
            $ad['new_balance'] = $basic->admin_total + $request->id;
            $ad['details'] = "Invest ID: # ".$dep['deposit_number'].'; '."Invest Plan : ".$plan->name;
            AdminBalance::create($ad);
            $basic->admin_total = $ad['new_balance'];
            $basic->save();

        }else{
            /* ---------- Reference Log ---------*/
            $rrrr = User::whereReference(Auth::user()->under_reference)->first();
            $ref['user_id'] = $rrrr->id;
            $ref['reference_id'] = $rrrr->reference;
            $ref['under_reference'] = $user->reference;
            $ref['balance'] = ( $request->id * $basic->reference ) / 100;
            $ref['details'] = "Referral Invest Bonus : ".$ref['balance']."-".$basic->currency."; ".' Referral ID : # '.$ref['under_reference'];
            $ref['old_balance'] = $rrrr->amount;
            $ref['new_balance'] = $rrrr->amount + $ref['balance'];
            Reference::create($ref);

            /*---- User reference Log ----*/
            $ad1['user_id'] = $rrrr->id;
            $ad1['balance_type'] = 5;
            $ad1['balance'] = $ref['balance'];
            $ad1['old_balance'] = $rrrr->amount;
            $ad1['new_balance'] = $rrrr->amount + $ad1['balance'];
            $ad1['details'] = $ref['details'];
            UserBalance::create($ad1);

            $rrrr->amount = $ref['new_balance'];
            $rrrr->save();

            /* ------ Admin reference Log -------*/
            $ad['user_id'] = $rrrr->id;
            $ad['balance_type'] = 5;
            $ad['balance'] = $ref['balance'];
            $ad['old_balance'] = $basic->admin_total;
            $ad['new_balance'] = $basic->admin_total - $ad['balance'];
            $ad['details'] = $ref['details'];
            AdminBalance::create($ad);
            $basic->admin_total = $ad['new_balance'];
            $basic->save();

0 个答案:

没有答案