<?php
/**
 * Test.php
 * Created by: Owen
 * Created on: 2020/5/21 12:14
 *
 */

class TestControl{
    /**
     * 更新最後登錄時間
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2020/5/21 12:28
     */
    public function setLastLoginTime($param){
        $uid      = oo::functions()->uint($param['uid']);
        $lastTime = oo::functions()->uint($param['lastTime']);
        if(empty($uid) || empty($lastTime)){
            return oo::response(-1);
        }
        $userInfo = oo::commonOprModel('member')->getUserInfo($uid);
        if($userInfo){
            $userInfo['lasttime'] = $lastTime;
            oo::commonOprRedis('User')->hMset(okeys::t_userinfoNew($uid), $userInfo);
            oo::commonOprRedis('User')->expire(okeys::t_userinfoNew($uid), 7*24*60*60);
            return oo::response(1);
        }
        return oo::response(-2);
    }

    /**
     * 设置签到时间
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2020/5/25 19:25
     */
    public function delSignIn($param){
        $uid = oo::functions()->uint($param['uid']);
        $day = oo::functions()->uint($param['day']);
        $isDelToday = oo::functions()->uint($param['isDelToday']);
        if(empty($uid)){
            return oo::response(-1);
        }
        if($isDelToday){
            oo::commonOprRedis('User')->delete(okeys::SignInToday($uid));
        }
        if($day){
            oo::commonOprRedis('User')->setex(okeys::SignInTimes($uid),$day,oo::weekDeadline());
        }else{
            oo::commonOprRedis('User')->delete(okeys::SignInTimes($uid));
        }
        return oo::response(1);
    }

    /**
     * 簽到進度
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2020/5/28 10:10
     */
    public function delSignInProgress($param){
        $uid = oo::functions()->uint($param['uid']);
        if(empty($uid)){
            return oo::response(-1);
        }
        $signInDay  = oo::functions()->uint($param['signInDay']);
        $rewardDay  = explode(',',oo::functions()->escape($param['rewardDay']));
        $data = [
            'signInDay' => $signInDay,
            'rewardDay' => $rewardDay
        ];
        $isDelReward = oo::functions()->uint($param['isDelReward']);
        $isDelReward && $data['rewardDay'] = [];
        $res = oo::commonOprModel('member')->updateUserSignInProgress($uid,$data,true,true);
        $key = "SIGNINTIMES:{$uid}";
        if($signInDay<7){
            oo::commonOprRedis('common')->setex($key,$signInDay,86400*(7-$signInDay));
        }
        return oo::response(1, $res);
    }

    /**
     * 删除转盘状态
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2020/5/26 16:41
     */
    public function delTpFree($param){
        $uid = oo::functions()->uint($param['uid']);
        $type = oo::functions()->escape($param['type']);
        $gid = oo::functions()->escape($param['gid']);
        if(empty($type)){
            $type = 0;
        }
        if(empty($gid)){
            $gid = 13;
        }
        switch ($type){
            case 0:
                oo::commonOprRedis('common')->delete(okeys::TpFeeTimes($uid));
                oo::commonOprRedis('common')->hDel(okeys::fbTurnCount(),$uid);
                oo::commonOprRedis('common')->delete(okeys::bigwheel($uid));
                oo::commonOprRedis('common')->hDel(okeys::vipTurnTable(),$uid);
                break;
            case 2:
                oo::commonOprRedis('common')->hDel(okeys::fbTurnCount(),$uid);
                break;
            case 1:
                oo::commonOprRedis('common')->delete(okeys::bigwheel($uid));
                break;
            case 3:
                oo::commonOprRedis('common')->hDel(okeys::vipTurnTable(),$uid);
                break;
            case 4:
                oo::commonOprRedis('common')->delete(okeys::TpFeeTimes($uid));
                break;
        }
        oo::commonOprRedis('common')->hDel(okeys::advertisementRemainCount(),$uid.'-'.$gid);
        return oo::response(1);
    }

    /**
     * 转发
     * @param $param
     * @return bool|string
     * Created by: Owen
     * Created on: 2020/5/22 18:52
     */
    public function sendCurl($param){
        //初始化
        $curl = curl_init();
        //设置 url email,first_name,gender,locale,location,birthday,hometown,token_for_business
        curl_setopt($curl, CURLOPT_URL, $param['url']);
        //设置头文件的信息作为数据流输出
        curl_setopt($curl, CURLOPT_HEADER, false);
        //设置获取的信息以文件流的形式返回，而不是直接输出。
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        //执行命令
        $data = curl_exec($curl);
        //关闭URL请求
        curl_close($curl);
        //显示获得的数据
        return $data;
    }

    /**
     * 获取Token
     * @return string
     * Created by: Owen
     * Created on: 2020/12/14 15:43
     */
    public function getGoogleSubscribeToken(){
        $token = oo::commonOprModel('Paymentgoogle')->getToken();
        return oo::response(1,['token'=>$token, 'access_token' => $token]);
    }

    /**
     * 随机字符串
     */
    public function nxasuLvTToken(){
        $accToken = oo::commonOprModel('Paymentgoogle')->getAccessToken();
        $ttl = oo::commonOprRedis('Config')->ttl(okeys::GoogleAccessToken());
        return oo::response(1,['access_token' => $accToken, 'expiry' => time() + $ttl]);
    }

    /**
     * 删除限定礼包
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2020/6/12 15:19
     */
    public function delLimitGift($param){
        $uid = oo::functions()->uint($param['uid']);
        if(empty($uid)){
            return oo::response(-1);
        }
        oo::commonOprRedis('common')->delete([
            okeys::promotion($uid),
            okeys::promotion($uid,702),
            okeys::promotion($uid,703),
        ]);
        return oo::response(1);
    }

    /**
     * 删除动态key
     */
    public function delFromCloud($param){
        $uid = oo::functions()->uint($param['uid']);
        if( empty($uid) ){
            return oo::response(-1);
        }
        $userDynamicsData = oo::commonOprModel('member')->getUserDynamicsData($uid);
        $userDynamicsData = [];
        oo::commonOprRedis('common')->delete(okeys::UserCache($uid));
        oo::commonOprModel('member')->updateUserDynamicsData($uid,['userCache'=>[]]);
        return oo::response(1);
    }

    /**
     * 删除限定礼包
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2020/6/12 15:19
     */
    public function delSerialPack($param){
        $uid = oo::functions()->uint($param['uid']);
        if(empty($uid)){
            return oo::response(-1);
        }
        oo::commonOprRedis('common')->hDel(okeys::SerialPackTimer(),okeys::SerialPackTimer($uid,710));
        oo::commonOprRedis('common')->hDel(okeys::SerialPackTimer(),okeys::SerialPackTimer($uid,711));
        oo::commonOprRedis('common')->hDel(okeys::SerialPackTimer(),okeys::SerialPackTimer($uid,712));
        $aid   = oo::commonOprModel('activitynew')->getBindActivity($uid,'chain_gift');
        oo::commonOprRedis('activity')->hDel(okeys::buyChainGiftLimit($aid),$uid.'_710');
        oo::commonOprRedis('activity')->hDel(okeys::buyChainGiftLimit($aid),$uid.'_711');
        oo::commonOprRedis('activity')->hDel(okeys::buyChainGiftLimit($aid),$uid.'_712');
        return oo::response(1);
    }

    /**
     * 设定vip
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2020/6/19 10:20
     */
    public function setVip($param){
        $uid   = oo::functions()->uint($param['uid']);
        $point = oo::functions()->uint($param['point']);
        if(empty($uid) || empty($point)){
            return oo::response(-1);
        }
        $updateInfo['svipPoint'] = $point;
        $updateInfo['svip'] = 1;
        $updateInfo['svip_expire'] = time() + 7*24*60*60;
        oo::commonOprModel('member')->getUserInfo($uid, NULL, true,$updateInfo);
        oo::commonOprModel('newvip')->updateVipLv($uid);
        return oo::response(1,['vipInfo'=>oo::commonOprModel('newvip')->getVipInfo($uid)]);
    }

