示例#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);
     }
 }
示例#2
0
 /**
  * Check for user existance and brought downline left right
  * Query build
  *
  * @return array[]
  */
 public function checkUplineUser($uplineId = null)
 {
     $result = [];
     if (User::where('username', $uplineId)->exists()) {
         array_push($result, "is available");
     } else {
         echo json_encode("User not found");
         return;
     }
     $userInfo = User::where('username', $uplineId)->first();
     if ($userInfo->id) {
         $downLineTableRow = Downline::where('user_id', $userInfo->id)->first();
         $left_member_id = $downLineTableRow->left_member_id;
         $right_member_id = $downLineTableRow->right_member_id;
         if ($left_member_id == 0 && $right_member_id == 0) {
             array_push($result, "Left , Right");
         } elseif ($left_member_id != 0 && $right_member_id == 0) {
             array_push($result, "Right");
         } elseif ($left_member_id == 0 && $right_member_id != 0) {
             array_push($result, "Left");
         } else {
             array_push($result, "No free position here. Please try another upline id");
         }
     } else {
         array_push($result, "Not Valid user found");
     }
     echo json_encode($result);
 }