<?php
defined('IN_WEB') or die('Include Error!');
/**
 * 好友相关
 */
class Friend
{
    /**
     * 添加好友
     * @return false|string
     * Created by: Owen
     * Created on: 2019/6/25 14:24
     * Description:
     */
    public function apply($param){
        $uid = oo::functions()->uint($param['uid']);
        $toUid = oo::functions()->uint($param['toUid']);
        if( empty($uid) || empty($toUid) ){
            return oo::response(-1,[],'参数错误');
        }
        $ret = oo::commonOprModel('friend')->applyFriend($uid,$toUid);
        return json_encode($ret,JSON_NUMERIC_CHECK);
    }

    /**
     * 刪除好友
     * @param $param
     * @return false|string
     * Created by: Owen
     * Created on: 2019/6/25 15:30
     * Description:
     */
    public function delete($param){
        $uid = oo::functions()->uint($param['uid']);
        $toUid = oo::functions()->uint($param['toUid']);
        if(empty($uid) || empty($toUid)){
            return oo::response(-1,[],'参数错误');
        }
        if(!funs::concurrentLock($uid,'FriendDelete:'.$toUid,2)){
            return json_encode(['code'=>-500,'msg'=>'Frequent requests']);
        }
        $ret = oo::commonOprModel('friend')->deleteFriend($uid,$toUid);
        return json_encode($ret,JSON_NUMERIC_CHECK);
    }

    public function attackList($param){
        $data = [];
        $uid = oo::functions()->uint($param['uid']);
        if (empty($uid)) {
            return json_encode(['code' => -1, 'list' => []]);
        }
        $list = oo::commonOprModel('attack')->getAttackerFriendList($uid);
        foreach ($list as $fid=>$time){
            $data = oo::commonOprModel('member')->getUserBasic($fid);
//            if($time>time()){
//                $data['protectTime'] = $time-time();
//                $data['status'] = 1;
//                $data['type'] =3;
//            }else{
                $data['protectTime'] = 0;
                $data['status'] = 0;
                $data['type'] = 1;
//            }
            $datas[] = $data;
        }
//        $datas = $datas ? array_multisort(array_column($datas,'star'),SORT_DESC,$datas) : [];
        $ret['data'] =$datas;
        $ret['code'] =1;
        return json_encode($ret);
    }
    /**
     * 好友列表 -- 攻击模式
     * @param $param
     * @return false|string
     * Created by: Owen
     * Created on: 2020/3/27 15:20
     */
    public function attackList_old($param){
        $data = [];
        $datas = array('code' => -1, 'list' => []);
        $uid = oo::functions()->uint($param['uid']);
        if (empty($uid)) {
            return json_encode($datas);
        }
        $friends = oo::commonOprModel('friend')->getUserAllFriend($uid);
        $datas['code'] =1;
        unset($datas['list']);
        if(empty($friends)){
            $datas['data'] = [];
            return json_encode($datas);
        }
        $attackCfg = oo::cfg('stealattack')['attack'];
        foreach ($friends as$k =>$v){
            $data[$k] = oo::commonOprModel('member')->getUserBasic($v);
            if($data[$k]['levelId']<=$attackCfg['minLv']){
                unset($friends[$k]);
                unset($data[$k]);
                continue;
            }
            $ttl = oo::commonOprRedis('common')->ttl(okeys::AttackLock($v));
            if($ttl>0){
                $data[$k]['protectTime'] = $ttl;
                $data[$k]['status'] = 1;
                $data[$k]['type'] =3;
            }else{
                $data[$k]['protectTime'] = 0;
                $data[$k]['status'] = 0;
                $data[$k]['type'] = 1;
            }
        }
        array_multisort(array_column($data,'star'),SORT_DESC,$data);
        $datas['data'] =$data;
        return json_encode($datas);
    }

    /**
     * 推荐好友
     * @param $param
     * @return false|string
     * Created by: Owen
     * Created on: 2020/3/27 16:08
     */
    public function recommend($param){
        $uid = oo::functions()->uint($param['uid']);
        if(empty($uid)){
            return oo::response(-1,[],'参数错误');
        }
        $ret = oo::commonOprModel('friend')->recommendFriend($uid);
        return json_encode($ret,JSON_NUMERIC_CHECK);
    }