    /**
     * 删除vip奖励领取记录
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2021/3/17 20:01
     */
    public function delVipDailyReward($param){
        $uid   = oo::functions()->uint($param['uid']);
        if(empty($uid)){
            return oo::response(-1);
        }
        oo::commonOprRedis('common')->delete(okeys::UserVipWeekReward($uid));
        return oo::response(1);
    }

    /**
     * 给单个玩家发送推送
     * @param $param
     * @return false|string
     * Created by: Owen
     * Created on: 2020/6/22 11:41
     */
    public function pushFirebase($param){
        $uid     = oo::functions()->uint($param['uid']);
        $title   = oo::functions()->escape($param['title']);
        $content = oo::functions()->escape($param['content']);
        if( empty($uid) || empty($title) || empty($content) ){
            return oo::response(-1);
        }
        $extra   = oo::functions()->escape($param['extra']);
        $extra   = json_decode($extra,true) ?? ['id'=>1,'content'=>11111];
        IS_DEBUF ? funs::sendCurl("",['mod'=>"Test",'act'=>'pushFirebase','uid'=>$uid,'title'=>$title,'content'=>$content]) : oo::commonOprModel('push')->pushNewsToOne($uid, $title, $content, $extra);
        return oo::response(1);
    }

    /**
     * 删除宠物
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2020/7/2 15:51
     */
    public function deletePet($param){
        $uid     = oo::functions()->uint($param['uid']);
        if(empty($uid)){
            return oo::response(-1);
        }
        $tb = otable::UserPet($uid);
        $sql = "DELETE FROM {$tb} WHERE uid={$uid}";
        oo::commonOprDb('common')->query($sql);
        oo::commonOprRedis('user')->delete([
            okeys::UserPet($uid,1),
            okeys::UserPet($uid,2),
            okeys::UserPet($uid,3),
            okeys::CurUserPet($uid),
            okeys::FreeFeedPet($uid),
            okeys::UserPet2($uid)
        ]);
        return oo::response(1);
    }

    /**
     * Notes:激活宠物
     * User: wsc
     * Time: 2021/8/9 19:46
     * @param $param
     * @return string
     */
    public function incubatePet($param){
        $uid  = oo::functions()->uint($param['uid']);
        $petId  = oo::functions()->uint($param['petId']);
        $petInfo = oo::commonOprModel('pet')->getUserPet($uid,$petId);
        if($petInfo){
            return oo::response(-1,[],"已经激活过");
        }
        $tb  = otable::UserPet($uid);
        $time = time();
        oo::commonOprDb('common')->query("INSERT INTO {$tb} (uid,petId,nick,getTime,star) VALUES ('{$uid}','{$petId}','pet','{$time}',-1)", false);
        $userPet = oo::commonOprDb('common')->getOne("SELECT * FROM {$tb} WHERE uid={$uid} AND petId={$petId} LIMIT 1", MYSQLI_ASSOC);
        oo::commonOprRedis('User')->hSet(okeys::UserPet2($uid),$petId,json_encode($userPet));
        return oo::response(1,[],"激活成功");
    }

    /**
     * Notes:清除宠物喂养时间
     * User: xwy
     * Time: 2021/12/28 16:46
     * @param $param
     * @return string
     */
    public function changePetFeedTime($param){
        $uid  = oo::functions()->uint($param['uid']);
        $petId  = oo::functions()->uint($param['petId']);
        $petInfo = oo::commonOprModel('pet')->getUserPet($uid,$petId);
        $petInfo['lastFeedTime'] = 1;
        $petInfo['feedEffecteTime'] = 1;
        oo::commonOprRedis('User')->hSet(okeys::UserPet2($uid) ,$petId,json_encode($petInfo));
        oo::commonOprRedis('User')->delete(okeys::FreeFeedPet($uid));
        return oo::response(1,[],"激活成功");
    }
    /**
     * 删除首冲
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2020/7/28 15:48
     */
    public function delFirstPay($param){
        $uid     = oo::functions()->uint($param['uid']);
        $gid     = oo::functions()->uint($param['gid']);
        if(empty($uid)){
            return oo::response(-1);
        }
        oo::commonOprRedis('User')->delete(okeys::firstPay($uid,$gid));
        $tb = otable::payment($uid);
        oo::commonOprDb('payment')->query("DELETE FROM {$tb} WHERE uid={$uid} AND status=2 AND gid= {$gid}");

        oo::commonOprRedis("common")->delete(okeys::PropsExpire($uid,"37-spins"));
        oo::commonOprRedis("common")->delete(okeys::PropsExpire($uid,"37-coins"));
        oo::commonOprRedis("common")->delete(okeys::PropsExpire($uid,"37-buy"));

        return oo::response(1);
    }

    /**
     * 删除星星兑换状态
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2021/3/17 20:02
     */
    public function delStarExchange($param){
        $uid     = oo::functions()->uint($param['uid']);
        if(empty($uid)){
            return oo::response(-1);
        }
        oo::commonOprRedis('user')->delete([
            okeys::StarExchange($uid,10),
            okeys::StarExchange($uid,11),
            okeys::StarExchange($uid,12),
            okeys::StarExchangeBuyTimer($uid,10),
            okeys::StarExchangeBuyTimer($uid,11),
            okeys::StarExchangeBuyTimer($uid,12),
        ]);
        return oo::response(1);
    }

    /**
     * 删除好友礼物
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2020/8/20 14:58
     */
    public function delFriendGift($param){
        $uid     = oo::functions()->uint($param['uid']);
        if(empty($uid)){
            return oo::response(-1);
        }
        oo::commonOprRedis('common')->hDel(okeys::friendGiftMaxTimes(1),$uid);
        oo::commonOprRedis('common')->hDel(okeys::friendGiftMaxTimes(2),$uid);
        $list = oo::commonOprModel('friend')->getFriendAndGiftList($uid);
        $list = json_decode($list,true);
        $list = $list['data'];
        foreach ($list['list'] as $user){
            oo::commonOprRedis('common')->delete([
                okeys::SendGiftToday($uid,$user['uid'],1),
                okeys::SendGiftToday($user['uid'],$uid,1),
                okeys::SendGiftToday($uid,$user['uid'],2),
                okeys::SendGiftToday($user['uid'],$uid,2),
            ]);
        }
        return oo::response(1);
    }

    /**
     * 删除矿工小游戏
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2020/8/27 14:26
     */
    public function delMingGame($param){
        $uid = oo::functions()->uint($param['uid']);
        if (empty($uid)) {
            return oo::response(-1);
        }
        oo::commonOprRedis('User')->delete(okeys::MiningGame($uid));
        oo::commonOprRedis('User')->delete(okeys::LastMiningGameCoinsNum($uid));
        oo::commonOprRedis('User')->delete(okeys::MiningGameLevel($uid));
        oo::commonOprRedis('User')->delete(okeys::MiningGamePreLevelId($uid));
        oo::commonOprRedis('User')->delete(okeys::MiningGameStateReward($uid));
        return oo::response(1);
    }

    /**
     * 删除当日首次老虎机概率状态
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2020/9/2 17:16
     */
    public function delFirstSlot($param){
        $uid = oo::functions()->uint($param['uid']);
        if (empty($uid)) {
            return oo::response(-1);
        }
        $key = okeys::concurrentLock($uid,"ADJUSTSLOTPRO");
        oo::commonOprRedis('common')->delete($key);
        return oo::response(1);
    }

    /**
     * 体力加速
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2020/9/11 19:45
     */
    public function doubleSpins($param){
        $uid  = oo::functions()->uint($param['uid']);
        $time = oo::functions()->uint($param['time']);
        oo::commonOprModel('activitynew')->openSpecialAct($uid,'speed_spins',$time);
        return oo::response(1);
    }

