<?php
/**
 * 宠物相关
 */
defined( 'IN_WEB') or die( 'Include Error!');

class Pet
{
    public function getPetConfig(){
        $ret = oo::commonOprModel('pet')->getPetConfig(0,true);
        return json_encode($ret,32);
    }

    public function getPetExpConfig(){
        $ret = oo::commonOprModel('pet')->getPetExpConfig();
        return json_encode($ret);
    }

    public function savePetConfig($param){
        $data = json_decode($param['data'],true);
        foreach ($data as $row){
            oo::commonOprModel('pet')->savePetConfig($row);
        }
        if(!empty($param['filename'])){
            $filename = $param['filename'];
            $tb = otable::StaticConfig();
            $sql = "UPDATE {$tb} SET path='{$filename}' WHERE config='PetConfig'";
            oo::commonOprDb('common')->query($sql);
            oo::commonOprRedis('common')->hSet(okeys::StaticConfig(),'PetConfig',$filename);
        }
        return 1;
    }

    public function savePetExpConfig($param){
        $data = json_decode($param['data'],true);
        oo::commonOprModel('pet')->savePetExpConfig($data);
        return 1;
    }
}