    /**
     * 审核好友
     * @param $param
     * @return false|string
     * Created by: Owen
     * Created on: 2019/6/25 15:23
     * Description:
     */
    public function review($param){
        $uid = oo::functions()->uint($param['uid']);
        $toUid = oo::functions()->uint($param['toUid']);
        $status = oo::functions()->uint($param['status']);
        if( empty($uid) || empty($toUid) || empty($status) ){
            return oo::response(-1,[],'参数错误');
        }
        $ret = oo::commonOprModel('friend')->reviewFriend($uid,$toUid,$status);
        return json_encode($ret,JSON_NUMERIC_CHECK);
    }

    /**
     * 查询好友
     * @param $param
     * @return false|string
     * Created by: Owen
     * Created on: 2019/6/25 14:24
     * Description:
     */
    public function search($param){
        $uid = oo::functions()->uint($param['uid']);
        $toUid = oo::functions()->uint($param['toUid']);
        if( empty($uid) || empty($toUid) || $uid == $toUid){
            return oo::response(-1,[],'参数错误');
        }
        $userInfo = oo::commonOprModel('member')->getUserInfo($toUid);
        if(empty($userInfo)){
            return oo::response(-3,[],'用户不存在');
        }
        $friends = oo::commonOprModel('friend')->getUserAllFriend($uid);
        $code = 1;
        if(in_array($toUid,$friends)){
            $userInfo['isfri'] = 1;
            $code = -2;
        }else{
            $userInfo['isfri'] = 0;
        }
        $tempInfo = oo::commonOprModel('member')->getUserAssetsInfo($toUid);
        $userInfo['star'] = $tempInfo['star'];
        return oo::response($code,$userInfo,'',true);
    }

    /**
     * 召回好友
     * @param array $param
     */
    public function callbackFriend($param) {
        $uid = oo::functions()->uint($param['uid']);
        $fid = oo::functions()->uint($param['fid']);
        if(empty($uid)){
            return oo::response(-1,[],'参数错误');
        }

        if(!oo::commonOprModel('friend')->isFriend($uid, $fid)){
            return oo::response(errorCode::NOT_MY_FRIEND);
        }

        $assetsInfo = oo::commonOprModel('member')->getUserAssetsInfo($fid);
        if(empty($assetsInfo)){
            return oo::response(errorCode::USER_NOT_EXISTS);
        }

        //触发召回活动召回
//        oo::commonOprModel('callback')->callbackFriend($uid, $fid);

        $conf = oo::commonOprModel('friend')->callbackConf();
        //好友等级太低，不能召回
        if($assetsInfo['levelId'] < $conf['level']){
            return oo::response(errorCode::CALLBACK_FRIEND_LEVEL_LOW);
        }

        $userInfo = oo::commonOprModel('member')->getUserInfo($fid);

        //召回好友只支持fb玩家
        if(empty($userInfo['isFb'])){
            return oo::response(errorCode::CALLBACK_FRIEND_ONLY_FB);
        }

        if($userInfo['lasttime'] + 15 * 24 * 3600 > time()){
            return oo::response(errorCode::CALLBACK_FRIEND_DAYS_LIMIT);
        }
        $time = oo::commonOprModel('friend')->getCallBackTime($uid, $fid);
        if($time && $time >= time()){
            return oo::response(errorCode::CALLBACK_FRIEND_DAY_ALREADY);
        }
        $info = oo::commonOprModel('friend')->callbackFriend($uid, $fid);

        /**
         * 通行证任务11 召回好友
         */
        oo::commonOprModel('activitynew')->addTrafficPermitNum($uid,11);

        return oo::response(1, $info, '', true);
    }

    /**
     * 当前已领取的奖励进度信息
     */
    public function friendProgressRewardInfo($param) {
        $uid = oo::functions()->uint($param['uid']);
        if(empty($uid)){
            return oo::response(errorCode::REQUEST_PARAM_ERROR);
        }
        $step = (int)oo::commonOprRedis('common')->get(okeys::friendProgressReward($uid));
        $friends = oo::commonOprModel('friend')->getUserAllFriend($uid);
        $list = oo::commonOprModel('friend')->friendsProgressRewardConf();

        foreach($list as $key => $v){
            $coins = 0;
            if(!empty($v['reward']['coins'])){
                $coins = oo::commonOprModel('goods')->getGoodCoins($uid, $v['reward']['coins']['coins']);
                $coins = intval($coins * $v['reward']['coins']['bet']);
                unset($list[$key]['reward']['coins']);
            }
            $coinsAdded = false;
            foreach($v['reward']['props'] as $k => $val){
                if($val['propsId'] == 14){
                    $coinsAdded = true;
                }
                if($coins > 0 && $val['propsId'] == 14){
                    $val['num'] += $coins;
                    $list[$key]['reward']['props'][$k] = $val;
                    break;
                }
            }
            if(!$coinsAdded && $coins > 0){
                $list[$key]['reward']['props'][] = ['propsId' => 14, 'num' => $coins];
            }
        }

        $data = [
            'my' => ['step' => $step, 'num' => count($friends)],
            'list' => $list,
        ];
        return oo::response(1, $data, '', true);
    }

