<?php
defined('IN_WEB') or die('Include Error!');
/**
 * 用户相关
 */
class User
{
    private  $response = ['code'=>-1,'msg'=>'','data'=>[]];
    /**
     * 修改用户 昵称 描述文字
     * @param unknown $param
     * @return number
     */
    public function modifyInfo($param) {
        $uid = oo::functions()->uint($param['uid']);
        if (!$uid) {
            return 0;
        }
        $updateInfo = array();
        //更改昵称
        $nick = isset($param['nick']) ? htmlspecialchars($_POST['nick']) : '';
        if (!empty($nick)) {
            $code = mb_detect_encoding($nick);

            if (strtolower($code) != 'utf-8') {
                $nick = mb_convert_encoding($nick, 'UTF-8');
            }
            if (mb_strlen($nick) > 127) { // 留一位做全是单音节以.结束
                $nick = mb_substr($nick, 0, 127);
            }
            $nick = oo::functions()->escapeNick($nick);
            $updateInfo['nick'] = addslashes($nick);
        }
        //更改签名
        $signature = isset($param['signature']) ? htmlspecialchars($_POST['signature']) : '';
        if (!empty($signature)) {
            $code = mb_detect_encoding($nick);

            if (strtolower($code) != 'utf-8') {
                $signature = mb_convert_encoding($signature, 'UTF-8');
            }
            $updateInfo['signature'] = addslashes($signature);
        }
        //更改旗帜
        $u_flag = isset($param['u_flag']) ? htmlspecialchars($_POST['u_flag']) : '';
        if (!empty($u_flag)) {

            $f_id = oo::functions()->uint($u_flag);
            if($f_id && $f_id>0){
                $updateInfo['u_flag'] = (int)$f_id;
            }

        }
        //更改性别
        $sex = isset($param['sex']) ? htmlspecialchars($_POST['sex']) : '';
        if (!empty($sex)) {
            if(in_array($sex,['f','m'])){
                $updateInfo['sex'] = $sex;
            }

        }
        //更改头像
        $s_picture = isset($param['s_picture']) ? htmlspecialchars($_POST['s_picture']) : '';
        if (!empty($s_picture)) {
            if(is_numeric($s_picture)){
                $picture_id = oo::functions()->uint($s_picture);
                if($picture_id && $picture_id>0){
                    $updateInfo['s_picture'] = (int)$picture_id;
                }
            }else{
                $preg = "/^http(s)?:\\/\\/.+/";
                if(preg_match($preg,$s_picture))
                {
                    $updateInfo['s_picture'] = $s_picture;
                }
            }
        }
      
      	//更改头像框
        $updateInfo['avatar'] = isset($param['avatar']) ? intval($_POST['avatar']) :0;
      
        $result = oo::commonOprModel('member')->updateUserInfo($uid, $updateInfo);
        if($result){
            $data = ['code'=>1,'msg'=>'修改成功','data'=>oo::commonOprModel('user')->showUserInfo($uid)];
        }else{
            $data = ['code'=>-1,'msg'=>'修改失败','data'=>oo::commonOprModel('user')->showUserInfo($uid)];
        }
        return json_encode($data);
    }

    /**
     *	设置LINE号
     */
    public function setLine($param)
    {
        $data = array('code' => -1);
        $lineaccount = oo::functions()->escape($param['lineaccount']);//Line账号
        $uid = oo::functions()->uint($param['uid']);//账号UID
        if( empty($lineaccount) || empty($uid) ){
            return json_encode($data);
        }
        $data = oo::commonOprModel('member')->setLine($uid, $lineaccount);
        return json_encode($data);
    }

    /**
     *	查看玩家信息
     * $param  uid   必须
     */
    public function showUserInfo($param)
    {
        if(empty($param['uid'])){
            return false;
        }
        $uid = $param['uid'];
        $data = oo::commonOprModel('user')->showUserInfo($uid);
        $this->response['data'] = $data;
        $this->response['code'] = 1;
        if(empty($data)){
            $this->response['code'] = -1;

            return json_encode($this->response);

        }
        return json_encode($this->response);
    }

    /**
     *	获取我的支付记录(历史订单)
     */
    public function getMyOrderList($param)
    {
        $data = oo::commonOprModel('user')->getMyOrderList($param);
        return json_encode($data);
    }

    /**
     *	记录token, 推送需要使用token
     */
    public function pushToken($param)
    {
        $data = oo::commonOprModel('user')->recordPushToken($param);
        return $data;
    }