    public function addCardByGroup($param){
        $uid  = oo::functions()->uint($param['uid']);
        $gid  = oo::functions()->uint($param['gid']);
        if (empty($uid)) {
            return oo::response(-1);
        }
    }

    /**
     * 删除通行证
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2020/10/26 11:26
     */
    public function delTrafficPermit($param){
        $uid  = oo::functions()->uint($param['uid']);
        if (empty($uid)) {
            return oo::response(-1);
        }
        $aid = oo::commonOprModel('activitynew')->activityLock($uid,"traffic_permit");
        $tb  = otable::payment($uid);
        oo::commonOprDb('userinfo')->query("DELETE FROM {$tb} WHERE uid='{$uid}' AND buff='{$aid}'");
        oo::commonOprRedis('activity')->hDel(okeys::TrafficPermitReward($aid),'normal_'.$uid);
        oo::commonOprRedis('activity')->hDel(okeys::TrafficPermitReward($aid),'special_'.$uid);
        oo::commonOprRedis('activity')->delete(okeys::TrafficPermitUser($aid, $uid));
        
        for($i=1;$i<=10;$i++){
            oo::commonOprRedis('activity')->hDel(okeys::TrafficPermitTaskCurNum($aid),"{$uid}-{$i}");
        }
        oo::commonOprRedis('activity')->delete(okeys::TrafficPermitUserTask($aid, $uid));
        oo::commonOprRedis('activity')->hDel(okeys::TrafficPermitCurNum($aid),$uid);
        oo::commonOprRedis('activity')->delete(okeys::BuyTrafficPermitStatus($aid,$uid));
        return oo::response(1);
    }

    /**
     * 通行证广播
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2020/11/11 14:33
     */
    public function pushTrafficPermit($param){
        $uid  = oo::functions()->uint($param['uid']);
        if (empty($uid)) {
            return oo::response(-1);
        }
        oo::commonOprModel('activitynew')->BuyTrafficPermitNotice($uid);
        return oo::response(1);
    }

    /**
     * 删除vip
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2020/11/20 17:19
     */
    public function delVip($param){
        $uid  = oo::functions()->uint($param['uid']);
        if (empty($uid)) {
            return oo::response(-1);
        }
        $updateInfo['svip'] = 0;
        $updateInfo['svip_expire'] = time();
        oo::commonOprModel('member')->getUserInfo($uid, NULL, true,$updateInfo);
        oo::commonOprRedis('common')->delete(okeys::VipExperience($uid));
        return oo::response(1);
    }

    /**
     * 删除夺宝
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2020/11/26 11:27
     */
    public function delLuckyDraw($param){
        $uid  = oo::functions()->uint($param['uid']);
        if (empty($uid)) {
            return oo::response(-1);
        }
        oo::commonOprModel('luckydraw')->updateUserLuckyValue($uid,0);
        $progressConfig = oo::commonOprModel('luckydraw')->getProgressConfig(true);
        oo::commonOprRedis('usercache')->delete(okeys::LuckyProgress($uid));
        foreach ($progressConfig as $key=>$row){
            oo::commonOprRedis('usercache')->delete(okeys::LuckuRewardProgress($uid,$key));
        }
        return oo::response(1);
    }

    /**
     * 删除保险柜
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2021/3/17 20:03
     */
    public function delSafeBox($param){
        $uid  = oo::functions()->uint($param['uid']);
        if (empty($uid)) {
            return oo::response(-1);
        }
        $aid = oo::commonOprModel('activitynew')->activityLock($uid,'spin_safe');
        oo::commonOprRedis('Activity')->hDel(okeys::SteelSafeCurNum($aid),$uid);
        oo::commonOprRedis('Activity')->hDel(okeys::SteelSafeCurProgress($aid),$uid);
        return oo::response(1);
    }

    /**
     * 添加保险柜
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2020/12/5 17:00
     */
    public function addSafeBox($param){
        $uid  = oo::functions()->uint($param['uid']);
        $num  = oo::functions()->uint($param['num']);
        if (empty($uid) || empty($num)) {
            return oo::response(-1);
        }
        $aid = oo::commonOprModel('activitynew')->activityLock($uid,"spin_safe");
        $conf = oo::commonOprModel('activitynew')->getActReward($aid)['extra_reward'];
        $userCurProgress = count(oo::commonOprModel('activitynew')->getSteelSafeCurProgress($aid,$uid));
        $pConfig = $conf['config'][$userCurProgress];
        //$coins = intval(oo::commonOprModel('goods')->getGoodCoins($uid,$pConfig['coins']) * $pConfig['bet']);
        $spins = isset($pConfig['spins'])?$pConfig['spins']:3;
        oo::commonOprRedis('Activity')->hSet(okeys::SteelSafeCurNum($aid),$uid,min($num,$spins));
        return oo::response(errorCode::SUCCESS,['curSafeBoxNum'=>min($num,$spins)]);
    }

    /**
     * 触发保险柜限时奖励
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2021/3/17 20:03
     */
    public function safeBoxLimit($param){
        $uid  = oo::functions()->uint($param['uid']);
        $aid = oo::commonOprModel('activitynew')->activityLock($uid,'spin_safe');
        oo::commonOprRedis('Activity')->delete(okeys::SteelSafeLimitReward($aid,$uid));
        oo::commonOprRedis('Activity')->delete(okeys::SteelSafeWaitPush($uid));
        oo::commonOprRedis('Activity')->delete(okeys::SteelSafePushStatus($uid,0));
        oo::commonOprRedis('Activity')->delete(okeys::SteelSafePushStatus($uid,1));
        oo::commonOprRedis('Activity')->delete(okeys::SteelSafePushStatus($uid,2));
        oo::commonOprRedis('Activity')->delete(okeys::SteelSafePushStatus($uid,3));
        oo::commonOprModel('activitynew')->actionSteelSafe($uid,0);
        return oo::response(1);
    }
    /**
     * 删除小丑卡
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2021/3/17 20:03
     */
    public function delJokerCard($param){
        $uid  = oo::functions()->uint($param['uid']);
        oo::commonOprRedis('User')->delete(okeys::JokerCard($uid));
        return oo::response(1);
    }

    /**
     * 设置用户卡片
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2021/3/17 20:04
     */
    public function setCardNum($param){
        $uid   = oo::functions()->uint($param['uid']);
        $userCard = [];
        foreach ([2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 20, 21, 22, 23, 24, 25, 26, 27, 29, 30, 31, 32, 33, 34, 35, 36, 38, 39, 40, 41, 42, 43, 44, 45, 47, 48, 49, 50, 51, 52, 53, 54, 56, 57, 58, 59, 60, 61, 62, 63, 65, 66, 67, 68, 69, 70, 71, 72, 74, 75, 76, 77, 78, 79, 80, 81, 83, 84, 85, 86, 87, 88, 89, 90, 92, 93, 94, 95, 96, 97, 98, 99, 101, 102, 103, 104, 105, 106, 107, 108, 110, 111, 112, 113, 114, 115, 116, 117, 119, 120, 121, 122, 123, 124, 125, 126, 128, 129, 130, 131, 132, 133, 134, 135, 137, 138, 139, 140, 141, 142, 143, 144, 146, 147, 148, 149, 150, 151, 152, 153, 155, 156, 157, 158, 159, 160, 161, 162, 164, 165, 166, 167, 168, 169, 170, 171, 173, 174, 175, 176, 177, 178, 179, 180, 182, 183, 184, 185, 186, 187, 188, 189, 191, 192, 193, 194, 195, 196, 197, 198, 200, 201, 202, 203, 204, 205, 206, 207, 209, 210, 211, 212, 213, 214, 215, 216, 218, 219, 220, 221, 222, 223, 224, 225, 227, 228, 229, 230, 231, 232, 233, 234, 236, 237, 238, 239, 240, 241, 242, 243, 245, 246, 247, 248, 249, 250, 251, 252, 254, 255, 256, 257, 258, 259, 260, 261, 263, 264, 265, 266, 267, 268, 269, 270, 272, 273, 274, 275, 276, 277, 278, 279, 281, 282, 283, 284, 285, 286, 287, 288, 290, 291, 292, 293, 294, 295, 296, 297, 299, 300, 301, 302, 303, 304, 305, 306, 308, 309, 310, 311, 312, 313, 314, 315, 317, 318, 319, 320, 321, 322, 323, 324, 326, 327, 328, 329, 330, 331, 332, 333, 335, 336, 337, 338, 339, 340, 341, 342] as $ciid){
            $userCard[$ciid] = 8;
        }
        oo::commonOprModel('card')->updateUserCardInfo($uid,['ciid'=>$userCard]);
        return oo::response(1);
    }

