多个if / else语句对我不起作用

时间:2018-06-26 16:12:01

标签: laravel

请帮帮我,我要执行此条件语句是该条件语句中的一两个要通过,但是我提供的任何表达式都不会保存到数据库中...谢谢

这是我调用的功能

public function updateuserstage($userid){

    $user = User::where("user_id",$userid)->first();
    //get the stage bonus for this stage
    $stageBonus = StageBonus::where("user_id",$userid)- 
    where("stage",$user->stage)->first();
    //get the completion bonus

    $bonus = $this->completionbonus($user->stage);

    $directdownline = $this->loaduserdirectdownlines($userid);

    // $downlineright = $this- 
    loaduserdirectdownlines($directdownline[0]->user_id);

    // $downlineleft = $this- 
    loaduserdirectdownlines($directdownline[1]->user_id);


    $downlineright = $this- 
    loaduserdirectdownlinesrightleft($directdownline[0]->user_id);

    $downlineleft = $this- 
    loaduserdirectdownlinesrightleft($directdownline[1]->user_id);

    // matching bonus reward
    if(($user->boosted == 1) && ($directdownline[0]->boosted == 1) && 
    ($directdownline[1]->boosted == 1) && ($downlineright == 2) && 
    ($downlineleft == 2)){
        if (isset($bonus['point']))
            $stageBonus->point = $stageBonus->point+$bonus['point'];

        if (isset($bonus['ultimapv']))
            $stageBonus->point = $stageBonus- 
     point+$bonus['ultimapv'];

        if (isset($bonus['cash']))
            $stageBonus->cash = $stageBonus->cash+$bonus['cash'];

     // direct downline reward

当我在循环外登录它时,此函数在此返回true,但从不保存到此处的数据库

    } else if(($user->boosted == 1) && ($directdownline[0]->boosted == 
    1) || ($directdownline[1]->boosted == 1)){
        if (isset($bonus['point']))
            $stageBonus->point = $stageBonus->point+$bonus['point'];

        if (isset($bonus['totalultimarefbonus']))
            $stageBonus->cash = $stageBonus- 
    cash+$bonus['totalultimarefbonus'];

    } else if(($user->boosted == 1) && ($directdownline[0]->boosted == 
    1) || ($directdownline[1]->boosted == 0)){
        if (isset($bonus['point']))
            $stageBonus->point = $stageBonus->point+$bonus['point'];

        if (isset($bonus['ultimarefbonus']))
            $stageBonus->cash = $stageBonus- 
    cash+$bonus['ultimarefbonus'];

    } else if(($user->boosted == 1) && ($directdownline[0]->boosted == 
    0) || ($directdownline[1]->boosted == 1)){
        if (isset($bonus['point']))
            $stageBonus->point = $stageBonus->point+$bonus['point'];

        if (isset($bonus['ultimarefbonus']))
            $stageBonus->cash = $stageBonus- 
     >cash+$bonus['ultimarefbonus'];

    } else if(($user->boosted == 1) && ($downlineright[0]->boosted == 
    1) || ($downlineright[1]->boosted == 1) || ($downlineleft[0]- 
   >boosted == 1) || ($downlineleft[1]->boosted == 1)){

        if (isset($bonus['ultimarefbonuschild']))
            $stageBonus->cash = $stageBonus- 
   >cash+$bonus['ultimarefbonuschild'];

    // referral reward for parent user if boosted
    } else if($user->boosted == 1){

        if (isset($bonus['refbonus']))
            $stageBonus->cash = $stageBonus->cash+$bonus['refbonus'];   

    // referral reward for user that is not boosted
    } else if($user->boosted == 0){

        if (isset($bonus['point']))
            $stageBonus->point = $stageBonus->point+$bonus['point'];

        if (isset($bonus['refbonus']))
            $stageBonus->cash = $stageBonus->cash+$bonus['refbonus'];
    }


    $stageBonus->completed = 1;
    $stageBonus->completed_on = Carbon::now();

    $stageBonus->save();
    //increase user stage
    $user->stage+= 1;
    $user->save();

    }

}

此函数将确定要保存在这些表达式中的内容

public function completionbonus($stage){
    switch($stage){
        case 1:
            return [ 'voucher'=>600, 'cash'=>5000, 'point'=>100, 'refbonus'=>2000, 'totalultimarefbonus'=>4000, 'ultimarefbonus'=>2000, 'ultimarefbonuschild'=>1500, 'ultimapv'=>700];
            break;
    }

}

这是模型

Schema::create('stage_bonuses', function (Blueprint $table) {
        $table->increments('id');
        $table->string('user_id');
        $table->bigInteger('point')->default(0);
        $table->bigInteger('cash')->default(0);
        $table->date('date_entered')->nullable();
        $table->timestamps();

        $table->foreign('user_id')->references('user_id')->on('users');
    });

1 个答案:

答案 0 :(得分:0)

非常感谢您,我非常感谢您的努力 实际上已经得到了答案,条件是返回两个或true,如果返回两个或多个true,则不会保存到数据库...谢谢