    /**
     *	给单个玩家发送推送
     */
    public function pushMsgToOneUser($param)
    {
        $data = array('code' => -1);
        $touid = oo::functions()->uint($param['touid']);
        $title = $param['title'];//推送标题
        $msg = $param['msg'];//推送内容
        $argument = $param['param'];//推送参数
        if( empty($touid) || empty($title) || empty($msg) ){
            return json_encode($data);
        }
        $arg = json_decode($argument, 1);
        $ret = oo::commonOprModel('push')->pushNewsToOne($touid, $title, $msg, $arg);
        $data['code'] = 1;
        $data['ret'] = $ret;
        return json_encode($data);
    }


    /**
     * VK绑定领奖
     * @param $param
     * @return string
     */
    public function visitorBindRwd($param)
    {
        $uid = oo::functions()->uint($param['uid']);
        $data = oo::commonOprModel('user')->visitorBindRwd($uid);
        return json_encode($data);
    }





    /**
     * 刷新体力接口 - 请求使用
     */
    public function refreshSpins($param){
        $uid = oo::functions()->uint($param['uid']);
        $data = array('code' => -1);
        if( empty($uid)  ){
            return json_encode($data);
        }
        $dataInfo = oo::commonOprModel('user')->refreshSpins($uid);
        return json_encode($dataInfo);
    }

    /**
     * Notes: 获取仇人列表
     * User: wsc
     * Time: 2020/4/2 14:43
     * @param $param
     * @return false|string
     */
    public function getEnemyList($param){
        $uid = oo::functions()->uint($param['uid']);
        if( empty($uid)  ){
            $data = array('code' => -1,'desc'=>'参数错误！');
            return json_encode($data);
        }
        $enemyList   = oo::commonOprModel('member')->getDefaultEnemyList($uid);//过滤后的仇人列表
        $myEnemyList = oo::commonOprModel('member')->getMyEnemyList($uid);
        $enemyList = array_values($enemyList);
        foreach ($enemyList as $k => $v){
            $listInfo[$k] = oo::commonOprModel('member')->getUserBasic($v);
            !empty($myEnemyList)&&in_array($v,$myEnemyList)?$listInfo[$k]['type']=2:$listInfo[$k]['type'] =1;
        }
        $resop = array('code'=>1,'desc'=>'获取成功','data'=>array_values($listInfo));
        return json_encode($resop);
    }
    /**
     * 获取仇人列表
     * $uid  当前用户uid  wsc-4.2(废弃)
     */
    public function getEnemyListold($param){
        $uid = oo::functions()->uint($param['uid']);
        if( empty($uid)  ){
            $data = array('code' => -1,'desc'=>'参数错误！');
            return json_encode($data);
        }
        $temp_list = oo::commonOprRedis('common')->get(okeys::EnemyList($uid));
        $temp_list = json_decode($temp_list,true);
        $list      = $temp_list['list_info'];
        $game_list = $temp_list['game_list'];
        $enemyList = oo::commonOprRedis('common')->hGetAll(okeys::EnemyID($uid));
        asort($enemyList);
        $i = 0;
//        $tb = otable::userlevel();
        $createtime = time() - 3*24*60*60;
        $attackProtectionTime = time();
        foreach ($enemyList as $key=>$value){
            if($i>=20){
                break;
            }
            if(empty($game_list) || in_array($key,$game_list) || $key == $uid){
                continue;
            }

//            $sql = "SELECT * FROM {$tb} WHERE uid ={$key} LIMIT 1";
//            $ret = oo::commonOprDb('userlevel')->getOne($sql,MYSQLI_ASSOC);
            $ret = oo::commonOprModel('member')->getUserLevel_orig($uid);
            if(empty($ret) || $ret['levelId'] <=2 || $ret['total'] == 0 || $ret['createtime'] >$createtime || $ret['attackedNum'] >15 || $ret['attackProtectionTime'] > $attackProtectionTime){
                continue;
            }

            $temp = oo::commonOprModel('member')->getUserLevel($key);
            $temp['uid'] = $key;
            $temp['total_level'] = $ret['total'];
            $temp['type'] = 2;
            $list[] = $temp;
            $i++;
        }
        $listInfo = [];
        $userList = [];
        foreach($list as $k=>$v){
            if(in_array($v['uid'],$userList)){
                continue;
            }
            $temp_array = oo::commonOprModel('member')->getUserAssetsInfo($v['uid']);
            $temp_info = oo::commonOprModel('member')->getUserInfo($v['uid']);
            if(empty($temp_info)){
                continue;
            }else{
                $userList[] = $v['uid'];
            }
            $listInfo[$k]['type'] = $v['type'];
            $listInfo[$k]['uid'] = intval($v['uid']);
            $listInfo[$k]['nick'] = $temp_info['nick'];
            $listInfo[$k]['s_picture'] = $temp_info['s_picture'];
            $listInfo[$k]['star'] = $temp_array['star'];
            $listInfo[$k]['coins'] = intval($temp_array['money']);
            $listInfo[$k]['u_flag'] = intval($temp_info['u_flag']);
          	$listInfo[$k]['vip'] = $temp_info['vip'];
          	$listInfo[$k]['vipLv'] = $temp_info['vipLv'];
          	$listInfo[$k]['vipExpire'] = $temp_info['vip_expire'];
          	$listInfo[$k]['avatar'] = intval($temp_info['avatar']);
        }
        $resop = array('code'=>1,'desc'=>'获取成功','data'=>array_values($listInfo));
        return json_encode($resop);
    }

