<?php
defined('IN_WEB') or die('Include Error!');
/**
 * 获取在线相关
 */
class Pet
{
    /**
     * 宠物列表
     * @param $param
     * @return string
     * Created by: owen
     * Created on: 2020/2/5 20:58
     */
    public function getPetList($param){
        $uid = oo::functions()->uint($param['uid']);
        if(empty($uid)){
            return oo::response(-1);
        }
        $petList = oo::commonOprModel('pet')->getUserPet($uid);
        $freeFeedStatus = oo::commonOprRedis('common')->ttl(okeys::FreeFeedPet($uid));
        $data = [
            'freeFeedStatus' => time() + max($freeFeedStatus,0),
            'list' => $petList
        ];
        return oo::response(1,$data,"",true);
    }

    /**
     * 免费喂食
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2020/3/10 20:24
     */
    public function freeFeed($param){
        $uid = oo::functions()->uint($param['uid']);
        $petId = oo::functions()->uint($param['petId']);
        if(empty($uid) || empty($petId)){
            return oo::response(-1);
        }
       return oo::commonOprModel('pet')->freeFeedPet($uid,$petId);
    }

    /**
     * 孵化宠物
     * @param $param
     * @return string
     * Created by: owen
     * Created on: 2020/2/5 20:58
     */
    public function incubatePet($param){
        $uid   = oo::functions()->uint($param['uid']);
        $petId = oo::functions()->uint($param['petId']);
        if(empty($uid) || empty($petId)){
            return oo::response(-1);
        }
        $petList = oo::commonOprModel('pet')->incubatePet($uid,$petId);
        if($petList['code']==1){
            return oo::response(1,$petList['data'],"",true);
        }else{
            return oo::response($petList['code'],[],$petList['msg'],true);
        }
    }

    /**
     * 激活宠物
     * @param $param
     * @return string
     * Created by: owen
     * Created on: 2020/2/5 20:58
     */
    public function activatePet($param){
        $uid = oo::functions()->uint($param['uid']);
        $petId = oo::functions()->uint($param['petId']);
        if(empty($uid) || empty($petId)){
            return oo::response(-1);
        }
        return oo::commonOprModel('pet')->activatePet($uid,$petId);
    }

    /**
     * 宠物升级
     * @param $param
     * @return string
     * Created by: owen
     * Created on: 2020/2/5 21:00
     */
    public function upLevelUserPet($param){
        $uid = oo::functions()->uint($param['uid']);
        $petId = oo::functions()->uint($param['petId']);
        if(empty($uid) || empty($petId)){
            return oo::response(-1);
        }
        oo::commonOprModel('pet')->upLevelUserPet($uid,$petId);
        return oo::response(1,[],"",true);
    }

    /**
     * 喂养宠物粮食
     * @param $param
     * @return string
     * Created by: owen
     * Created on: 2020/2/5 21:01
     */
    public function feedPet($param){
        $uid = oo::functions()->uint($param['uid']);
        $petId = oo::functions()->uint($param['petId']);
        return oo::commonOprModel('props')->useUserProps($uid, 9,1,['petId'=>$petId]);
    }
    /**
     * 喂养宠物经验
     * @param $param
     * @return string
     * Created by: owen
     * Created on: 2020/2/5 21:01
     */
    public function feedPetExp($param){
        $uid = oo::functions()->uint($param['uid']);
        $petId = oo::functions()->uint($param['petId']);
        return oo::commonOprModel('props')->useUserProps($uid, 8,100,['petId'=>$petId]);
    }
}