    /**
     * 获取好友进度奖励
     */
    public function friendsProgressReward($param) {
        $uid = oo::functions()->uint($param['uid']);
        if(empty($uid)){
            return oo::response(errorCode::REQUEST_PARAM_ERROR);
        }
        $info = oo::commonOprModel('friend')->getUserFriendsProgress($uid);
        if(empty($info['reward'])){
            return oo::response(errorCode::REPET_REWRD);
        }
        $friends = oo::commonOprModel('friend')->getUserAllFriend($uid);
        if(count($friends) < $info['num']){
            return oo::response(errorCode::RATE_NOT_RNOUGH);
        }
        //更新进度标志
        oo::commonOprRedis('common')->incr(okeys::friendProgressReward($uid));
        //领取好友数量进度奖励
        $resAttr = oo::commonOprModel('member')->getAttr();
        $resource = [];
        foreach($info['reward'] as $k => $v){
            if(isset($k, $resAttr)){
                $resource[$k] = $v;
            }
            if($k !== 'props'){
                continue;
            }
            foreach ($v as $kk => $val){
                oo::commonOprModel('member')->sendReward($uid,$val['propsId'],$val['num'],53,"好友数量进度奖励:".($info['step']+1),[],$val);
            }
        }
        if($resource){
            oo::commonOprModel('member')->optProperty($uid,$resource,'+',53,'好友数量进度奖励:'.($info['step']+1));
        }

        return oo::response(1, $info['reward'], '', true);
    }

    /**
     * 获取召回领取奖励信息
     */
    public function callBackRewardInfo($param) {
        $uid = oo::functions()->uint($param['uid']);
        if(empty($uid)){
            return oo::response(-1,[],'参数错误');
        }
        $info = oo::commonOprModel('friend')->getCallbackListInfo($uid);
        return oo::response(1, $info, '', true);
    }

    /**
     * 领取召回奖励
     */
    public function callbackReward($param) {
        $uid = oo::functions()->uint($param['uid']);
        $fid = oo::functions()->uint($param['fid']);
        if(empty($uid)){
            return oo::response(-1,[],'参数错误');
        }
        $info = oo::commonOprModel('friend')->getCallbackListInfo($uid);
        if(empty($info['list'])){
            return oo::response(-1,[],'没有成功召回的好友');
        }

        if(empty($info['reward'])){
            return oo::response(-1,[],'没有可领取的奖励');
        }
        //删除召回奖励缓存
        oo::commonOprRedis('common')->delete(okeys::callBackReward($uid));

        //发放奖励奖
        $resAttr = oo::commonOprModel('member')->getAttr();
        $resource = [];

        foreach($info['reward'] as $k => $v){
            if(isset($k, $resAttr)){
                $resource[$k] = $v;
            }
            if($k !== 'props'){
                continue;
            }

            foreach ($v as $kk => $val){
                oo::commonOprModel('member')->sendReward($uid,$val['propsId'],$val['num'],52,'召回奖励:'.json_encode($info['list']),[],$val);
            }
        }
        if($resource){
            oo::commonOprModel('member')->optProperty($uid,$resource,'+',52,'召回奖励:'.json_encode($info['list']));
        }

        return oo::response(1, $info['reward'], '', true);
    }

    /**
     * 拉取自己好友列表&礼物信息
     * @param $param
     * @return false|string
     * Created by: Owen
     * Created on: 2020/3/27 17:32
     */
    public function giftList($param){
        $uid = oo::functions()->uint($param['uid']);
        if(empty($uid)){
            return oo::response(-1,[],'参数错误');
        }
        $page = oo::functions()->uint($param['page']);
        $page = $page < 1 ? 0 : $page;
        return oo::commonOprModel('friend')->getFriendAndGiftList($uid, $page);
    }

