<?php
class ModelJson
{
    // json 文件存放路径
    public $staticPath =  "/home/wwwroot/crazy_god_CMS/public/game/config/";
    public function __construct(){
    }

    public function SaveJson($fileType, $data){
        $filename = $fileType . time() . '.json';
        $dir = $this->staticPath;
        $filepath = "{$dir}{$filename}";
        if (!is_dir($dir) || !is_writeable($filepath)) {
//            return false;
            $old = umask(0);
            //mkdir($dir, PRODUCTION_SERVER ? 0775 : 0777, true);
            mkdir($dir,0775 , true);
            umask($old);
        }
        $data = json_decode(json_encode($data,JSON_NUMERIC_CHECK), true);
        $ret = file_put_contents($filepath, json_encode($data,JSON_UNESCAPED_UNICODE));
        if($ret){
            oo::commonOprModel("config")->setStaticConfig($fileType, $filename);
        }
        return $ret;
    }



}