    //查看消息列表
    public function showMessageList($param){
        $uid = oo::functions()->uint($param['uid']);
        if( empty($uid)  ){
            $data = array('code' => -1,'desc'=>'参数错误！');
            return json_encode($data);
        }
        $data = oo::commonOprModel('message')->getMessageList($uid);
        return json_encode($data,JSON_NUMERIC_CHECK);
    }



//    --------------------------------------------------------------------------------------------------------------------

    /**
     * 获取当前等级对应的配置
     * @param $param
     * @return false|string
     * Created by: Cassie Lee
     * Created on: 2019/6/10 19:54
     * Description:
     */
    public function getConfig($param){
        $uid = oo::functions()->uint($param['uid']);
        if(empty($uid)){
            return json_encode(['code'=>-1],JSON_NUMERIC_CHECK);
        }
        $data  = oo::commonOprModel('member')->getUserConfig($uid);
        return json_encode([
            'code'=>1,
            'data'=>$data
        ]);
    }

    /**
     * 触发偷取对象
     * @param $param
     * @return false|string
     * Created by: Owen
     * Created on: 2019/6/12 11:39
     * Description:
     */
    public function getRichestKing($param){
        $uid = oo::functions()->uint($param['uid']);
        if(empty($uid)){
            return json_encode(['code'=>-1, 'msg'=>'uid empty']);
        }
        return oo::commonOprModel('user')->getRichestKing($uid);
    }

    /**
     * 获取财产
     * @param $param
     * @return false|string
     * Created by: Owen
     * Created on: 2019/6/19 15:17
     * Description:
     */
    public function getMoney($param){
        $uid = oo::functions()->uint($param['uid']);
        if(empty($uid)){
            return json_encode([
                'code'=>-1,
                'msg'=>'uid empty'
            ]);
        }
        $userInfo = oo::commonOprModel('member')->getUserAssetsInfo($uid);
        return json_encode([
            'code'=>1,
            'data'=>$userInfo
        ]);
    }

    public function getNewLevel($param){
        $uid = oo::functions()->uint($param['uid']);
        if(empty($uid)){
            return json_encode([
                'code'=>-1,
                'msg'=>'uid empty'
            ]);
        }
        $config  = oo::commonOprModel('member')->getUserConfig($uid);
        $LandData = oo::commonOprModel('level')->getLandDatas($uid);
        return json_encode([
            'code'=>1,
            'data'=>[
                'config'=>$config,
                'LandData'=>$LandData
            ]
        ]);
    }

