<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
header("Content-type: text/html; charset=gb2312");
/**
 * ajax Class
 *
 * ajax管理
 *
 * @package     zsb
 * @subpackage      Controllers
 * @category        Controllers
 * @author      sun
 */
class outapi extends MY_Controller {


   /* function __construct()
    {
        pare
        header('Access-Control-Allow-Origin: *');
        header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');

    }*/

    function __construct($type = NULL)
    {
        parent::__construct($type);
        header('Access-Control-Allow-Origin: *');
        header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');
    }

    /**
     * Notes: vr申请剩余套数显示
     * User: zhangkg
     */
    public function weekVrData(){
        $this->load->model('sell_real_model');
        //计算申请VR时拍摄时间，当前时间下 延后7天
        $week_array = $this->sell_real_model->getWeekVrData();
        $week_array = $this->transcoding_sec($week_array);
        echo json_encode($week_array);
    }


    public function check_vr(){

        $this->load->model('sell_model');
        $rowid = $this->input->post( 'rowid' , TRUE );
        if( intval($rowid) > 0 ) {
            $post = $this->input->post();
            //初始化房源操作类
            $this->load->model('sell_model');
            $vra = $this->sell_model->check_vr($post);
            $vra = $this->transcoding($vra);
            echo json_encode($vra);
            die;

        }
        $result['code'] = 0;
        $result['msg'] = '参数错误';
        $result = $this->transcoding($result);
        echo json_encode($result);
        die;
    }


    function vrapplay(){
        $rowid = $this->input->post( 'rowid' , TRUE );
        $data = $this->input->post();
        //验证房源编号和提交验证码
        if( intval($rowid) > 0 ) {
            //初始化房源操作类
            $this->load->model('sell_model');
            $vra = $this->sell_model->vrApplay($data);
            $vra = $this->transcoding($vra);
            echo json_encode($vra);
            die;
        }
        $result['code'] = 0;
        $result['msg'] = '参数错误';
        $result = $this->transcoding($result);

        echo json_encode($result);
        die;
    }

    public function check_bind(){
        $rowid = $this->input->post( 'rowid' , TRUE );
        if( intval($rowid) > 0 ) {
            $post = $this->input->post();
            //初始化房源操作类
            $this->load->model('sell_model');
            $vra = $this->sell_model->check_bind($post);
            $vra = $this->transcoding($vra);
            echo json_encode($vra);
            die;

        }
        $result['code'] = 0;
        $result['msg'] = '参数错误';
        $result = $this->transcoding($result);

        echo json_encode($result);
        die;
    }


    /**
     * Notes:一维数组转码
     * User: zhangkg
     */
    public function transcoding($array){

        $newarray = array();
        foreach ($array as $key=>$val){
            $newarray[$key]  = iconv('gbk','utf8//IGNORE',$val);
        }
        return $newarray;
    }

    /**
     * Notes:二维数组转码
     * User: zhangkg
     */
    public function transcoding_sec($array){

        $newarray = array();
        foreach ($array as $key=>$val){

            foreach ($val as $k=>$v){
                $val[$k] = iconv('gbk','utf8//IGNORE',$v);
            }
            $newarray[$key] = $val;
        }
        return $newarray;
    }



}