<?php

    function user_spent($type, $user, $balance){
        
        global $db;
        
        $usersorgu = $db->from('users')->where('user_id', $user)->first();
            
        if($usersorgu){
            
            if($type == "ekle"){
                
                if(is_double($balance)){
                    
                    $update = $db->update('users')->where('user_id', $user)
                    ->set(array(
                        'user_spent' => $usersorgu['user_spent'] + $balance    
                    ));
                    
                    if($update){
                        
                        $return = true;
                    
                    }else{
                        
                        $return = false;
                        
                    }
                    
                }else{
                    
                    $return = false;
                    
                }
                
            }elseif($type == "cikar"){
                
                if(is_double($balance)){
                    
                    $update = $db->update('users')->where('user_id', $user)
                    ->set(array(
                        'user_spent' => $usersorgu['user_spent'] - $balance    
                    ));
                    
                    if($update){
                        
                        $return = true;
                    
                    }else{
                        
                        $return = false;
                        
                    }
                    
                }else{
                    
                    $return = false;
                    
                }
                
            }
                
        }else{
            
            $return = false;
                
        }
        
        return $return;
        
    }