    public function adreward($param){
        $uid  = oo::functions()->uint($param['uid']);
        $time = oo::functions()->uint($param['time']);
        $type = oo::functions()->escape($param['type']);
        $num  = oo::functions()->uint($param['num']);
        $sign = oo::functions()->escape($param['sign']);
        if(empty($uid) || empty($time) || empty($type) || empty($num) || empty($sign) || $num<=0){
            return json_encode(['code'=>-1]);
        }
        $data['code'] = 1;
        $serverSign = base64_encode(md5("$2019$".$uid.'TIME'.$time."TYPE".$type."NUM".$num."_SUPERANT"));
        if($serverSign != $sign){
            return json_encode(['code'=>-2],JSON_NUMERIC_CHECK);
        }

        $ad = oo::commonOprRedis('common')->hGetAll(okeys::Adreward($uid));
        if(!empty($ad) && $ad['time'] == date('Y-m-d')){
            if(isset($ad[$type])){
                $adHistroy = json_decode($ad[$type],true);
                $times = oo::commonOprModel('readconfig')->getCon('adReward',$type."Times"); //限制
                if(count($adHistroy) == $times){
                    return json_encode(['code'=>-3]);
                }
                foreach ($adHistroy as $row){
                    if($row['sign'] == $serverSign){
                        return json_encode(['code'=>-4]);
                    }
                }
            }else{
                $adHistroy = [];
            }
        }
        $serverNum = oo::commonOprModel('readconfig')->getCon('adReward',"reward".ucfirst($type)); //数量
        $num = intval($num);
        if($serverNum != $num){
            return json_encode(['code'=>-5]);
        }
      	
      	if($type == 'spins'){
            $id = 8;
        }else if($type == 'coins'){
            $id = 9;
        }
        $ret = oo::commonOprModel('advertisement')->getRemainCount($uid,$id);
        if(empty($ret)){
            return oo::response(-5,[],'广告未开启');
        }
        if($ret['remain']<=0){
            return oo::response(-5,[],'次数不足');
        }
      
      
        if($type == 'spins'){
            oo::commonOprModel('member')->optProperty($uid,['spins'=>$num],'+',108,'广告获得体力');
           	oo::commonOprModel('advertisement')->addCount($uid,8);
            $data['data']=['spins'=>$num];
        }else if($type == 'coins'){
            oo::commonOprModel('member')->optProperty($uid,['money'=>$num],'+',108,'广告获得金币');
          	oo::commonOprModel('advertisement')->addCount($uid,9);
            $data['data']=['money'=>$num];
        }else{
            return json_encode(['code'=>-6]);
        }

        if(empty($ad) || $ad['time'] != date('Y-m-d')){
            oo::commonOprRedis('common')->hSet(okeys::Adreward($uid),'time',date('Y-m-d'));
            oo::commonOprRedis('common')->hSet(okeys::Adreward($uid),$type,json_encode([['time'=>time(),'sign'=>$serverSign]]));
        }else{
            array_push($adHistroy,['time'=>time(),'sign'=>$serverSign]);
            oo::commonOprRedis('common')->hSet(okeys::Adreward($uid),$type,json_encode($adHistroy));
        }
        return json_encode($data);
    }