    /**
     * 给单个玩家赠送道具
     * @param $param
     * @return false|string
     * Created by: Owen
     * Created on: 2020/3/27 16:19
     */
    public function sendGift($param){
        $uid   = oo::functions()->uint($param['uid']);
        $toUid = oo::functions()->uint($param['toUid']);
        $gid   = oo::functions()->uint($param['gid']);
        if(empty($uid) || empty($toUid) || empty($gid)){
            return oo::response(-1,[],'参数错误');
        }
        return oo::commonOprModel('friend')->sendGift($uid,$toUid,$gid);
    }

    /**
     * 领取好友赠送的道具
     * @param $param
     * @return false|string
     * Created by: Owen
     * Created on: 2020/3/27 15:52
     */
    public function receiveGift($param){
        $uid   = oo::functions()->uint($param['uid']);
        $toUid = oo::functions()->uint($param['toUid']);
        $gid   = oo::functions()->uint($param['gid']);//类型id
        if(empty($uid) || empty($toUid) || empty($gid)){
            return oo::response(-1,[],'参数错误');
        }
        return  oo::commonOprModel('friend')->receiveGift($uid,$toUid,$gid);
    }

    /**
     * 一键批量赠送好友
     * @param $param
     * @return false|string
     * Created by: Owen
     * Created on: 2020/3/27 16:26
     */
    public function receiveGifts($param){
        $uid = oo::functions()->uint($param['uid']);
        $gid = oo::functions()->uint($param['gid']);
        if (empty($uid) || empty($gid)) {
            return oo::response(-1,[],"参数错误");
        }
        if(!funs::concurrentLock($uid,"receiveGifts{$gid}",30)){
            return oo::response(-2,[],'频繁操作');
        }
        return oo::commonOprModel('friend')->sendAndReceiveGifts($uid,$gid);
    }

    /**
     * 赠送卡片
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2020/3/30 15:26
     */
    public function sendCard($param){
        $uid  = oo::functions()->uint($param['uid']);
        $toUid= oo::functions()->uint($param['toUid']);
        $cids = oo::functions()->escape($param['cid']);
        $time = oo::functions()->uint($param['time']);
        $sign = oo::functions()->escape($param['sign']);
        $serverSign = md5($uid.'#2019$'.$cids.'superant'.$toUid.$time.'&^%');
        $redisSign = oo::commonOprRedis('common')->get('CARDSENTO:'.$uid);
        if($sign != $serverSign || $redisSign == $sign){
            return oo::response(-1,[],'参数错误');
        }
        if(isset($param['rewardId'])){
            $rewardData = oo::commonOprRedis('common')->get(okeys::ShareRewardIdData($param['rewardId']));
            if(!empty($rewardData)){
                if(isset($rewardData['recTimestamp'])){
                    if(in_array($param['timestamp'],$rewardData['recTimestamp'])){
                        return oo::response(-3,[],'分享领取上限');
                    }
                }
            }else{
                return oo::response(-1,[],'分享过期');
            }
            $toUidFriends = oo::commonOprModel('friend')->getUserAllFriend($toUid);
            if(!in_array($uid,$toUidFriends)){
                return oo::response(-2,[],'对方不是你的好友');
            }
        }
        $cids = explode(',',$cids);
        if(empty($cids)){
            return oo::response(-1,[],'参数错误');
        }
        return oo::commonOprModel('card')->sendCardToFriend($uid,$toUid,$cids);
    }

    /**
     * 领取好友赠送的卡片
     * @param $param
     * @return false|string
     * Created by: Owen
     * Created on: 2020/3/28 15:50
     */
    public function receiveCard($param){
        $uid   = oo::functions()->uint($param['uid']);
        $toUid = oo::functions()->uint($param['toUid']);
        $cid   = oo::functions()->uint($param['cid']);
        if(empty($uid) || empty($toUid)){
            return oo::response(-1,[],'参数错误');
        }
        $all = oo::functions()->uint($param['getAll']);
        return oo::commonOprModel('card')->receiveCardFromFriend($uid,$toUid,$all,$cid);
    }