    /**
     * 設置卡片数量
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2020/12/22 14:21
     */
    public function setCard($param){
        $uid   = oo::functions()->uint($param['uid']);
        $ciid  = oo::functions()->uint($param['ciid']);
        if (empty($uid) || empty($ciid)) {
            return oo::response(-1);
        }
        $num   = oo::functions()->uint($param['num']);
        $userCardInfo = oo::commonOprModel('card')->getUserCardInfo($uid);
        $userCard = $userCardInfo['ciid'];
        if($num){
            $userCard[$ciid] = $num;
        }else{
            unset($userCard[$ciid]);
        }
        oo::commonOprModel('card')->updateUserCardInfo($uid,['ciid'=>$userCard]);
        return oo::response(1,oo::commonOprModel('card')->getUserCardInfo($uid),"",true);
    }

    /**
     * 删除用户卡片
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2021/3/17 20:03
     */
    public function delAllCard($param){
        $uid   = oo::functions()->uint($param['uid']);
        $userCard = [];
        oo::commonOprModel('card')->updateUserCardInfo($uid,['ciid'=>$userCard,'cgreward'=>[]]);
        /**
         * 删除宠物
         */
        $tb = otable::UserPet($uid);
        $sql = "DELETE FROM {$tb} WHERE uid={$uid}";
        oo::commonOprDb('common')->query($sql);
        oo::commonOprRedis('user')->delete([
            okeys::UserPet($uid,1),
            okeys::UserPet($uid,2),
            okeys::UserPet($uid,3),
            okeys::CurUserPet($uid),
            okeys::FreeFeedPet($uid),
            okeys::UserPet2($uid)
        ]);
        return oo::response(1);
    }

    /**
     * 添加好友
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2021/3/17 20:05
     */
    public function addFriend($param){
        $uid   = oo::functions()->uint($param['uid']);
        $toUid = oo::functions()->uint($param['toUid']);
        $num   = oo::functions()->uint($param['num']);
        $tb    = otable::userinfo();
        if (empty($uid)) {
            return oo::response(-1);
        }
        if ($toUid != 0){
            foreach ([$uid, $toUid] as $tuid){
                $ret = oo::commonOprDb('common')->getOne("SELECT * FROM {$tb} WHERE uid = {$tuid}",MYSQLI_ASSOC);
                if(empty($ret)){
                    return oo::response(-1,[],"用户:{$tuid} 不存在");
                }
                if($ret['status'] != 1)return oo::response(-1,[],"用户:{$tuid} 为失效用户");
            }

            $ret = oo::commonOprModel('friend')->addUserFriend($uid,$toUid);
            return oo::response(1,['list'=>$ret]);
        }
        if($num == 0){
            return oo::response(-1,[],"数量异常");
        }
        $num = min(max($num,1),50);

        $friends = oo::commonOprModel('friend')->getUserAllFriend($uid);
        $friends[] = $uid;
        $friendsStr =   implode(',', $friends);
        $ret = oo::commonOprDb('common')->getAll("SELECT * FROM {$tb} WHERE uid not in ({$friendsStr}) and status = 1 ORDER BY lasttime DESC LIMIT {$num}",MYSQLI_ASSOC);
        $cnt = 0;
        foreach ($ret as $row){
            $toUid = $row['uid'];
            $retList = oo::commonOprModel('friend')->addUserFriend($uid,$toUid);
//            oo::commonOprRedis('userinfo')->delete(okeys::userfriends($toUid,'all'));
//            oo::commonOprRedis('userinfo')->delete(okeys::userfriends($toUid,'game'));
//            oo::commonOprRedis('userinfo')->delete(okeys::userIndexFriends($toUid));
            $cnt++;
        }
//        oo::commonOprRedis('userinfo')->delete(okeys::userfriends($uid,'all'));
//        oo::commonOprRedis('userinfo')->delete(okeys::userfriends($uid,'game'));
//        oo::commonOprRedis('userinfo')->delete(okeys::userIndexFriends($uid));
        return oo::response(1, ['count' => $cnt,"list"=>$retList]);
    }

    /**
     * Notes:删除好友
     * User: wsc
     * Time: 2021/9/1 14:46
     * @param $param
     * @return string
     */
    public function delFriend($param){
        $uid   = oo::functions()->uint($param['uid']);
        $toUid = oo::functions()->uint($param['toUid']);
        $num   = oo::functions()->uint($param['num']);
        if (empty($uid)) {
            return oo::response(-1);
        }
        if ($toUid != 0){
            $ret =oo::commonOprModel('friend')->deleteFriend($uid,$toUid);
            return oo::response(1,["list"=>$ret]);
        }
        $list = oo::commonOprModel('friend')->getUserAllFriend($uid,"all");
        $i=0;
        foreach ($list as $fid){
            $i++;
            oo::commonOprModel('friend')->deleteFriend($uid,$fid);
            if ($num<$i){
                break;
            }
        }

    }

    /**
     * 删除邀请记录
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2021/3/17 20:05
     */
    public function delInvite($param){
        $uid     = oo::functions()->uint($param['uid']);
        $inviter = oo::functions()->uint($param['inviteUid']); //邀请者uid
        if (empty($uid)) {
            return oo::response(-1);
        }
        oo::commonOprRedis('common')->delete(okeys::InviteUrlRecord($uid));
        $tb  = otable::userinvitesuc();
        oo::commonOprDb('common')->query("DELETE FROM {$tb} WHERE is_backuid={$uid}", false);
        $tb  = otable::userinvitegiftbag();
        oo::commonOprDb('common')->query("DELETE FROM {$tb} WHERE uid={$uid}", false);
        return oo::response(1);
    }

    /**
     * 删除所有邀请者的邀请数据
     * @param $param
     * @return string
     * Created by: Richard
     * Created on: 2021/8/17 10:21
     */
    public function delInviterInfo($param){
        $uid     = oo::functions()->uint($param['uid']);
        if (empty($uid)) {
            return oo::response(-1);
        }
        $gbTb = otable::userinvitegiftbag();
        oo::commonOprDb('common')->query("DELETE FROM {$gbTb} WHERE uid={$uid}");//邀请礼包记录删除
        $data = oo::commonOprRedis('user')->delete(okeys::InviteStageLog($uid));
        $tb  = otable::userinvitesuc();

        $arr = oo::commonOprDb('common')->getAll("SELECT * FROM {$tb} WHERE is_senduid={$uid}", 1);
        foreach($arr as $v){
            oo::commonOprRedis('User')->delete(okeys::userinvitesuc($v['is_backuid']));
        }
        oo::commonOprRedis('User')->delete(okeys::InviteeFbReward($uid));
        oo::commonOprRedis('User')->delete(okeys::inviteBindFb($uid));
        oo::commonOprDb('common')->query("DELETE FROM {$tb} WHERE is_senduid={$uid}");
        return oo::response(1);
    }

    /**
     * 获取FireBase token
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2021/3/17 20:05
     */
    public function getFirebaseToken($param){
        $uid   = oo::functions()->uint($param['uid']);
        if (empty($uid)) {
            return oo::response(-1);
        }
        $tb  = otable::xg_push();
        $ret = oo::commonOprDb('common')->getOne("SELECT * FROM {$tb} WHERE uid={$uid} LIMIT 1", MYSQLI_ASSOC);
        return oo::response(1,[
            'token'=>$ret['token']
        ]);
    }

