Вход Регистрация
Файл: public_html/core/payment/lib/UnitPayModel.php
Строк: 127
<?php
class UnitPayModel
{
    private 
$mysqli;

    static function 
getInstance()
    {
        return new 
self();
    }

    private function 
__construct()
    {
        
$port Config::DB_PORT;
        if (empty(
$port)) {
            
$port ini_get("mysqli.default_port");
        }
        
$this->mysqli = @new mysqli (
            
Config::DB_HOSTConfig::DB_USERConfig::DB_PASSConfig::DB_NAME$port
        
);
        
/* проверка подключения */
        
if (mysqli_connect_errno()) {
            throw new 
Exception('Не удалось подключиться к бд');
        }
    }

    function 
createPayment($unitpayId$account$sum$itemsCount)
    {
        
$query '
            INSERT INTO
                unitpay_payments (unitpayId, account, sum, itemsCount, dateCreate, status)
            VALUES
                (
                    "'
.$this->mysqli->real_escape_string($unitpayId).'",
                    "'
.$this->mysqli->real_escape_string($account).'",
                    "'
.$this->mysqli->real_escape_string($sum).'",
                    "'
.$this->mysqli->real_escape_string($itemsCount).'",
                    NOW(),
                    0
                )
        '
;

        return 
$this->mysqli->query($query);
    }

    function 
getPaymentByUnitpayId($unitpayId)
    {
        
$query '
                SELECT * FROM
                    unitpay_payments
                WHERE
                    unitpayId = "'
.$this->mysqli->real_escape_string($unitpayId).'"
                LIMIT 1
            '
;
            
        
$result $this->mysqli->query($query);

        if (!
$result){
            throw new 
Exception($this->mysqli->error);
        }

        return 
$result->fetch_object();
    }

    function 
confirmPaymentByUnitpayId($unitpayId)
    {
        
$query '
                UPDATE
                    unitpay_payments
                SET
                    status = 1,
                    dateComplete = NOW()
                WHERE
                    unitpayId = "'
.$this->mysqli->real_escape_string($unitpayId).'"
                LIMIT 1
            '
;
        return 
$this->mysqli->query($query);
    }
    
    function 
getAccountByName($account)
    {
        
$sql "
            SELECT
                *
            FROM
               "
.Config::TABLE_ACCOUNT."
            WHERE
               "
.Config::TABLE_ACCOUNT_NAME." = '".$this->mysqli->real_escape_string($account)."'
            LIMIT 1
         "
;
         
        
$result $this->mysqli
            
->query($sql);

        if (!
$result){
            throw new 
Exception($this->mysqli->error);
        }

        return 
$result->fetch_object();
    }

    function 
questUpdate($uid$quest_id$count=1)
    {
        
$quest $this->mysqli->query("SELECT * FROM `quest_user` WHERE `quest` = '".$quest_id."' AND `user` = '".$uid."'")->fetch_object();
        if(
$quest->rewarded == 0)
        {
            
$this->mysqli->query("UPDATE `quest_user` SET `count` = `count` + '".$count."' WHERE `id` = '".$quest->id."'");
        }
    }
    
    function 
donateForAccount($account$countRes)
    {
        
$count $countRes;
        if(
$countRes == 100$count += 10;
        elseif(
$countRes == 300$count += 30;
        elseif(
$countRes == 500$count += 50;
        elseif(
$countRes == 1000$count += 100;
        elseif(
$countRes == 3000$count += 300;
        
$user $this->mysqli->query("SELECT * FROM `users` WHERE `id` = '".$account."'")->fetch_object();
        if(
$user->referer 0)
        {
            
$percent round($count/100*20);
            
$this->mysqli->query("UPDATE `users` SET `gold` = `gold` + '".$percent."' WHERE `id` = '".$user->referer."'");
        }
        if(
$user->vip_type == 1$count += round($countRes/100*10);
        elseif(
$user->vip_type == 2$count += round($countRes/100*30);
        elseif(
$user->vip_type == 3$count += round($countRes/100*50);
        
$this->questUpdate($account5$count);
        
$query "
            UPDATE
                "
.Config::TABLE_ACCOUNT."
            SET
                "
.Config::TABLE_ACCOUNT_DONATE." = ".Config::TABLE_ACCOUNT_DONATE." + ".$this->mysqli->real_escape_string($count)."
            WHERE
                "
.Config::TABLE_ACCOUNT_NAME." = '".$this->mysqli->real_escape_string($account)."'
        "
;
        return 
$this->mysqli->query($query);
    }
}
Онлайн: 0
Реклама