<?php 
defined('BASEPATH') OR exit('No direct script access allowed');

class Withdrawad extends CI_Controller {

    
    public function __construct()
    {
        parent::__construct();
        if($this->session->userdata('level') != 99)
        {
            
            redirect(base_url(''),'refresh');
            
        }
    }
    
    public function index()
    {
        $curl = curl_init();
        curl_setopt_array($curl, array(
        CURLOPT_URL => 'https://t.b777.win/Banks/api/scb_balance/fbgray?pin=312540',
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 0,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => 'GET',
        ));
        
        $response = curl_exec($curl);
        curl_close($curl);
        $arr = json_decode($response, true);
        $balance = $arr['balance'];
        $this->data['balance'] = $balance;
        $this->load->view('admin/Header');
        $this->load->view('admin/Withdrawad', $this->data ,false);
        $this->load->view('admin/Footer');
    }

    public function submit()
    {
        $amount = $this->input->post("amount");
        $curl = curl_init();
        curl_setopt_array($curl, array(
        CURLOPT_URL => 'https://t.b777.win/Banks/api/scb_transfer/fbgray?pin=312540',
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 0,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => 'POST',
        CURLOPT_POSTFIELDS => array('ToBank' => 'kbank','ToBankCode' => '0541854401','amount' => $amount,'pin' => '312540'),
        CURLOPT_HTTPHEADER => array(
            'Cookie: __cfduid=dfb1352b5b025f201ca2b136604330cbb1612548939'
        ),
        ));

        $response = curl_exec($curl);

        curl_close($curl);
        $arr = json_decode($response, true);
        if($arr['status'] == 'success')
        {

            $object = array(
                'amount' => $amount,
                'qrcode'    => $arr['data']['data']['additionalMetaData']['paymentInfo'][0]['QRstring']
            );
            $this->db->insert('withdraw_admin', $object);
            echo json_encode(['status' => 1, 'msg' => 'Success']);
        }else{
            echo json_encode(['status' => 0, 'msg' => $arr['msg']]);
        }
    }

    public function test()
    {
        $a = '2021-02-06T02:05:59.000+07:00';
        echo date('Y-m-d h:i:sa',strtotime($a));
    }
}

/* End of file Withdrawad.php */