    /**
     * 获取用户VIP订单详情
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2021/3/17 20:06
     */
    public function getVipInfo($param){
        $uid   = oo::functions()->uint($param['uid']);
        if (empty($uid)) {
            return oo::response(-1);
        }
        $vipInfo  = oo::commonOprModel('newvip')->getVipInfo($uid);
        $tb  = otable::subscription();
        $sql = "SELECT * FROM {$tb} WHERE uid={$uid}";
        $ret = oo::commonOprDb('payment')->getOne($sql,MYSQLI_ASSOC);
        $purchaseToken = $ret["purchaseToken"];
        if(!empty($purchaseToken)){
            $goodInfo = oo::commonOprModel('Paymentgoogle')->getUserSubscribeStatus("com.gworld.crazyspin","com.gworld.cc.subscription01",$purchaseToken);
            if(isset($goodInfo['error'])){
                oo::commonOprRedis('common')->delete($purchaseToken);
                $goodInfo = oo::commonOprModel('Paymentgoogle')->getUserSubscribeStatus("com.gworld.crazyspin","com.gworld.cc.subscription03",$purchaseToken);
            }
        }else{
            $goodInfo = "token empty";
        }
        return oo::response(1,[
            'vipInfo'  => $vipInfo,
            'goodInfo' => $goodInfo,
            'token'    => $purchaseToken
        ]);
    }

    /**
     * 获取通行证等级分布
     * @param $param
     * @return bool|string
     * Created by: Owen
     * Created on: 2021/3/17 20:06
     */
    public function getTrafficPermitLevelInfo($param){
        $maxLevel   = oo::functions()->uint($param['levelId']);
        $aidArr = oo::commonOprModel('activitynew')->getAllOnlineActivityByType('traffic_permit');
        if (empty($aidArr)) {
            return false;
        }
        $aid = 0;
        foreach ($aidArr as $row) {
            $aid = $row;
            break;
        }
        $curNumArr  = oo::commonOprRedis('activity')->hGetAll(okeys::TrafficPermitCurNum($aid));
        $rewardConf = oo::commonOprModel('activitynew')->getActReward($aid);
        $levelConf  = [];
        $reward = $rewardConf['reward']??[];
        foreach ($reward as $k=>$v) {
            $levelConf[$v['levelId']] = $v['max'];
        }
        $levelData = [];
        $out = [];
        foreach ($curNumArr as $uid=>$num){
            $levelId = 0;
            foreach ($levelConf as $level=>$max){
                if($num < $max){
                    break;
                }
                $levelId = $level;
            }
            if($levelId >= $maxLevel){
                $out[] = $uid."-".$levelId;
            }
            $levelData[$levelId] = intval($levelData[$levelId]) + 1;
        }
        return oo::response(1,$out);
    }

    /**
     * 删除基金活动
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2021/3/17 20:06
     */
    public function delFund($param){
        $uid = oo::functions()->uint($param['uid']);
        $delPay    = oo::functions()->uint($param['delPay']);
        $delStatus = oo::functions()->uint($param['delStatus']);
        $delAct    = oo::functions()->uint($param['delAct']);
        $delReissue= oo::functions()->uint($param['delReissue']);
        if (empty($uid)) {
            return oo::response(-1);
        }
        $aid = oo::commonOprModel('activitynew')->activityLock($uid,"fund");
        if($delPay){
            oo::commonOprRedis('activity')->delete(okeys::BuyFundStatus($aid,$uid));
            oo::commonOprRedis('activity')->delete(okeys::BuyFundTime($aid,$uid));
            $tb  = otable::payment($uid);
            oo::commonOprDb('payment')->query("DELETE FROM {$tb} WHERE uid='{$uid}' AND buff='{$aid}'");
        }
        if($delStatus){
            oo::commonOprRedis('activity')->delete(okeys::TodayRewardStatus($aid,$uid));
            oo::commonOprRedis('activity')->hDel(okeys::FundRewardList($aid),$uid);
        }
        if($delAct){
            oo::commonOprRedis("Activity")->delete(okeys::FundAid($uid));
        }
        if($delReissue){
            oo::commonOprRedis("Activity")->hDel(okeys::FundReissue($aid),$uid);
        }
        return oo::response(1);
    }

    /**
     * 设置基金活动购买时间
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2021/3/17 20:07
     */
    public function setFundPayTime($param){
        $uid  = oo::functions()->uint($param['uid']);
        $time = oo::functions()->uint($param['time']);
        $aid  = oo::commonOprModel('activitynew')->activityLock($uid,"fund");
        $cacheKey = okeys::BuyFundTime($aid,$uid);
        oo::commonOprRedis('activity')->setex($cacheKey,$time,7*24*60*60);
        oo::commonOprRedis("Activity")->hSet(okeys::FundAidUid($aid),$uid,$time);
        oo::commonOprRedis('activity')->delete(okeys::TodayRewardStatus($aid,$uid));
        return oo::response(1);
    }

    /**
     * 删除用户签到分组
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2021/3/17 20:07
     */
    public function delSignInUserGroup($param){
        $uid  = oo::functions()->uint($param['uid']);
        $cacheKey = okeys::SignInUserGroupId($uid);
        oo::commonOprRedis('User')->delete($cacheKey);
        return oo::response(1);
    }

    /**
     * 用户卡片信息
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2021/3/17 20:09
     */
    public function getUserCardInfo($param){
        $uid  = oo::functions()->uint($param['uid']);
        $userCardInfo = oo::commonOprModel('card')->getUserCardInfo($uid);
        return oo::response(1,$userCardInfo);
    }

    /**
     * 清除每日宝箱每日购买记录
     */
    public function delDailyChestActExpire($param) {
        $uid  = oo::functions()->uint($param['uid']);
        oo::commonOprRedis('user')->delete(okeys::daliyChestNextTime($uid));
        return oo::response(1);
    }

    /**
     * 删除每日宝箱数据
     */
    public function delDailyChestAct($param) {
        $uid  = oo::functions()->uint($param['uid']);
        oo::commonOprRedis('user')->delete(okeys::userDailyChest($uid));
        oo::commonOprRedis('user')->delete(okeys::dailyChest($uid));
        oo::commonOprRedis('user')->delete(okeys::daliyChestNextTime($uid));
        return oo::response(1);
    }

    public function refreshInvite($param){
        $uid   = oo::functions()->uint($param['uid']);
        $toUid = oo::functions()->uint($param['toUid']);
        if (empty($uid)||empty($toUid)) {
            return oo::response(-1);
        }
        $tb = otable::userinvitesuc();
        oo::commonOprDb('common')->query("DELETE FROM {$tb} WHERE is_senduid={$uid} AND is_backuid={$toUid}");
        oo::commonOprModel('invite')->inviteSuccess($uid,$toUid,3);
        return oo::response(1);
    }

    public function setOldAdjustUser($param){
        $uid      = oo::functions()->uint($param['uid']);
        $toUid    = oo::functions()->uint($param['toUid']);
        $gid      = oo::functions()->uint($param['gid']);
        $uid1     = oo::functions()->uint($param['uid1']);
        $toUid1   = oo::functions()->uint($param['toUid1']);
        if(!empty($uid1)){
            $uid = $uid1;
        }
        if(!empty($toUid1)){
            $toUid = $toUid1;
        }
        $deviceId = $param['deviceId'];
        //老玩家邀请回归,更新上一次登录时间为7天前
        oo::commonOprModel('member')->getUserInfo($toUid, [], true, ['slasttime' => time() - 8 * 86400]);

        //删除玩家缓存,adjust设备缓存
        oo::commonOprRedis('User')->delete(okeys::AdjustDeviceID($toUid));
        $tb   = otable::AdJustSta($toUid);
        $ret  = oo::commonOprDb('common')->getOne("SELECT * FROM {$tb} WHERE uid={$toUid} LIMIT 1",MYSQLI_ASSOC);
        if(!empty($ret)){
            oo::commonOprDb('common')->query("UPDATE {$tb} SET ios = '{$deviceId}', android = '{$deviceId}' WHERE uid={$toUid}");
        } else {
            oo::commonOprDb('common')->query("INSERT INTO {$tb} SET ios = '{$deviceId}', android = '{$deviceId}', uid={$toUid}");
        }
        $tb  = otable::AdjustBackData();

        $adid = md5($toUid);
        $label = base64_encode($uid);
        $time = time();
        oo::commonOprDb('common')->query("DELETE FROM {$tb} WHERE adid='{$adid}'");
        $sql = "INSERT INTO {$tb} set adid='{$adid}',gps_adid='{$deviceId}',idfa='{$deviceId}',tracker_name='crazycoin.vip',network_name='crazycoin.vip',label='{$label}',created_at={$time}";
        oo::commonOprDb('common')->query($sql);
        return oo::response(1);
    }

