<?php
defined('IN_WEB') or die('Include Error!');
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/3/20
 * Time: 14:41
 */
class Vip
{

    /**
     * 获取vip配置
     */
    public function getConfig()
    {
        $config = oo::commonOprModel('vip')->getVipConfig();
        return $config;
    }


    /**
     * 购买vip
     * @return string
     */
    public function buy($param)
    {
        $uid = intval($param['uid']);
        $type = intval($param['type']);
        if(empty($uid) || empty($type)) {
            return oo::response(-1, '参数错误');
        }
        $data = oo::commonOprModel('vip')->buy($uid, $type);
        return $data;
    }

    /**
     * 查询vip信息
     * @param $param
     * @return string
     */
    public function getVip($param)
    {
        $uid = intval($param['uid']);
        if(empty($uid)) {
            return oo::response(-1, '参数错误');
        }
        $data = oo::commonOprModel('vip')->getVip($uid);
        return json_encode($data);
    }


    public function updateBankPasswd($param)
    {
        $uid = intval($param['uid']);
        $passwd = oo::functions()->escape($param['passwd']);
        $email = oo::functions()->escape($param['email']);
        $data = oo::commonOprModel('vip')->updateBankPasswd($uid, $passwd, $email);
        return $data;
    }

    /**
     * 校验密码是否正确
     * @param $param
     * @return mixed
     */
    public function checkPasswd($param)
    {
        $uid = oo::functions()->uint($param['uid']);
        $passwd =  oo::functions()->escape($param['passwd']);
        $data = oo::commonOprModel('vip')->checkPasswd($uid, $passwd);
        return json_encode($data);
    }

    /**
     * @param $param
     * @return string
     */
    public function forgetPasswd($param)
    {
        $uid = oo::functions()->uint($param['uid']);
        $passwd =  oo::functions()->escape($param['passwd']);
        $lang = oo::functions()->escape($param['lang']) ?? 'en';
        $data = oo::commonOprModel('vip')->forgetPasswd($uid, $passwd, $lang);
        return json_encode($data);
    }

    /**
     * 绑定邮箱
     * @param $param
     * @return string
     */
    public function bindEmail($param)
    {
        $uid = oo::functions()->uint($param['uid']);
        $email = oo::functions()->escape($param['email']);
        $data = oo::commonOprModel('vip')->bindEmail($uid, $email);
        return json_encode($data);
    }


    /**
     * vip用户头像列表
     * @return mixed
     */
    public function vipUserIconList()
    {
        $data = oo::commonOprModel('vip')->vipUserIconList();
        return $data;
    }

    /**
     * 保险箱存取钱
     * @param $param
     * @return string
     */
    public function storeMoney($param)
    {
        $uid = intval($param['uid']);
        $money = $param['money'];
        $state = $param['state'];
        if(empty($uid) || empty($money) || !in_array($state, [1,2])) {
            return oo::response(-1, '参数错误');
        }
        $data = oo::commonOprModel('vip')->storeMoney($uid, $money, $state);
        return $data;
    }


    /**
     * 使用道具和表情
     * @param $param
     * @return string
     */
    public function useExpression($param)
    {
        $type = $param['type'];
        $uid = intval($param['uid']);
        $data = oo::commonOprModel('vip')->usePropsExpression($uid, $type);
        return $data;
    }


    public function experienceVip($param){
        $uid = oo::functions()->uint($param['uid']);
        $ret = oo::commonOprModel('newvip')->setExperienceVip($uid,3*24*60*60);
//        $ret = oo::commonOprModel('newvip')->setExperienceVip($uid,60);
        if($ret){
            return oo::response(1,$ret,"",true);
        }
        return oo::response(-1);
    }
}