    public function beginGuide($param){
        $uid = oo::functions()->uint($param['uid']);
        $stage = oo::functions()->uint($param['stage']);
        $redisStage = oo::commonOprRedis('common')->hGet(okeys::beginGuide(),$uid);
        if($stage > 18){
            return json_encode(['code'=>-1,'msg'=>'stage error']);
        }

        $tb = otable::gh_gameserver($uid);
        $sql = "SELECT beginGuide FROM {$tb} WHERE mid={$uid} LIMIT 1";
        $ret = oo::commonOprDb('ghgames')->getOne($sql,1);
        if($ret['beginGuide'] >= 19){
            return json_encode(['code'=>-1]);
        }

        $out = ['code'=>1,'data'=>[]];
        $sql = "UPDATE {$tb} SET beginGuide = {$stage} WHERE mid = {$uid} LIMIT 1";
        oo::commonOprDb('ghgames')->query($sql);
        if($redisStage<$stage){
            oo::commonOprModel('member')->optProperty($uid,['spins'=>1],'-',101,"新手引导");
            oo::commonOprRedis('common')->hSet(okeys::beginGuide(),$uid,$stage);
            switch ($stage){
                case 1:
//                    $money = 0;
//                    oo::commonOprModel('member')->optPropertySet($uid,['money'=>$money],"新手引导");
                    oo::commonOprModel('member')->optProperty($uid,['money'=>10000],'+',101,"新手引导");
                    break;
                case 2:
                    oo::commonOprModel('member')->optProperty($uid,['money'=>80000],'+',101,"新手引导");
                    break;
                case 3:
                    oo::commonOprModel('member')->optProperty($uid, ['money' => 20000], '+',101, "新手引导");
                    break;
                case 4:
                    oo::commonOprModel('member')->optProperty($uid, ['money' => 150000], '+',101, "新手引导");
//                    oo::commonOprModel('member')->saveStatisticsByArray($uid, [
//                        'coinbya' => 150000,
//                        'damage' => 1
//                    ]);
                    break;
                case 5:
                    oo::commonOprModel('member')->optProperty($uid, ['money' => 5000], '+', 101,"新手引导");
                    break;
                case 6:
                    oo::commonOprModel('member')->optProperty($uid, ['money' => 290000], '+',101, "新手引导");
//                    oo::commonOprModel('member')->saveStatisticsByArray($uid, [
//                        'allstealnum' => 1,
//                        'stealnum' => 1,
//                        'stealcoin' => 290000,
//                    ]);
                    break;
                case 7:
                    oo::commonOprModel('member')->optProperty($uid,['money'=>2000],'+',101,"新手引导");
                    break;
                case 8:
                    oo::commonOprModel('member')->optProperty($uid,['money'=>2000],'+',101,"新手引导");
                    oo::commonOprModel('member')->optProperty($uid,['spins'=>10],'+',101,"新手引导");
                    break;
                case 9:
                    oo::commonOprModel('member')->optProperty($uid,['money'=>80000],'+',101,"新手引导");
//                    oo::commonOprModel('member')->saveStatistics($uid,'damaged',1);
                    // 破壞建築
                    $tb  = otable::userlevel($uid);
                    $sql = "SELECT * FROM {$tb} WHERE levelId=(SELECT Max(levelId) as levelId FROM {$tb} WHERE uid={$uid}) AND uid={$uid}";
                    $ret = oo::commonOprDb('userlevel')->getOne($sql,MYSQLI_ASSOC);
                    $levelId = $ret['levelId'];
                    $element = json_decode($ret['element'],true);
                    foreach ($element as $key=>$row){
                        if($row['level']>0 && $row['status'] == 0){
                            $element[$key]['status'] = 1;
                            break;
                        }else if($row['level']>0 && $row['status'] == 1){
                            $element[$key]['status'] = 0;
                            $element[$key]['level'] = $element[$key]['level'] - 1;
                        }
                    }
                    oo::commonOprModel('member')->setUserLevel($uid,$levelId,$element);
                    break;
                case 10:
                    oo::commonOprModel('member')->optProperty($uid,['money'=>1000],'+',101,"新手引导");
                    break;
                case 11:
                    oo::commonOprModel('member')->optProperty($uid,['money'=>150000],'+',101,"新手引导");
//                    oo::commonOprModel('member')->saveStatisticsByArray($uid,[
//                        'coinbya' => 150000,
//                        'damage'  => 1
//                    ]);
                    break;
                case 12:
                    oo::commonOprModel('member')->optProperty($uid,['money'=>20000],'+',101,"新手引导");
                    break;
                case 13:
                    oo::commonOprModel('member')->optProperty($uid,['money'=>5000],'+',101,"新手引导");
                    break;
                case 14:
                    oo::commonOprModel('member')->optProperty($uid,['shield'=>1],'+',101,"新手引导");
                    oo::commonOprModel('member')->optProperty($uid,['money'=>50000],'+',101,"新手引导");
                    break;
                case 15:
                    oo::commonOprModel('member')->optProperty($uid,['money'=>80000],'+',101,"新手引导");
                    break;
                case 16:
                    oo::commonOprModel('member')->optProperty($uid,['money'=>1000],'+',101,"新手引导");
                    break;
                case 17:
                    oo::commonOprModel('member')->optProperty($uid,['money'=>2000],'+',101,"新手引导");
                    break;
                case 18:
                    oo::commonOprModel('member')->optProperty($uid,['money'=>5000],'+',101,"新手引导");
                    break;
            }
        }
        switch ($stage){
            case 1:
                $out['data'] = ['type'=>1, 'rid'=>5, 'rewardId'=>1, 'num'=>10000, 'curSpins'=>7];
                break;
            case 2:
                $out['data'] = ['type'=>1, 'rid'=>5, 'rewardId'=>6, 'num'=>80000, 'curSpins'=>6];
                break;
            case 3:
                $out['data'] = ['type'=>1, 'rid'=>9, 'rewardId'=>5, 'num'=>20000, 'curSpins'=>5];
                break;
            case 4:
                $out['data'] = ['rid'=>1, 'type'=>4,
                    'attackInfo'=>[
                        'levelId'=>1,
                        'element'=>[
                            ['id'=>1,'level'=>5,'maxLevel'=>5,'status'=>0],
                            ['id'=>2,'level'=>5,'maxLevel'=>5,'status'=>0],
                            ['id'=>3,'level'=>4,'maxLevel'=>5,'status'=>0],
                            ['id'=>4,'level'=>1,'maxLevel'=>3,'status'=>0],
                            ['id'=>5,'level'=>3,'maxLevel'=>5,'status'=>0],
                        ],
                        'createTime'=>time(), 'completionTime'=>null, 'is_reward'=>0, 'toUid'=>10000, 'guideCoins'=>150000, 'nick'=>"King", 's_picture'=>1,
                    ],
                    'lastTime'=>null, 'curSpins'=>4,
                ];
                break;
            case 5:
                $out['data'] = ['type'=>1, 'rid'=>8, 'rewardId'=>4, 'num'=>5000, 'curSpins'=>3];
                break;
            case 6:
                $out['data'] = ['rid'=>2, 'type'=>3,
                    'stealInfo'=>[
                        'levelId'=>1,
                        'element'=>[
                            ['id'=>1,'level'=>5,'maxLevel'=>5,'status'=>0],
                            ['id'=>2,'level'=>5,'maxLevel'=>5,'status'=>0],
                            ['id'=>3,'level'=>4,'maxLevel'=>5,'status'=>0],
                            ['id'=>4,'level'=>1,'maxLevel'=>3,'status'=>0],
                            ['id'=>5,'level'=>3,'maxLevel'=>5,'status'=>0],
                        ],
                        'createTime'=>time(), 'completionTime'=>null, 'is_reward'=>0, 'toUid'=>10000, 'coins'=>290000, 'nick'=>"King", 's_picture'=>1, 'u_flag'=>1, 'guideCoins'=>[174000,87000,29000]
                    ],
                    'lastTime'=>null, 'curSpins'=>2, 'coins'=>[174000,87000,29000]
                ];
                break;
            case 7:
                $out['data'] = ['type'=>1, 'rid'=>5, 'rewardId'=>1, 'num'=>2000, 'curSpins'=>1];
                break;
            case 8:
                $out['data'] = ['type'=>2, 'rid'=>3, 'num'=>10, 'curSpins'=>10, 'lastTime'=>null];
                break;
            case 9:
                $out['data'] = ['type'=>1, 'rid'=>5, 'rewardId'=>6, 'num'=>80000, 'curSpins'=>9];
                $userAssert = oo::commonOprModel('member')->getUserAssetsInfo($uid);
                oo::commonOprModel('Workerman')->push($uid,ocmd::$SVR_SELF_ATTACK_MESSAGE,array('nick'=>'KING','u_flag'=>1,'url'=>1,'shield'=>$userAssert['shield'],'isDefense'=>3,'star'=>100));
                break;
            case 10:
                $out['data'] = ['type'=>1, 'rid'=>5, 'rewardId'=>1, 'num'=>1000, 'curSpins'=>8];
                break;
            case 11:
                $out['data'] = ['rid'=>1, 'type'=>4, 'attackInfo'=>[
                    'levelId'=>1,
                    'element'=>[
                        ['id'=>1,'level'=>5,'maxLevel'=>5,'status'=>0],
                        ['id'=>2,'level'=>5,'maxLevel'=>5,'status'=>0],
                        ['id'=>3,'level'=>4,'maxLevel'=>5,'status'=>0],
                        ['id'=>4,'level'=>1,'maxLevel'=>3,'status'=>0],
                        ['id'=>5,'level'=>3,'maxLevel'=>5,'status'=>0],
                    ],
                    'createTime'=>time(), 'completionTime'=>null, 'is_reward'=>0, 'toUid'=>10001, 'guideCoins'=>150000, 'nick'=>"Queen", 's_picture'=>1,
                    'enemyInfo'=>[
                        'levelId'=>1,
                        'element'=>[
                            ['id'=>1,'level'=>5,'maxLevel'=>5,'status'=>0],
                            ['id'=>2,'level'=>5,'maxLevel'=>5,'status'=>0],
                            ['id'=>3,'level'=>4,'maxLevel'=>5,'status'=>0],
                            ['id'=>4,'level'=>5,'maxLevel'=>5,'status'=>0],
                            ['id'=>5,'level'=>4,'maxLevel'=>5,'status'=>0],
                        ],
                        'createTime'=>time(), 'completionTime'=>null, 'is_reward'=>0, 'guideCoins'=>10000, 'coins'=>150000, 'nick'=>"King", 's_picture'=>1,
                        ]
                    ],
                    'lastTime'=>null,
                    'curSpins'=>7,
                ];
                break;
            case 12:
                $out['data'] = ['type'=>1, 'rid'=>9, 'rewardId'=>5, 'num'=>20000, 'curSpins'=>6];
                break;
            case 13:
                $out['data'] = ['type'=>1, 'rid'=>8, 'rewardId'=>4, 'num'=>5000, 'curSpins'=>5];
                break;
            case 14:
                $out['data'] = ['type'=>5, 'rid'=>4, 'num'=>1, 'curSpins'=>4];
                break;
            case 15:
                $out['data'] = ['type'=>1, 'rid'=>5, 'rewardId'=>6, 'num'=>80000, 'curSpins'=>3];
                break;
            case 16:
                $out['data'] = ['type'=>1, 'rid'=>5, 'rewardId'=>1, 'num'=>1000, 'curSpins'=>2];
                break;
            case 17:
                $out['data'] = ['type'=>1, 'rid'=>5, 'rewardId'=>1, 'num'=>2000, 'curSpins'=>1];
                break;
            case 18:
                $out['data'] = ['type'=>1, 'rid'=>8, 'rewardId'=>4, 'num'=>5000, 'curSpins'=>0];
                break;
        }
        return json_encode($out);
    }