    /**
     * 同步Fb好友
     * @param $param
     * @return false|string
     * Created by: Owen
     * Created on: 2020/3/27 17:28
     */
    public function SynchronizeFb($param){
        $uid = oo::functions()->uint($param['uid']);;
        if (empty($uid)) {
            return oo::response(-1,[],'参数错误');
        }
        if(!funs::concurrentLock($uid,"SynchronizeFb",120)){
            return oo::response(-500,[],'限制频繁请求');
        }
        $accessToken = isset($param['access_token']) ? $param['access_token'] : '';
        if (empty($accessToken)) {
            return oo::response(-2,[],'安装了app的好友列表为空');
        }
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, 'https://graph.facebook.com/v8.0/me?fields=friends.limit(2000)&access_token='.$accessToken);
        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 请求失败');
        }
        $appList = array();
        $resArray = json_decode($resJson, TRUE);
        if (!empty($resArray['friends']['data'])) {
            foreach ($resArray['friends']['data'] as $tmpUser) {
                !empty($tmpUser['id']) && $appList[] = $tmpUser['id'];
            }
        }
        if (empty($appList)) {
            return oo::response(-4,[],'应用好友为空');
        }

        $accountList = [];
        $result = oo::commonOprModel('member')->getAccountMulti(['keytype'=>'i','keyname'=>'siteuid','keylist'=> $appList],['isiteuid'=> 0,'iuid'=>0],$accountList);
        if ($result <= 0) {
            return oo::response(-5,[],'反向查询uid失败');
        }
        $uidList = array();
        foreach ($accountList as $v) {
            $toUid = intval($v['uid']);
            if($toUid == $uid){
               continue;
            }
            $uidList[] = $toUid;
        }
        $friends = array();
        $result = oo::commonOprModel('friend')->getUserFriends($uid, $friends);
        if ($result < 0) {
            return oo::response(-6,[],'获取用户好友数据失败');
        }

        if(!empty($friends['poker'])) {
            $oldArray = explode(',', $friends['poker']);
            //$deleteArr= explode(',', $friends['notapper']);
            //防止poker字段和notapper里面有相同的值，这样下面删除数据时候就不会把牌友给删除了
            //foreach ($oldArray as &$val) {
            //    $val  = intval($val);
            //    if($k = array_search($val, $deleteArr) !== FALSE) {
            //        unset($deleteArr[$k]);
            //    }
            //}
            //$newPokerArray = array_merge($uidList, $oldArray);
            //if (!empty($deleteArr)) {
            //    $newPokerArray = array_diff($newPokerArray, $deleteArr);
            //}
            $newPokerArray = array_merge($uidList, $oldArray);
            $uidList = array_unique($newPokerArray);
        }
        $updateUFRet = oo::commonOprModel('friend')->updateUserFriends($uid, array('sisapper' => json_encode($accountList), 'spoker' => implode(',', $uidList), 'iupdatetime' => time()));
        if ($updateUFRet < 0) {
            $array['code'] = -7;
            $array['line'] = __LINE__;
            $array['ttcCode'] = $updateUFRet;
            return json_encode($array);
        }
        return oo::response(1);
    }

    /**
     * 分享添加好友
     * @param $param
     * @return false|string
     * Created by: Owen
     * Created on: 2019/8/15 17:14
     * Description:
     */
    public function shareAdd($param){
        $uid = oo::functions()->uint($param['uid']);
        $toUid = oo::functions()->uint($param['toUid']);
        if(empty($uid) || empty($toUid)){
            return oo::response(-1);
        }
        $userInfo = [];
        $argument['keylist'] = [$uid,$toUid];//批量获得参数
        $ret = oo::commonOprModel('member')->getUserInfoMulti($argument, $userInfo);
        if($ret != 1){
            return oo::response(-2,[],'用户ID异常');
        }

        $uidFriends = oo::commonOprModel('friend')->getUserAllFriend($uid);
        if(in_array($toUid,$uidFriends)){
            return oo::response(1,[],'已是好友');
        }

        $toUidFriends = oo::commonOprModel('friend')->getUserAllFriend($toUid);
        if(count($toUidFriends)>=200 || count($uidFriends)>=200){
            return oo::response(-3,[],'好友上限');
        }
        oo::commonOprModel('friend')->addUserFriend($uid,$toUid);
        return oo::response(1);
    }

    /**
     * 获取邀请ID
     * @param $param
     * @return string
     */
    public function inviteId($param) {
        $uid   = oo::functions()->uint($param['uid']);
        if(empty($uid)) {
            return oo::response(-1);
        }
        $data['code'] = 1;
        $data['u'] = $uid;
        $data['id'] = oo::commonOprModel('invite')->getInviteID($uid);
        $data['sk'] = oo::commonOprModel('invite')->getInviteSkey($uid, $data['id']);
        return json_encode($data);
    }

    /**
     * 上报邀请好友记录
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2020/3/27 17:47
     */
    public function inviteRecord($param){
        $uid = oo::functions()->uint($param['uid']);
        $data = isset($param['data']) ? oo::functions()->escape($param['data']) : '';
        $list = isset($param['list']) ? oo::functions()->escape($param['list']) : '';
        $source = isset($param['source']) ? oo::functions()->escape($param['source']) : '';
        $requestid = isset($param['requestid']) ? oo::functions()->escape($param['requestid']) : '';
        if( empty($uid) || empty($data) || empty($list) || empty($source) || empty($requestid) ){
            return oo::response(-1);
        }
        return oo::commonOprModel('invite')->report($param);
    }

    /**
     * 邀请成功
     * @param $param
     * @return false|string
     * Created by: Owen
     * Created on: 2020/3/27 17:47
     */
    public function inviteSuccess($param){
        $uid = oo::functions()->uint($param['uid']);
        $data = isset($param['data']) ? oo::functions()->escape($param['data']) : '';
        if( empty($uid) || empty($data) ){
            return oo::response(-1);
        }
        return oo::commonOprModel('invite')->update($param);
    }

    /**
     * 获取邀请进度和奖励信息
     */
    public function getInviateProcessInfo(&$param){
        $uid   = oo::functions()->uint($param['uid']);
        $isNew = oo::functions()->uint($param['isNew']);
        if(empty($uid)){
            return oo::response(-1,[],'参数错误');
        }
        unset($param['superKey']);
        $tmp = oo::commonOprModel('invite')->getInviteProgressInfo($uid,0,true);
        if($isNew){
            foreach ($tmp as $key=>$row){
                if($row['isNew'] == 0){
                    unset($tmp[$key]);
                }
            }
            $tmp = array_values($tmp);
        }
        return oo::response(1, $tmp);
    }

    /**
     * 可领取邀请奖励列表
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2021/2/19 11:17
     */
    public function getNewInviteList($param){
        $uid   = oo::functions()->uint($param['uid']);
        if(empty($uid)){
            return oo::response(-1,[],'参数错误');
        }
        $tmp = oo::commonOprModel('invite')->getInviteProgressInfo($uid,0,true);
        foreach ($tmp as $key=>$row){
            if($row['isNew'] == 0){
                unset($tmp[$key]);
            }
        }
        $data = array_values($tmp);
        if(oo::compareVersion(oo::commonOprModel('user')->getUserVersion($uid),'1.8.4')){
            $spinsNum = oo::commonOprModel('invite')->inviteConfig($uid);
            $data = [
                "list"   => $data,
                "bindFb" => oo::commonOprModel('invite')->getInviteeBindFbList($uid),
                "extraFb"=> oo::commonOprModel('invite')->InviteeBindFbExtra($uid),
                "reward" => [
                    'facebook'=>$spinsNum['bind'],
                    'base'    =>$spinsNum['base'],
                    'extra'   =>$spinsNum['extra'],
                ],
            ];
        }
        return oo::response(1, $data);
    }

    /**
     * 删除被邀请方绑定FB弹框
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2021/3/26 18:41
     */
    public function delInviteeBindFb($param){
        $uid   = oo::functions()->uint($param['uid']);
        if(empty($uid)){
            return oo::response(-1,[],'参数错误');
        }
        oo::commonOprRedis('User')->delete(okeys::InviteeFbReward($uid));
        return oo::response(1);
    }


    /**
     * 1.7.5新版邀请进度奖励
     */
    public function gainInviteProcessReward($param) {
        $uid = oo::functions()->uint($param['uid']);
        $fid = oo::functions()->uint($param['fid']);
        $num = oo::functions()->uint($param['num']);
        if(empty($uid) || empty($num)){
            return oo::response(-1,[],'参数错误');
        }

        $ret = oo::commonOprModel('invite')->gainInviteReward($uid, $fid, $num);
        if(!$ret){
            return oo::response(errorCode::LIMIT_NOT_RNOUGH);
        }

        $data = oo::commonOprModel('invite')->getInviteProgressInfo($uid, $fid);
        $reward = [];
        if(isset($data['reward']['spins'])){
            $reward = ['propsId' => 15, 'num' => $data['reward']['spins']];
        }elseif(isset($data['reward']['diamond'])){
            $reward = ['propsId' => 22, 'num' => $data['reward']['diamond']];
        }elseif(isset($data['reward']['money'])){
            $reward = ['propsId' => 14, 'num' => $data['reward']['money']];
        }
        $data['reward'] = $reward;
        $data['status'] = $data['can_get'];
        unset($data['can_get']);
        //返回下一阶数据
        return oo::response(1,$data,'领取成功');
    }
}