    /**
     * 设置邀请成功进度数量
     * @param array $param
     * @return string
     */
    public function setInviteGiftStageNum($param){
        $uid = oo::functions()->uint($param['uid']);
        $num = oo::functions()->uint($param['num']);
        $tb  = otable::userinvitegiftbag();
        $sql ="SELECT * FROM {$tb} WHERE uid={$uid}";
        $data= oo::commonOprDb('common')->getOne($sql,1);
        if(empty($data)){
            oo::commonOprDb('common')->query("INSERT INTO {$tb} set uid={$uid},invitenum={$num}");
        } else {
            oo::commonOprDb('common')->query("UPDATE {$tb} set invitenum={$num} WHERE uid ={$uid}");
        }
        $key = okeys::InviteStageLog($uid);
        oo::commonOprRedis('user')->delete($key);
        return oo::response(1);
    }

    public function InviteePush($param){
        $uid   = oo::functions()->uint($param['uid']);
        $toUid = oo::functions()->uint($param['toUid']);
        if (empty($uid)||empty($toUid)) {
            return oo::response(-1);
        }
        $userInfo = oo::commonOprModel('member')->getUserInfo($uid);
        $data[] = [
            'uid'   =>$uid,
            'u_flag'=>$userInfo['u_flag'],
            'avatar'=>$userInfo['avatar'],
            'nick'  =>$userInfo['nick'],
            's_picture'=>$userInfo['s_picture'],
            'isFb'  =>$userInfo['isFb'],
        ];
        oo::commonOprRedis('User')->setex(okeys::InviteeFbReward($toUid),$uid,15*24*60*60);
        oo::commonOprModel('Workerman')->push($uid,ocmd::$send['Invitee'],$data);
        return oo::response(1);
    }

    public function refreshInviteStatus($param){
        $uid   = oo::functions()->uint($param['uid']);
        $toUid = oo::functions()->uint($param['toUid']);
        if (empty($uid)||empty($toUid)) {
            return oo::response(-1);
        }
        $tb = otable::userinvitesuc();
        oo::commonOprDb('common')->query("DELETE FROM {$tb} WHERE is_backuid={$toUid}");
        oo::commonOprRedis('User')->setex(okeys::AdjustInviteStatus($toUid),10,3*24*60*60);

        oo::commonOprRedis('User')->delete(okeys::AdjustDeviceID($toUid));
        $deviceID = oo::commonOprModel('member')->getAdjustDeviceIDByUid($toUid);

        oo::commonOprRedis('User')->delete(okeys::AdjustData($deviceID));
        $ret = oo::commonOprModel('member')->getDataFromAdjust($deviceID);
        $labelUid = intval(base64_decode($ret['label']));


        oo::commonOprRedis('User')->delete([okeys::InviteeFbReward($toUid),okeys::InviteeFbReward($uid)]);
        oo::commonOprRedis('User')->delete([okeys::inviteBindFb($toUid),okeys::inviteBindFb($uid)]);

        $data = [
            'deviceID'  => $deviceID,
            'inviteUid' => abs($labelUid),
        ];
        return oo::response(1,$data);
    }

    /**
     * 邀请假定绑定FB
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2021/3/25 14:33
     */
    public function assumeBindFb($param){
        $uid   = oo::functions()->uint($param['uid']);
        if (empty($uid)) {
            return oo::response(-1);
        }
        $uid = oo::commonOprModel('invite')->recordInviteBindFb($uid);
        return oo::response(1,["inviteUid"=>$uid]);
    }

    /**
     * 發送消息
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2021/4/8 16:13
     */
    public function sendMessage($param){
        $uid = oo::functions()->uint($param['uid']);
        if(empty($uid)) {
            return oo::response(-1);
        }
        $toUidInfo = oo::commonOprModel('member')->getUserInfo(200310);
        $nick      = $toUidInfo['nick'];
        $s_picture = $toUidInfo['s_picture'];
        $is_real   = 0;
        oo::commonOprModel('message')->addMessage($uid,200310,$nick,$s_picture,0,10,$is_real);
        return oo::response(1);
    }

    /**
     * 刪除分享冷卻
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2021/4/8 16:20
     */
    public function delShare($param){
        $uid = oo::functions()->uint($param['uid']);
        if(empty($uid)) {
            return oo::response(-1);
        }
        $config = oo::commonOprModel('config')->getShareConfig('',true);
        foreach ($config as $row){
            oo::commonOprRedis('common')->delete(okeys::ShareIntervalTime($uid,$row['type']));
            oo::commonOprRedis('common')->delete(okeys::userShareTimes($uid,$row['type']));
        }
        return oo::response(1);
    }

    /**
     * 设置偷取对象
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2021/4/10 16:12
     */
    public function setStealInfo($param){
        $uid   = oo::functions()->uint($param['uid']);
        $toUid = oo::functions()->uint($param['toUid']);
        $levelId = oo::functions()->uint($param['levelId']);
        $money   = oo::functions()->uint($param['money']);
        if(empty($uid) || empty($toUid)) {
            return oo::response(-1);
        }
        $info["uid"] = $toUid;
        if(empty($levelId)){
            $levelId = oo::commonOprModel('member')->getUserLevelId($toUid);
        }
        if(empty($money)){
            $money = oo::commonOprModel('member')->getUserAssetsInfo($toUid)['money'];
        }
        $nowDay = date("Ymd",time());
        oo::commonOprRedis('server')->hDel(akey::proteTimeKey($nowDay,$toUid),$toUid);//删除保护时间
        oo::commonOprRedis('server')->hDel(akey::beStealNumHashKey($nowDay),$uid);//删除被偷次数
        oo::commonOprRedis('common')->delete(okeys::beStealLock($toUid));//删除其他玩家的锁定
        $king = [
            'uid'    => $toUid,
            'money'  => $money,
            'levelId'=> $levelId,
        ];
        oo::commonOprRedis('usercache')->delete(okeys::richestKingInfo($uid));//删除老的绑定偷对象信息
        oo::commonOprRedis('server')->setex(okeys::richestKing($uid),json_encode($king),30*60);
        oo::commonOprModel('steal')->toOutQueue($king['uid'],$king['levelId'],$king['money']);
        $attacks = oo::commonOprModel('steal')->getStealData($uid);
        if($attacks) {
            $nick = oo::commonOprModel('member')->getUserFirstName($attacks['nick']);
            $res = oo::commonOprModel('Workerman')->push($uid, ocmd::$SVR_PLAYER_RAID_INFO, array('levelId' => $attacks["levelId"], 'nick' => $nick, 'vip' => $attacks['vip'], 'vipLv' => $attacks['vipLv'], 'vipExpire' => $attacks['vip_expire'], 'avatar' => intval($attacks['avatar']), 'url' => $attacks['s_picture'], 'coins' => intval($attacks['coins'])));
        }
        return oo::response(1);
    }