  	public function setGuide($param){
        $uid   = oo::functions()->uint($param['uid']);
        $stage = 18;
        $tb = otable::gh_gameserver($uid);
        $sql = "SELECT beginGuide FROM {$tb} WHERE mid={$uid} LIMIT 1";
        $ret = oo::commonOprDb('ghgames')->getOne($sql,1);
        if($ret['beginGuide'] >= 19){
            return oo::response(-1);
        }

        $sql = "UPDATE {$tb} SET beginGuide = {$stage} WHERE mid = {$uid} LIMIT 1";
        oo::commonOprDb('ghgames')->query($sql);
        oo::commonOprRedis('common')->hSet(okeys::beginGuide(),$uid,$stage);
        return oo::response(1);
    }
  
  
    /**
     * 结束新手引导
     * @param $param
     * @return false|string
     * Created by: Owen
     * Created on: 2019/8/29 15:15
     * Description:
     */
    public function endGuide($param){
        $uid = oo::functions()->uint($param['uid']);
        if(empty($uid)){
            return oo::response(-1);
        }
        $dump  = oo::functions()->escape($param['dump']);
        $build = $param['build'];
        return oo::response(-1);
        //return oo::commonOprModel('member')->endGuide2($uid,$build, $dump);
    }

    /**
     * 异常上报
     * @param $param
     * @return false|string
     * Created by: Owen
     * Created on: 2019/8/29 15:15
     * Description:
     */
    public function error($param){
        $uid = oo::functions()->uint($param['uid']);
        oo::logs()->debug4(['time'=>time(),'uid'=>$uid,'data'=>$param['data']],$uid.'.log','error/'.date("Ymd").'/');
        return json_encode(['code'=>1]);
    }

