예제 #1
0
 /**
  * Carry is recursive function
  * When user make deposit this function help to find user position where is.
  * Left or Right of upliner. And add points
  *
  * @return 
  */
 public function carry($uid = null, $upid = null, $amount = null)
 {
     // echo "<br/>".$upid . "<br/>";
     $uplineUserId = User::where('id', $upid)->first()->upline_id;
     $checkPosition = Downline::select('left_member_id', 'right_member_id')->where('user_id', $upid)->get();
     // Carry::where('user_id', $upid)->update(['right_carry'=>250]);
     if ($checkPosition) {
         foreach ($checkPosition as $position) {
             if ($position->left_member_id == $uid && $position->right_member_id != $uid) {
                 $left_carry = Carry::where('user_id', $upid)->first()->left_carry;
                 $newAmount = $left_carry + $amount;
                 Carry::where('user_id', $upid)->update(['left_carry' => $newAmount]);
             } else {
                 $right_carry = Carry::where('user_id', $upid)->first()->right_carry;
                 $newAmount = $right_carry + $amount;
                 Carry::where('user_id', $upid)->update(['right_carry' => $newAmount]);
             }
         }
     }
     // recursivly find upper lavel users
     if (!empty($uplineUserId)) {
         $this->carry($upid, $uplineUserId, $amount);
     }
 }