    /**
     * 设置攻擊对象
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2021/4/13 11:39
     */
    public function setAttackInfo($param){
        $uid   = oo::functions()->uint($param['uid']);
        $toUid = oo::functions()->uint($param['toUid']);
        if(empty($uid) || empty($toUid)) {
            return oo::response(-1);
        }
        $toUid2 =oo::commonOprRedis('common')->get(okeys::DefaultEnemy($uid));
        if($toUid2){
            oo::commonOprRedis('common')->delete(okeys::beAttactLock($toUid2));
        }
        oo::commonOprRedis('User')->setex(okeys::beAttactLock($toUid),$uid,10*60);//设置toUid被uid锁定关系
        oo::commonOprRedis('User')->setex(okeys::DefaultEnemy($uid),$toUid,10*60);//设置默认攻击对象
        return oo::response(1);
    }

    public function setAdjustCallBack($param){
        $uid  = oo::functions()->uint($param['uid']);
        $label  = oo::functions()->escape($param['label']);
        $device = oo::functions()->escape($param['device']);
        if(empty($uid) || empty($label) || empty($device)) {
            return oo::response(-1);
        }

        $tb   = otable::AdJustSta($uid);
        oo::commonOprDb('common')->query("DELETE FROM {$tb} WHERE uid='{$uid}'");
        oo::commonOprDb('common')->query("INSERT INTO {$tb} VALUES ('{$uid}', '{$device}', '{$device}')");
        oo::commonOprRedis('User')->delete(okeys::AdjustDeviceID($uid));
        $label = base64_encode($label);
        $id    = "android".time();
        $tb    = otable::AdJustData();
        oo::commonOprDb('common')->query("DELETE FROM {$tb} WHERE gps_adid='{$device}' OR idfa='{$device}'");
        oo::commonOprDb('common')->query("INSERT INTO {$tb} VALUES ('{$id}', '{$device}', '', 'Facebook Installs::Tony_Asia_And_0928_Fanpage pic (23845497589230479)::TH_ID_PH_VN_MY_SG (23845497589260479)::FAN PAGE PICS (23845497676540479)', 'Facebook Installs', 'Tony_Asia_And_0928_Fanpage pic (23845497589230479)', 'TH_ID_PH_VN_MY_SG (23845497589260479)', 'FAN PAGE PICS (23845497676540479)', '1602148102', 'install', '{$label}')");
        oo::commonOprRedis('User')->delete(okeys::AdjustData($device));
        return oo::response(1);
    }

    public function deleteAnnounce($param) {
        $uid  = oo::functions()->uint($param['uid']);
        oo::commonOprRedis('userinfo')->delete(okeys::announcementReward($uid));
        return oo::response(1);
    }

    /**
     * Notes:删除领奖记录
     * User: wsc
     * Time: 2021/7/30 17:02
     * @param $param
     * @return string
     */
    public function deleteInviteRewardLog($param){
        $uid  = oo::functions()->uint($param['uid']);
        $tbl = otable::userinvitegiftbag();
        oo::commonOprDb('common')->query("update {$tbl} set reward1=0,reward2=0,reward3=0,reward4=0,reward5=0 where uid={$uid} ");
        oo::commonOprRedis('common')->delete(okeys::InviteStageLog($uid));
        return oo::response(1);
    }

    /**
     * Notes:获取fb好友列表
     * @param $params
     * @return string
     */
    public function xfbFriendx($params) {
        $token = $params['token'];
        if(empty($token)){
            return oo::response(1, []);
        }
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, 'https://graph.facebook.com/v8.0/me?fields=friends.limit(200)&access_token='.$token);
        curl_setopt($curl, CURLOPT_HEADER, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $resJson = curl_exec($curl);
        curl_close($curl);
        if (empty($resJson)) {
            return oo::response(-3,[],'access token 请求失败');
        }
        $data = (array)json_decode($resJson, TRUE);
        return oo::response(1, $data);
    }

    /**
     * Notes:查询登录记录
     * User: xwy
     * Time: 2021/9/1 17:02
     * @param $param
     * @return string
     */
    public function loginLog($param){
        $uid  = oo::functions()->uint($param['uid']);
        $date = trim($param['date']);
        $time = strtotime($date);
        $time = empty($time) ? time() : $time;
        $date = date('Ymd', $time);
        $table = otable::LoginLog($date);
        $sql = "select `uid`  ,`sid`  ,`lv`  ,`version`  ,`ip`  ,`ts` ,`deviceId` ,`ab`  from {$table} where uid=".$uid;
        $res = oo::commonOprDb('statistics')->getAll($sql, 1);
        return oo::response(1, ['result' => $res]);
    }

    public function syncDir($params){
        $table = otable::activeImgNameConfig();
        if(
            empty($params['parent'])
            ||  empty($params['type'])
            ||  empty($params['name'])
        )return oo::response(-1, [], '非法操作');

        $sql = "SELECT * FROM {$table} WHERE name='{$params['parent']}'";
        $ret = oo::commonOprDb('config')->getOne($sql,1);
        if(empty($ret)){
            $now = time();
            $sql = " INSERT INTO {$table} (name, content, add_time) VALUES('{$params['parent']}', '', $now) ";
            oo::commonOprDb('config')->query($sql);

            $sql = "SELECT * FROM {$table} WHERE name='{$params['parent']}'";
            $ret = oo::commonOprDb('config')->getOne($sql,1);
        }
        $content = empty($ret['content']) ? [] : json_decode($ret['content'], true);
        $types = array_column($content, 'type');
        if(!in_array($params['type'], $types)){
            $keys = array_keys($content);
            $maxKey = max($keys);
            $content[$maxKey+1] = [
                "id" => $maxKey+1,
                "name" => $params['name'],
                "type" => $params['type'],

            ];
            $temp = json_encode($content,JSON_UNESCAPED_UNICODE);
            $sql = "UPDATE {$table} SET content = '{$temp}' WHERE id = {$ret['id']}";
            $res = oo::commonOprDb('config')->query($sql);
        }
        return oo::response(1, [$res, $temp, $content]);
    }
    public function syncTitleConf($params){
        $table = otable::activeImgNameConfig();
        if(
            empty($params['parent'])
            ||  empty($params['titleConf'])
        )return oo::response(-1, [], '非法操作');

        $sql = "UPDATE {$table} SET title_conf = '{$params['titleConf']}' WHERE name = '{$params['parent']}'";
        $res = oo::commonOprDb('config')->query($sql);
        return oo::response(1, [$res,$params]);
    }

    /**
     * Notes:水果机游戏信息设置
     * User: wsc
     * Time: 2021/9/18 10:00
     * @param $params
     * @return string
     */
    public function setFruitGameInfo($params){
        $key = okeys::userFruitGameInfo($params["uid"]);
        if($params['num']){
            oo::commonOprRedis('common')->hSet($key,'buyLimit',$params['num']);
        }
        if($params['lv']){
            oo::commonOprRedis('common')->hSet($key,'lv',$params['lv']);
        }
        if($params['exp']){
            oo::commonOprRedis('common')->hSet($key,'exp',$params['exp']);
        }
        $data = oo::commonOprRedis('common')->hGetAll($key);
        return oo::response(1, $data);
    }
    /**
     * 活动图片资源目录配置
     * @param $id
     * @return mixed
     * Created by: Hss
     * Created on: 2020/8/14 15:14
     */
    public function getActiveImgNameConfig($params){
        $tb = otable::ActiveImgNameConfig();
        $cache = oo::commonOprDb('common')->getAll("SELECT * FROM {$tb}",1);
        foreach ($cache as $k=>$v){
            $cache[$k]['content'] = json_decode($v['content'],true);
        }
        return oo::response(1, $cache);
    }