    /**
     * 用户统计
     * @param $param
     * @return false|string
     * Created by: Owen
     * Created on: 2019/8/29 15:14
     * Description:
     */
    public function getSatistics($param){
        $uid = oo::functions()->uint($param['uid']);
        if(empty($uid)){
            return oo::response(-1);
        }
        $data = [];
//        $statistics = oo::commonOprModel('member')->getStatistics($uid);
        $outputKey  = [
            'money'     =>"",
            'damage'    =>"",
            'destroy'   =>"",
            'coinbya'   =>"",
            'stealnum'  =>"",
            'allstealnum'=>"stealperfect",
            'stealcoin' =>"",
            'defense'   =>"",
            'damaged'   =>"",
            'destroyed' =>"",
            'stealed'   =>"",
        ];
//        foreach ($outputKey as $key=>$row){
//            (empty($row))?$data[$key] = $statistics[$key]:$data[$row] = $statistics[$key];
//        }
        return oo::response(1,$outputKey,"",true);
    }

    /**
     * 用户设置
     * @param $param
     * @return false|string
     * Created by: Owen
     * Created on: 2019/8/29 15:14
     * Description:
     */
    public function userSetting($param){
        $uid = oo::functions()->uint($param['uid']);
        $type = oo::functions()->escape($param['type']);
        $lock = oo::functions()->uint($param['lock']);// 0 默認開，1关
        if($type == 'ALL'){
            if($lock == 0){
                oo::commonOprRedis('common')->delete(okeys::UserSettingLock($uid));
            }else if($lock == 1){
                oo::commonOprRedis('common')->hSet(okeys::UserSettingLock($uid),'stealAndAttack',1);
                oo::commonOprRedis('common')->hSet(okeys::UserSettingLock($uid),'ALL',1);
            }
        }else{
            if($lock == 0){
                oo::commonOprRedis('common')->hDel(okeys::UserSettingLock($uid),$type);
            }else if($lock == 1){
                oo::commonOprRedis('common')->hSet(okeys::UserSettingLock($uid),$type,1);
            }
        }
        return json_encode(['code'=>1],JSON_NUMERIC_CHECK);
    }

    /**
     * 首冲状态
     * @param $param
     * @return false|string
     * Created by: Owen
     * Created on: 2019/7/10 17:39
     * Description:
     */
    public function firstPay($param){
        $uid = oo::functions()->uint($param['uid']);
        $firstPay = oo::commonOprModel('member')->getUserFirstPayStatus($uid);
        return json_encode(['code'=>1,'status'=>$firstPay],JSON_NUMERIC_CHECK);
    }

    /**
     * 机器人下线移除richestKing占位，真实玩家在socket断开移除
     * @param $param
     * Created by: Owen
     * Created on: 2019/7/17 13:49
     * Description:
     */
    public function deleteKing($param){
        $uid = oo::functions()->uint($param['uid']);
        // 触发发送偷取信息
        $RichestKing = oo::commonOprRedis('common')->get(okeys::richestKing($uid));
        if(!empty($RichestKing)){
            oo::commonOprRedis('common')->delete(okeys::richestKing($uid));
            oo::commonOprRedis('common')->sRemove(okeys::richestKingTo($RichestKing),$uid);
        }
    }

