<?php

    $amount=$up_id->amount;
    $uusersid=$up_id->id;

    $query=$this->db->query("SELECT * FROM  trader_activation WHERE trader_id=$uusersid ORDER BY id DESC LIMIT 1 ")->getResult();
    $trans=$query[0];

    $str1=trim($trans->btc_address);
    $coin_id = 1;
    $condition = "coid ='".$coin_id."'";
    $cointable = $this->common_model->GetRow('coin_info',$condition);
    $coin_symbol=trim(strtolower($cointable->coin_symbol));
    $coin_decimal=$cointable->coin_decimal;
    $ch = curl_init('https://api.blockcypher.com/v1/'.$coin_symbol.'/main/addrs/'.trim($str1));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
    curl_setopt($ch, CURLOPT_TIMEOUT, 3000);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));   
    $data1 = curl_exec($ch);
    if(curl_error($ch))
    {
        echo curl_error($ch);
    }
    if($data1)
    {
        $output = json_decode($data1);
        $output1 = $output->txrefs;
        $balance = $output->balance;
        //$balance=$amount;
        $subscriptiontype='yearly';
        $period=365;
        $endate = strtotime("+".$period." day", strtotime($dates));
        $enddate=date('Y-m-d H:i:s ', $endate);
        
        if($balance==$amount)
        {
                   
            $dep=$trans->depositid;
            $act=$trans->activation;
            if($dep=='' && $act=='')
            {

            $dates=date("Y-m-d H:i:s");
            $confirmation=$output1->confirmations;
            $this->db->query("INSERT INTO deposit SET uusersid='$uusersid',payment_id='2',pay_mode='2',amount='$balance',btc_amount='$balance',currency='".$coin_id."',transhash='".$output1->hash."', description='strategy',status='pending',invest_date='$dates',confirmation='$confirmation'");
            $depositid =$this->db->insertID();

            $update=$this->db->query("UPDATE trader_activation SET depositid='$depositid',activation='1' where trader_id='".$uusersid."'");

            $trid = "TRAN".strtoupper(uniqid());
            $history_data = array(
                "uusersid" => $uusersid,
                "amount"    =>  $amount,
                "btc_amount" => $amount,
                "type"   =>  'strategy',
                "description" => 'strategy payment made',
                "date"     =>  date("Y-m-d H:i:s"),
                "payment_id"    =>  $coin_id,
                "transactionid" => $trid,
                "depositid" =>  $depositid,
                "currency"=> $coin_id
            );
                            
            $query_status = $this->db->table('history')->insert($history_data);
        }                   
                                                                         
       }
        
    }

?>