    /**
     * Notes:限时邀请活动加人
     * User: wsc
     * Time: 2021/11/26 15:04
     * @param $params
     * @return string
     */
    public function addInviteActNum($params){
        $uid =$params['uid'];
        $aid = oo::commonOprModel('activitynew')->activityLock($uid,'time_limit_invite');
        $actInfo= oo::commonOprModel('activitynew')->getActivity($aid);
        if(!$aid){
            return oo::response(-1, [],"没找到活动");
        }
        $rewardCfg = json_decode($actInfo['reward_conf'],true);
        if($params['num']){
            $tb    = otable::userinfo();
            $num = $params['num'];
            $inviteList = array_keys(oo::commonOprRedis('activity')->hGetAll(okeys::activityInviteUserList($uid,$aid)));
            $friendsStr =   implode(',', $inviteList);
            if($friendsStr){
                $w =" WHERE uid not in ({$friendsStr}) ";
            }
            $ret = oo::commonOprDb('common')->getAll("SELECT * FROM {$tb}  {$w} ORDER BY lasttime DESC LIMIT {$num}",MYSQLI_ASSOC);
            $fids = array_column($ret,'uid');
        }else if($params['fid']){
            $fids =[$params['fid']];
        }
        foreach ($fids as $fid){
            oo::commonOprModel('activitynew')->setInviteLog($aid,$uid,$fid,0);
            $res[$fid] =oo::commonOprModel('activitynew')->tryFinishIntivityAct($aid,$uid,$fid,$rewardCfg['type'],time());
        }
        $cache['list'] = oo::commonOprRedis('activity')->hGetAll(okeys::activityInviteUserList($uid,$aid));
        $cache['addRes'] = $res;
        return oo::response(1, $cache);
    }

    /**
     * Notes:设置锦标赛用户排名积分
     * User: wsc
     * Time: 2021/11/29 20:41
     * @param $params
     * @return string
     */
    public function setRankActivityNum($params){
        $uid =$params['uid'];
        $rankNum = $params['rankNum'];
        $aid = oo::commonOprModel('activitynew')->activityLock($uid,'rank');
        if(!$aid){
            return oo::response(-1, [],"没找到活动");
        }
        $roomId  = intval(oo::commonOprRedis('activity')->hGet(okeys::activityUserRankBindRoomId($aid),$uid));
        //排名
        $key = okeys::activityUserRankList($aid,$roomId);
        oo::commonOprRedis('activity')->zAdd($key,$rankNum,$uid);
        $key2 = okeys::userActivityStageRate($uid,$aid);
        oo::commonOprRedis('activity')->hSet($key2,'rate',$rankNum);
        oo::commonOprRedis('activity')->hSet($key2,'stage',1);
        $ranking  = intval(oo::commonOprRedis('activity')->zRevRank($key,$uid))+1;
        $data =["roomId"=>$roomId,"rankNum"=>$rankNum,"ranking"=>$ranking];
        return oo::response(1, $data);
    }

    /**
     * Notes:设置拼图块用户信息
     * User: wsc
     * Time: 2021/12/13 17:42
     * @param $params
     * @return string
     */
    public function setCollectJigswInfo($params){
        $uid =$params['uid'];
        $data['stage'] = $params['stage'];
        $data['sumNum'] = $params['sumNum'];
        $aid = oo::commonOprModel('activitynew')->activityLock($uid,'collect_jigsw');
        if(!$aid){
            return oo::response(0, [],"失败,没有绑定活动");
        }
        $key = okeys::ActivityCollectJigswUserStageInfo($uid,$aid);
        if($data['stage']==0){
            $res =oo::commonOprRedis('common')->delete($key);
        }else{
            $res =oo::commonOprRedis('common')->hMset($key,$data);
        }

        return oo::response(1, $data,"{$res}");
    }
    //查询用户每日数据
    public function getUserDayLimit($params){
        $uid =$params['uid'];
        $key =okeys::userDayLimit($uid);
        $ret = oo::commonOprRedis('common')->hGetAll($key);
        $data['list'] = $ret;
        $data['ts'] = oo::commonOprRedis('common')->ttl($key);
        return oo::response(1, $data);
    }
    //重置用户每日数据
    public function reSetUserDayLimit($params){
        $uid =$params['uid'];
        $key =okeys::userDayLimit($uid);
        oo::commonOprRedis('common')->delete($key);
        return oo::response(1, [],"重置成功");
    }
    /**
     * Notes:清除广告次数
     * User: xwy
     * Time: 2021/12/28 17:42
     * @param $params
     * @return string
     */
    public function clearAdInfo($params){
        $uid = intval($params['uid']);
        $key = 'PLYMCT:'.$uid;
        $res = oo::commonOprRedis('common')->delete($key);
        return oo::response(1, ['res' => $res]);
    }
    /**
     * Notes:设置用户数数分组
     * User: xwy
     * Time: 2021/12/28 17:42
     * @param $params
     * @return string
     */
    public function setShushuGroups($params){
        $uid = intval($params['uid']);
        $groups = $params['groups'];
        $groups = strtr($groups, ['，' => ',']);
        $userData = oo::commonOprModel('member')->getUserDynamicsData($uid);

//        return oo::response(1, $userData);
        $userData['groupId3'] = $groups;
        if(!$userData['userCache']){
            $userData['userCache'] = new stdClass();
        }
        $redisResult = oo::commonOprRedis('User')->setex(okeys::UserDynamicsData($uid),json_encode($userData,32),oo::redisRandomExpire(7*24*60*60));
        $redisResult1 = oo::commonOprRedis('User')->setex('UserDynamicsData:'.$uid,json_encode($userData,32),oo::redisRandomExpire(7*24*60*60));

        $table = otable::UserDynamicsData();
        $sql = "update {$table} set `groupId3`='{$groups}' where uid={$uid}";
        $mysqlResult =  oo::commonOprDb('common')->query($sql);
        return oo::response(1, ['redisResult' => $redisResult,'redisResult1' => $redisResult1, 'mysqlResult' => $mysqlResult, 'userInfo' => $userData]);
    }

    /**
     * Notes:设置用户宠物等级
     * User: xwy
     * Time: 2021/12/28 17:42
     * @param $params
     * @return string
     */
    public function setPetLv($params){
        $uid = intval($params['uid']);
        $petId = intval($params['petId']);
        $lv = intval($params['lv']);
        $cacheKey = okeys::UserPet2($uid);
        $petInfo = oo::commonOprRedis('User')->hGet($cacheKey, $petId);
        if(empty($petInfo))return oo::response(1,[],'宠物不存在');
        $petInfo = json_decode($petInfo, true);
        $petInfo['lv'] = $lv;
        oo::commonOprRedis('User')->hSet($cacheKey, $petId, json_encode($petInfo));
        return oo::response(1,['petInfo' => $petInfo],'操作成功');
    }


    public function actBindAids($params){
        $uid = intval($params['uid']);
        $actList = oo::commonOprModel('activitynew')->act_type;
        $bindList = [];
        foreach ($actList as $type => $item){
            $bindKey = okeys::userBindActivity($type, $uid);
            $aid = oo::commonOprRedis('activity')->get($bindKey);
            if($aid)$bindList[] = "活动：{$item['tips']},活动类型：{$type},绑定aid: $aid";
        }
        return oo::response(1,['info' => $bindList ],'操作成功');
    }

    public function unbindAct($params){
        $uid = intval($params['uid']);
        $type = $params['actType'];
        $bindKey = okeys::userBindActivity($type, $uid);
        $aid = oo::commonOprRedis('activity')->delete($bindKey);
        if($aid)return oo::response(1,['info' => '操作成功' ],'操作成功');
        return oo::response(-1,['info' => '操作失败' ],'操作失败');
    }
}

/**
 * 过滤
 * Class Test
 * Created by: Owen
 * Created on: 2021/1/28 12:17
 */
class Test extends TestControl {
    public function __call($name, $arguments){
        $writeList = [
            "getGoogleSubscribeToken",
            "sendCurl",
            "pushFirebase",
            "getFirebaseToken",
            "getTrafficPermitLevelInfo",
            "getUserCardInfo",
        ];
        if(IS_DEBUF || in_array($name,$writeList)){
            return parent::$name($arguments);
        }else {
            die();
        }
    }
}
