<?php
/**
 * 第三方订单管理
 * @Copyright (C) 2018 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author xiaogg <xiaogg@sina.cn>
 */
namespace Common\Vendor;
class Threeorder{
    public $class;
    public $class_name;
    /**
     * 构造方法，用于实例化一个处理对象
     * @param string $classname 要使用的类库
     */
    public function __construct($classname = 'Jddj'){
        $classname=ucfirst($classname);
        /* 引入处理库 */
        $classfullname  =    "Common\\Vendor\\Threeorder\\".$classname;
        $config=array();
        $this->class_name=$classname;
        if(class_exists($classfullname))$this->class = new $classfullname($config);
    }
    public function __call($method,$data) {
        if (method_exists($this, $method)) {
            return call_user_func_array(array(&$this, $method), $data);
        }else if(method_exists($this->class,$method))return call_user_func_array(array(&$this->class, $method), $data);
    }    
    public function format_param($param){
        if(empty($param))return false;
        if(!is_array($param))$param=json_decode($param,1);
        foreach($param as $k=>$v){
            if($v && !is_array($v))$v=urldecode($v);
            if($v && !is_array($v) && (str_exists($v,'&quot;') || substr($v,0,1)=='{')){
                $param[$k]=json_decode(htmlspecialchars_decode($v),1);
            }
        }return $param;
    }
    //读写配置文件缓存
    public function orderconfig($name,$value=''){
        if(empty($name))return false;
        static $old = array();
        if(!empty($old[$name]) && empty($value)){return $old[$name];}
        $filename=ROOT_PATH.'/threeorder/'.strtolower($this->class_name).'_'.$name.'.php';
        if(file_exists($filename)){
            $content=oaofile($filename);
            $content=strtr($content,array('<?php return;//'=>'','?>'=>''));
            $old[$name]= json_decode($content,1);
        }
        if($value){
            if($old[$name])foreach($value as $k=>$v){$old[$name][$k]=$v;}
            else $old[$name]=$value;
            $con = "<?php return;//".json_encode($old[$name])."?>";
            oaofile($filename, $con);return $old[$name];
        }else{return $old[$name];}
   }
   private function ajaxReturn($return){
       echo json_encode($return);exit;
   }
}