  	public function setDataToCloud($param){
        $uid = oo::functions()->uint($param['uid']);
        $KVDataList = $param['KVDataList'];
        $KVDataList = json_decode($KVDataList,true);
        $mSet = [];
        foreach ($KVDataList as $key=>$row){
            $mSet[$key] = json_encode($row);
        }
        oo::commonOprRedis('common')->hMset(okeys::UserCache($uid),$mSet);
        return oo::response(1);
    }

    public function getDataFromCloud($param){
        $uid = oo::functions()->uint($param['uid']);
        $key = $param['keys'];
        $key = json_decode($key,true);
        $ret = oo::commonOprRedis('common')->hMget(okeys::UserCache($uid),$key);
        foreach ($ret as $key=>$row){
            if(!$row){
                $ret[$key] = null;
            }else{
                $ret[$key] = json_decode($row);
            }
        }
        return oo::response(1,$ret??[]);
    }

    public function getAllDataFromCloud($param){
        $uid = oo::functions()->uint($param['uid']);
        $ret = oo::commonOprRedis('common')->hGetAll(okeys::UserCache($uid));
        foreach ($ret as $key=>$row){
            if(!$row){
                $ret[$key] = null;
            }else{
                $ret[$key] = json_decode($row);
            }
        }
        return oo::response(1,$ret??[]);
    }

    public function delDataFromCloud($param){
        $uid = oo::functions()->uint($param['uid']);
        $key = $param['keys'];
        $key = json_decode($key,true);
        foreach ($key as $row){
            oo::commonOprRedis('common')->hDel(okeys::UserCache($uid),$row);
        }
        return oo::response(1,$ret??[]);
    }
  
  	public function recall($param){
        $uid = oo::functions()->uint($param['uid']);
        if(empty($uid)){
            return oo::response(-1);
        }

        $recallData = oo::commonOprRedis('common')->get(okeys::recall($uid));
        if($recallData){
            $recallData = json_decode($recallData,true);
            $coins = oo::commonOprModel('goods')->getGoodCoins($uid,'coins01');
            $bet   = 0;
            $spins = 0;
            foreach ($recallData as $row){
                $bet   += $row['reward']['coins']['bet'];
                $spins += $row['reward']['spins'];
            }
            $ret = oo::commonOprModel('member')->optProperty($uid,['money' => $coins * $bet ,'spins' => $spins],'+',103,'回归赠送');
            if($ret){
                $userAssetsInfo = oo::commonOprModel('member')->getUserAssetsInfo($uid);
                return oo::response(1,[
                    'curAssetsInfo' => [
                        'coins' => $userAssetsInfo['money'],
                        'spins' => $userAssetsInfo['spins']
                    ]
                ],"领取成功",true);
            }
            return oo::response(-2);
        }
        return oo::response(-1);
    }

    /**
     * 测试用--删除最大关卡奖励
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2020/4/26 16:11
     */
    public function delMaxLevelStatus($param){
        $uid = oo::functions()->uint($param['uid']);
        $tb  = otable::MaxLevelReward();
        $sql = "DELETE FROM {$tb} WHERE uid={$uid}";
        $ret = oo::commonOprDb('common')->query($sql);
        return oo::response($ret?1:-1);
    }

    /**
     *
     * Created by: Owen
     * Created on: 2020/4/26 16:41
     */
    public function delSignInProgress($param){
        $uid = oo::functions()->uint($param['uid']);
        $update = '';
        if($param['signInDay']){
            $signInDay = oo::functions()->uint($param['signInDay']);
            $update = "`signInDay`={$signInDay}";
        }
        if($param['rewardDay']){
            $update .= ",`rewardDay` = '[]'";
        }
        if(!empty($update)){
            $cacheKey = okeys::UserSignInProgress($uid);
            oo::commonOprRedis('common')->delete($cacheKey);
            $tb = otable::UserSignInProgress();
            oo::commonOprDb('common')->query("UPDATE {$tb} SET {$update} WHERE `uid` = {$uid}");
        }
        return oo::response(1);
    }
    
    public function delFirstPay($param){
        $uid = oo::functions()->uint($param['uid']);
        oo::commonOprRedis('User')->delete(okeys::firstPay($uid));
        $tb = otable::payment($uid);
        $sql = "DELETE FROM {$tb} WHERE uid={$uid} AND status=2 AND gid= 601";
        oo::commonOprDb('payment')->query($sql);
        oo::commonOprRedis('common')->delete([okeys::promotion($uid),okeys::promotion($uid,702),okeys::promotion($uid,703),]);
    }
}
