<?php
defined('IN_WEB') or die('Include Error!');
/**
 * 商品相关
 */
class ModelGoods{
    /**
     * 疯狂的上帝商品
     * Created by: Owen
     * Created on: 2019/7/3 18:36
     * Description:
     */
    public function getCrazyGodGood($uid,$sid=''){
        $tb          = otable::goodsCrazy();
        $goodsInfo   = oo::commonOprDb('payment')->getAll("SELECT * FROM {$tb} WHERE gstatus=1 ORDER BY gid",MYSQLI_ASSOC);
        $property    = oo::commonOprModel('member')->getUserAssetsInfo($uid);
        $level       = intval($property['levelId']);
        $out         = [];
        $coinsArr    = self::getCoinsDataByLevel($level);
        $version     = oo::commonOprModel('user')->getUserVersion($uid);
        $giftArr     = self::getGiftConfig();
        $configArr   = self::getGoodTransformConfig();
        $exclusionGid= [];
        $cardChest   = self::getCardChestConfig($level);
        $iosSubArr   = ['subscription01'=>'sub01','subscription02'=>'sub03','subscription03'=>'sub02'];
        $point = oo::commonOprModel('newvip')->getUserCurPoint($uid); //积分
        $sid = empty($sid)?oo::getDefinedSid($uid):$sid;
        foreach ($goodsInfo as $row) {
            if(in_array($row['gid'],$exclusionGid)){
                continue;
            }
            if($row['gid']>720&&$row['gid']<=750){//超级连环礼包(动态数据)剔除
                continue;
            }
            if($row['gid']>750&&$row['gid']<=760){//四选一活动礼包(动态数据)剔除
                continue;
            }
            if($row['gtype']==27){//召回礼包(动态数据)剔除
                continue;
            }
            if($row['gid']>760&&$row['gid']<=790){//超级连环礼包2(动态数据)剔除
                continue;
            }
            $row['gsku'] = ($sid == 1) ? self::googleSkuToAndroid($row['gsku']) : self::googleSkuToIosSku($row['gsku']);
            $goodTypeId  = $row['gtype'];
            $config = $configArr[$goodTypeId];
            if(empty($config)){
               continue;
            }
            $temp   = [];
            foreach ($config['character'] as $key=>$value){
                $temp[$key] = $row[$value];
                $key=='price'    && $temp[$key] = '$'.$row[$value];
                $key=='priceNum' && $temp[$key] = (string)$row[$value];
            }
            if($goodTypeId == 2){
                $coinsType = explode('.',$row['gsku']);
                $temp['num'] = $coinsArr[end($coinsType)];
            }else if($goodTypeId == 3){
                //1.14版本魔幻宝箱重新上架，使用金币购买
                if(oo::compareVersion($version,'1.8.3') && $row['gid'] == 304){
                    continue; //下架魔幻宝箱
                }
                if(!oo::compareVersion($version,'1.8.4') && $row['gid'] == 306){
                    continue; //旧每日宝箱不上架
                }
                $cardInfo = explode(',',$row['gbaseReward']);
                $temp['cardNum'] = $cardInfo[0];
                if(in_array($row['gid'], [306])){
                    $temp['price']   = '$'.$row['gprice'];
                }else{
                    $temp['price']   = $cardChest[$row['gsku']];
                }
                if($row['gid'] == 306){
                    $chestInfo = oo::commonOprModel('activitynew')->getDailyChest($uid);
                    if(empty($chestInfo)){
                        continue;
                    }
                }else{
                    $cardStarArr     = array_filter(oo::commonOprModel('card')->getCardTypeProConfig($row['gimg']));
                    $cardStar = $key = array_search(max($cardStarArr),$cardStarArr);
                    unset($cardStarArr[$key]);
                    $cardStar2= array_search(max($cardStarArr),$cardStarArr);
                    if($cardStar < $cardStar2){
                        $t = $cardStar2;
                        $cardStar2 = $cardStar;
                        $cardStar  = $t;
                    }
                    $temp['cardStar']= [$cardStar2,$cardStar];
                }
                $temp['priceNum']= (string)$temp['price'];
                if(in_array($row['gid'], [304, 306])){
                    $temp['sku'] = $row['gsku'];
                }
            }else if($goodTypeId == 6){
                if($row['gid'] == 601){
                    $temp['coin'] = intval($coinsArr['coins03']*0.5);
                    $temp['coins']= intval($coinsArr['coins03']*0.5);
                    if(oo::compareVersion($version,'1.7.3')){
                        if(!empty($row['goriginReward'])) {
                            $props = json_decode($row['goriginReward'], true);
                            foreach ($props as $p) {
                                $p['propsId'] == 22 && $temp['diamond'] = $p['num'];
                                if($p['propsId'] == 14){
                                    $temp['coin'] = $temp['coins'] = $p['num'];
                                }
                            }
                        }
                    }
                    $temp['spin'] = $row['gbaseReward'];
                    $temp['spins']= $row['gbaseReward'];
                }else if($row['gid'] == 602){
                    $props  = json_decode($row['gbaseReward'],true);
                    foreach ($props as $p){
                        $p['propsId'] == 14 && $temp['coin'] = $p['num'] && $temp['coins'] = $p['num'];
                        $p['propsId'] == 15 && $temp['spin'] = $p['num'] && $temp['spins'] = $p['num'];
                        $p['propsId'] == 22 && $temp['diamond'] = $p['num'];
                    }
                    $temp['props'] = $props;
                }
                $temp['coupon'] = 1;

                $couponVer = oo::commonOprRedis('common')->get(okeys::firstPayCouponVersion());
                $couponVer = empty($couponVer) ? '1.9.1' : $couponVer; //1.9.1版本临时隐藏首冲优惠券商品
                if(in_array($row['gid'], [601, 602]) && oo::compareVersion($version, $couponVer)){
                    $temp['coupon'] = 0;
                }
            }else if($goodTypeId == 7){
                if(in_array($row['gid'],[710,711,712])){
                    $chainGiftFlag = true;
                    $aid = oo::commonOprModel('activitynew')->activityLock($uid,'chain_gift');
                    if($aid){
                        $chainGiftFlag = false;
                        oo::commonOprRedis('activity')->setex(okeys::bindChainGift($uid),$aid,86400*3);//连环礼包绑定活动id
                        $ret = oo::commonOprModel('activitynew')->getChainGiftConf($uid,$aid,$row['gid']);
                        foreach ($ret['props'] as $k=>$p){
                            $pConf = oo::commonOprModel('props')->getChestData($uid,$p['propsId']);
                            $pConf && $ret['props'][$k]['reward'] = $pConf;
                        }
                        $temp['coin']     =$ret['coin'];
                        $temp['coins']    =$ret['coin'];
                        $temp['spin']     =$ret['spin'];
                        $temp['spins']    =$ret['spin'];
                        $temp['props']    =$ret['props'];
                        $temp['price']    =$ret['price'];
                        $temp['priceNum'] =$ret['priceNum'];
                        $temp['sku']      =($sid == 1) ? self::googleSkuToAndroid($ret['sku']) : self::googleSkuToIosSku($ret['sku']);
                        $temp['giftType'] =$ret['giftType'];
                        $temp['gMax']     =$ret['gMax'];
                    }
                    if($chainGiftFlag){
                        if(strpos($row['gsku'],'com.sa') !== false || strpos($row['gsku'],'newsky.cc') !== false||strpos($row['gsku'],'com.gworld') !== false||strpos($row['gsku'],'gworld.cc') !== false){
                            $gsku    = $row['gsku'];
                            $price   = '$'.$row['gprice'];
                            $priceNum= (string)$row['gprice'];
                        }else{
                            $gsku    = "";
                            $price   = json_decode($row['gsku'],true);
                            $priceNum= empty($price['bet']) ? 0 : (string)$coinsArr[$price['coins']] * $price['bet'];
                        }
                        $reward = json_decode($row['gbaseReward'],true);
                        $coin   = $coinsArr[$reward['coins']['coins']] * $reward['coins']['bet'];
                        $temp['coin']     =intval($coin);
                        $temp['coins']     =intval($coin);
                        $temp['spin']     =intval($reward['spins']);
                        $temp['spins']     =intval($reward['spins']);
                        $temp['props']    =$reward['props'];
                        $temp['price']    =$price;
                        $temp['priceNum'] =$priceNum;
                        $temp['sku']      =$gsku;
                        $temp['giftType'] =1;
                        $temp['gMax']     =$row['gMax'];
                    }

                }else{
                    $reward = $giftArr[$row['gid']];
                    $temp['coin']     = intval($coinsArr[$reward['coins']] * $reward['coinsBet']);
                    $temp['coins']     = intval($coinsArr[$reward['coins']] * $reward['coinsBet']);
                    $temp['giftType'] = $reward['giftType'];
                    if(oo::compareVersion($version,'1.7.3')){
                        if(!empty($row['goriginReward'])){
                            $props  = json_decode($row['goriginReward'],true);
                            foreach ($props as $p){
                                $p['propsId'] == 22 && $temp['diamond'] = $p['num'];
                            }
                        }
                        foreach ([14=>'coins',15=>'spins',22=>'diamond'] as $k => $v){
                            $propsTemp = [];
                            $propsTemp['propsId'] = $k;
                            if(is_array($temp[$v]) && $k == 14){
                                $propsTemp['value'] = $temp[$v];
                                $propsTemp['num'] = 0;
                                $temp['props'][] = $propsTemp;
                            }else{
                                if(!empty($temp[$v])){
                                    $propsTemp['num'] = $temp[$v];
                                    $temp['props'][] = $propsTemp;
                                }
                            }
                        }
                    }
                }
            }else if($goodTypeId == 8){
                if($sid == 2){
                    foreach ($iosSubArr as $subscription=>$sub){
                        if(strpos($row['gsku'],$subscription) !== false){
                            $temp['sku'] = str_replace($subscription,$sub,$row['gsku']);
                            break;
                        }
                    }
                }
            }else if($goodTypeId == 9){
                $temp['goods']  = json_decode($row['gbaseReward'],true);
                $temp['buyNum'] = intval(oo::commonOprRedis('User')->hGet(okeys::GoodBuyNum(),$uid.'_'.$row['gid']));
            }else if($goodTypeId == 10){
                $temp['goods']  = json_decode($row['gbaseReward'],true);
            }else if($goodTypeId == 14){
                continue;
            }else if($goodTypeId == 15){
                //if(oo::compareVersion($version,'1.7.8')){
                //    $noEnoughArr = [1502];
                //}else{
                //    $noEnoughArr = [1501,1502,1511];
                //}
                $noEnoughArr = [1501,1502,1511];
                if(in_array($row['gid'],$noEnoughArr)){
                    //根据玩家积分、等级 返回对应商品
                    $keyType = $row['gid']==1501?'money':($row['gid'] == 1502 ? 'spins' : 'diamond');
                    if($row['gid'] == 1502 || ($point < 1000 && in_array($row['gid'], [1501, 1511]))){
                        $configNotEnough = oo::commonOprModel('config')->getShopNotEnoughConfig($keyType);
                    }else{
                        $configNotEnough = [];
                    }
                    $gid = 0;
                    foreach($configNotEnough as $rowTemp){
                        if($rowTemp['point'] <= $point && $rowTemp['level'] <= $level){
                            $gid = $rowTemp['gid'];
                        }
                    }
                    if($gid){
                        $goodInfoTemp = self::getGoodsInfoByGid($gid);
                        if(!empty($goodInfoTemp)){
                            $temp['sku'] = ($sid == 1) ? self::googleSkuToAndroid($goodInfoTemp['gsku']) : self::googleSkuToIosSku($goodInfoTemp['gsku']);
                            $temp['price'] = '$'.$goodInfoTemp['gprice'];
                            $temp['priceNum'] = (string)$goodInfoTemp['gprice'];
                            $temp['addRatio'] = $goodInfoTemp['gaddRatio'];
                            $row['gbaseReward'] = $goodInfoTemp['gbaseReward'];
                            oo::commonOprRedis('common')->setex(okeys::shopNotEnoughLog($uid,$row['gid']),json_encode($goodInfoTemp),1 * 24 * 3600);
                        }
                    }
                }

                if(in_array($row['gid'],[1501,1503,1504,1505,1506,1507])){
                    $rewardTemp  = json_decode($row['gbaseReward'],true);
                    $coins       = self::getGoodCoinsByLevelId($level + 1,$rewardTemp['coins']['coins']);
                    $temp['num'] = $coins * $rewardTemp['coins']['bet'];
                }else if(in_array($row['gid'],[1502,1508,1509,1510,1511,1512,1513,1514,1515])){
                    $temp['num'] = $row['gbaseReward'];
                }
            }else if($goodTypeId == 17){
                $temp['isoSku']  = self::googleSkuToIosSku($row['gsku']);
                $temp['giftType']= $row['gtype']==17?5:$row['gtype'];
            }else if(in_array($goodTypeId,[16,18,19])){
                $reward = json_decode($row['gbaseReward'],true);
                $temp['isoSku']  = self::googleSkuToIosSku($row['gsku']);
                $temp['giftType']= 5;
                $temp['coins']   = oo::commonOprModel('goods')->getGoodCoins($uid,$reward['coins']['coins']) * $reward['coins']['bet'];
                $temp['spins']   = $reward['spins'];
                $temp['props']   = $reward['props'];
                if($goodTypeId == 16){
                    $propsTemp = $reward['props'];
                    foreach ($propsTemp as $key=>$p){
                        $pConfig = oo::commonOprModel('props')->getChestData($uid,$p['propsId']);
                        if($pConfig){
                            $propsTemp[$key]['value'] = $pConfig;
                        }
                    }
                    $temp['props'] = $propsTemp;
                }
                if(oo::compareVersion($version,'1.7.3')){
                    foreach ([14=>'coins',15=>'spins',22=>'diamond'] as $k => $v){
                        $props = [];
                        $props['propsId'] = $k;
                        if(!empty($temp[$v])){
                            $props['num']    = $temp[$v];
                            $temp['props'][] = $props;
                        }
                    }
                }
                $temp['coins']   = [
                    'gid'  => oo::commonOprModel('config')->coinsToGid($reward['coins']['coins']),
                    'bet'  => $reward['coins']['bet']
                ];
                if(oo::compareVersion($version,'1.8.1') && !in_array($row['gid'],[1760,1761,1762])){
                    $temp['coins']['bet'] = 0;
                }
                if(in_array($goodTypeId,[16,18])){
                    unset($temp['coins'],$temp['spins'],$temp['diamond']);
                }else if($goodTypeId == 19){
                    $temp['spins'] = 0;
                    $temp['diamond'] = 0;
                }
            }else if($goodTypeId == 21){
                if(!oo::compareVersion($version,'1.7.1')){
                    continue;
                }
                $temp['diamond'] = $row['gbaseReward'];
            }else if($goodTypeId == 26){ //基金活动动态修改gsku和pirce
                $actInfo = oo::commonOprModel('activitynew')->getBindActivity($uid,'fund',true);
                if(!empty($actInfo)&&!empty($actInfo['reward_conf'])){
                    $rewardConf = (array)json_decode($actInfo['reward_conf'], true);
                    $rfmGroup = oo::commonOprModel('config')->getUserGroupIdByCid($uid, 2);
                    foreach($rewardConf as $ext){
                        if(!isset($ext['data'][$row['gid']])){
                            continue;
                        }
                        $groupConf = !empty($ext['gid']) ? $ext['gid'] : [];
                        if(in_array(0, $groupConf) || (in_array($rfmGroup, $ext['gid']))){
                            $temp['sku']       = ($sid == 1)?self::googleSkuToAndroid($ext['data'][$row['gid']]['gsku']):self::googleSkuToIosSku($ext['data'][$row['gid']]['gsku']);
                            $temp['price']     = $ext['data'][$row['gid']]['gprice'];
                            $temp['gdiscount'] = $ext['data'][$row['gid']]['gdiscount'];
                        }
                    }
                }
            } elseif ($goodTypeId == 23) { //体力存钱罐
                $safeGoodsInfo = oo::commonOprModel('activitynew')->getSpinSafeGoodsByGid($uid, $row['gid']);
                if($safeGoodsInfo){ //体力存钱罐商品过期保存,防止活动过期
                    oo::commonOprModel('activitynew')->setActivityShopCache(
                        okeys::activityShopCache($uid, 'spin_safe-'.$row['gid']), $safeGoodsInfo
                    );
                }

                if(!empty($safeGoodsInfo)){
                    $safeSku      = $safeGoodsInfo['sku'];
                    $temp['sku']   = ($sid == 1)?self::googleSkuToAndroid($safeSku):self::googleSkuToIosSku($safeSku);
                    $temp['priceNum'] = $safeGoodsInfo['price'];
                    $temp['price'] = '$'.$safeGoodsInfo['price'];
                }
            }
            $temp['sku'] == "" && $temp['sku'] = NULL;
            $temp['priceDollar'] = '$';
            $temp['priceCurrencyCode'] = 'USD';
            if($config['name'] == 'gift' && !empty($row['gShowGroup'])){
                $temp['rfmGroup'] = array_filter(array_map('intval', explode(',', $row['gShowGroup'])));
            }
            $out[$config['name']][] = $temp;
        }

        //钻石兑换物品列表
        if(oo::compareVersion($version,'1.7.1')){
            $out['diamondExchanges'] = oo::commonOprModel('diamond')->getShopDiamondWithClient($uid);
        }
        if(oo::compareVersion($version,'1.8.0')){
            $diamonNotEnoughEx = oo::commonOprModel('diamond')->notEnoughWithClient($uid);
            $out['diamondCoin'] = $diamonNotEnoughEx['diamondCoin'];
            $out['diamondSpin'] = $diamonNotEnoughEx['diamondSpin'];
        }
        //新连环礼包
        if(oo::compareVersion($version,'1.7.4')){
            $out['super_serial_pack'] = array_values(oo::commonOprModel('activitynew')->getCGGoodList($uid,'super_serial_pack'));
        }
        //新连环礼包2
        if(oo::compareVersion($version,'1.10.1')){
            $out['super_serial_pack2'] = array_values(oo::commonOprModel('activitynew')->getCGGoodList($uid,'super_serial_pack2'));
        }
        //二选一活动
        if(oo::compareVersion($version,'1.8.1')){
            $out['chooseOne'] = oo::commonOprModel('activitynew')->getChooseOneGoods($uid);
        }
        //1+1礼包
        if(oo::compareVersion($version,'1.14.1')){
            $out['onePlusGift'] = oo::commonOprModel('activitynew')->getActivityGoods($uid,"one_plus_gift");
        }
        //安全惊喜礼包
        if(oo::compareVersion($version,'1.14.1')){
            $out['safeSurprise'] = oo::commonOprModel('activitynew')->getActivityGoods($uid,"safe_surprise");
        }
        //四选一活动礼包
//        if(oo::compareVersion($version,'1.8.4')){
//            $out['easter_egg'] = oo::commonOprModel('activitynew')->getEasterGiftBag($uid);
//        }
        /**
         * 大转盘根据等级展现给用户
         */
        $out['wheel'] = $this->turnDataByLevelId($level,$out['wheel']);

        if(!empty($out['fund'])){
            //基金活动设置活动动态缓存,发货时更新动态价格
            oo::commonOprModel('activitynew')->setActivityShopCache(okeys::activityShopCache($uid, 'fund'), $out['fund']);
        }

        return ['code'=>1,'list'=>$out,'recomment'=>self::getRecommend($uid)];
    }

    /**
     * 大转盘根据等级展现给用户
     * @param $level
     * @param $data
     * @return mixed
     * Created by: Owen
     * Created on: 2021/1/12 19:35
     */
    public function turnDataByLevelId($level,$data){
        $between = [
            ["levelId"=>20, "gid"=>501],
            ["levelId"=>40, "gid"=>502],
            ["levelId"=>70, "gid"=>503],
            ["levelId"=>100,"gid"=>504],
            ["levelId"=>200,"gid"=>505],
            ["levelId"=>300,"gid"=>506],
        ];
        $action = ["levelId"=>300,"gid"=>506];
        foreach ($between as $row){
            if($level <= $row["levelId"]){
                $action = $row;
                break;
            }
        }
        $tmp = array_column($data,null,'gid');
        $out = [];
        $out[] = $tmp[500];
        $out[] = $tmp[$action['gid']];
        return $out;
    }


    /**
     * 资源不足道具列表(1501,1502,1511)
     * @param int $uid
     */
    public function getextraCrazyGodGood($uid, $sid = ''){
        $gids = [1501,1502,1511];
        $tb   = otable::goodsCrazy();
        $sql  = "SELECT * FROM {$tb} WHERE gstatus=1 AND gid IN (".implode(",", $gids).") ORDER BY gtype";
        $goodsInfo   = oo::commonOprDb('payment')->getAll($sql,MYSQLI_ASSOC);
        $property    = oo::commonOprModel('member')->getUserAssetsInfo($uid);
        $level       = intval($property['levelId']);
        $out         = [];
        $coinsArr    = self::getCoinsDataByLevel($level);
        $configArr   = self::getGoodTransformConfig();
        $point = oo::commonOprModel('newvip')->getUserCurPoint($uid); //积分
        $sid = empty($sid)?oo::getDefinedSid($uid):$sid;
        foreach ($goodsInfo as $row) {
            $row['gsku'] = ($sid == 1) ? self::googleSkuToAndroid($row['gsku']) : self::googleSkuToIosSku($row['gsku']);
            $goodTypeId  = $row['gtype'];
            $config = $configArr[$goodTypeId];
            if(empty($config)){
               continue;
            }
            $temp   = [];
            foreach ($config['character'] as $key=>$value){
                $temp[$key] = $row[$value];
                $key=='price'    && $temp[$key] = '$'.$row[$value];
                $key=='priceNum' && $temp[$key] = (string)$row[$value];
            }
            //根据玩家积分、等级 返回对应商品
            $keyType = $row['gid']==1501?'money':($row['gid'] == 1502 ? 'spins' : 'diamond');

            if($row['gid'] == 1502 || ($point < 1000 && in_array($row['gid'], [1501, 1511]))){
                $configNotEnough = oo::commonOprModel('config')->getShopNotEnoughConfig($keyType);
            } else {
                $configNotEnough = [];
            }
            $gid = 0;
            foreach($configNotEnough as $rowTemp){
                if($rowTemp['point'] <= $point && $rowTemp['level'] <= $level){
                    $gid = $rowTemp['gid'];
                }
            }
            if($gid){
                $goodInfoTemp = self::getGoodsInfoByGid($gid);
                if(!empty($goodInfoTemp)){
                    $temp['sku'] = ($sid == 1) ? self::googleSkuToAndroid($goodInfoTemp['gsku']) : self::googleSkuToIosSku($goodInfoTemp['gsku']);
                    $temp['price'] = '$'.$goodInfoTemp['gprice'];
                    $temp['priceNum'] = (string)$goodInfoTemp['gprice'];
                    $temp['addRatio'] = $goodInfoTemp['gaddRatio'];
                    $row['gbaseReward'] = $goodInfoTemp['gbaseReward'];
                    oo::commonOprRedis('common')->setex(okeys::shopNotEnoughLog($uid,$row['gid']),json_encode($goodInfoTemp),1 * 24 * 3600);
                }
            }

            if(in_array($row['gid'],[1501])){
                $rewardTemp  = json_decode($row['gbaseReward'],true);
                $coins       = self::getGoodCoinsByLevelId($level + 1,$rewardTemp['coins']['coins']);
                $temp['num'] = $coins * $rewardTemp['coins']['bet'];
            }else if(in_array($row['gid'],[1502,1511])){
                $temp['num'] = $row['gbaseReward'];
            }
            $temp['sku'] == "" && $temp['sku'] = NULL;
            $temp['priceDollar'] = '$';
            $temp['priceCurrencyCode'] = 'USD';
            $out[$config['name']][] = $temp;
        }
        return ['code'=>1,'list'=>$out];
    }


    /**
     * Notes:通过类型获取商品(局部刷新商品配置)
     * User: wsc
     * Time: 2020/11/27 16:13
     * @param $uid
     * @param $type
     * @return array
     */
    public function getGoodListByType($uid,$type){
        $out =[];
        $sid = oo::getDefinedSid($uid);
        if($type=='super_serial_pack'){
            $out['super_serial_pack'] = array_values(oo::commonOprModel('activitynew')->getCGGoodList($uid,$type));
        }else if($type=='super_serial_pack2'){
            $out['super_serial_pack2'] = array_values(oo::commonOprModel('activitynew')->getCGGoodList($uid,$type));
        }else if($type=='chain_gift'){
            $aid = oo::commonOprModel('activitynew')->activityLock($uid,'chain_gift');
            if($aid){
                foreach ([710,711,712] as $gid){
                    oo::commonOprRedis('activity')->setex(okeys::bindChainGift($uid),$aid,86400*3);//连环礼包绑定活动id
                    $ret = oo::commonOprModel('activitynew')->getChainGiftConf($uid,$aid,$gid);
                    foreach ($ret['props'] as $k=>$p){
                        $pConf = oo::commonOprModel('props')->getChestData($uid,$p['propsId']);
                        $pConf && $ret['props'][$k]['reward'] = $pConf;
                    }
                    $temp['coin']     =$ret['coin'];
                    $temp['coins']    =$ret['coin'];
                    $temp['spin']     =$ret['spin'];
                    $temp['spins']    =$ret['spin'];
                    $temp['props']    =$ret['props'];
                    $temp['price']    =$ret['price'];
                    $temp['priceNum'] =$ret['priceNum'];
                    $temp['sku']      =($sid == 1) ? self::googleSkuToAndroid($ret['sku']) : self::googleSkuToIosSku($ret['sku']);
                    $temp['giftType'] =$ret['giftType'];
                    $temp['gMax']     =$ret['gMax'];
                    $temp['priceDollar'] = '$';
                    $temp['priceCurrencyCode'] = 'USD';
                    $out['gift'][] = $temp;
                }
            }
        }else if($type=='easter_egg'){
            $out['easter_egg'] = oo::commonOprModel('activitynew')->getEasterGiftBag($uid);
        }else if($type=='chooseOne'){
            $out['chooseOne'] = oo::commonOprModel('activitynew')->getChooseOneGoods($uid);
        }else if($type=='onePlusGift'){
            $out['onePlusGift'] = oo::commonOprModel('activitynew')->getActivityGoods($uid,"one_plus_gift");
        }else if($type=='safeSurprise'){
            $out['safeSurprise'] = oo::commonOprModel('activitynew')->getActivityGoods($uid,"safe_surprise");
        }
        return ['code'=>1,'list'=>$out,'recomment'=>[]];
    }

    ///**
    // * 苹果过审商品sku临时替换
    // * @return string
    // */
    //public function appleSkuReplace($sku) {
    //    $sku = str_replace('sa.crazygod','astak.crazyspin',$sku);
    //    $sku = str_replace('gworld.cc','astak.crazyspin',$sku);
    //    switch($sku){
    //        case 'com.astak.crazyspin.gift01': //9.99
    //            $sku = 'com.astak.crazyspin.coins03';
    //            break;
    //        case 'com.astak.crazyspin.gift02': //19.99
    //            $sku = 'com.astak.crazyspin.coins04';
    //            break;
    //        case 'com.astak.crazyspin.gift04': //4.99
    //            $sku = 'com.astak.crazyspin.coins02';
    //            break;
    //        case 'com.astak.crazyspin.gift07': //1.99
    //            $sku = 'com.astak.crazyspin.coins01';
    //            break;
    //        case 'com.astak.crazyspin.gift09': //49.99
    //            $sku = 'com.astak.crazyspin.coins05';
    //            break;
    //    }
    //    return $sku;
    //}

    /**
     * 谷歌Sku转换成Ios Sku
     * @param $sku
     * @return mixed
     * Created by: Owen
     * Created on: 2020/8/17 14:38
     */
    public function googleSkuToIosSku($sku){
        $sku = str_replace('sa.crazygod', 'gworld.cc', $sku);
        return str_replace('gworld.cc','astak.crazyspin',$sku);
    }

    /**
     * 安卓旧版sku转新版
     * @param $sku
     * @return mixed
     * Created by: Owen
     * Created on: 2021/5/7 15:09
     */
    public function googleSkuToAndroid($sku){
        return str_replace('sa.crazygod','gworld.cc',$sku);
    }
    
    /**
     * 获取礼包配置
     * @return array
     * Created by: Owen
     * Created on: 2020/8/17 14:46
     */
    public function getGiftConfig(){
        return [
            701 => ['coins'=>'coins02','coinsBet'=>0.5 ,'giftType'=>1],
            702 => ['coins'=>'coins02','coinsBet'=>1   ,'giftType'=>1],
            703 => ['coins'=>'coins02','coinsBet'=>2   ,'giftType'=>1],
            704 => ['coins'=>'coins01','coinsBet'=>0.25,'giftType'=>2],
            705 => ['coins'=>'coins02','coinsBet'=>0.25,'giftType'=>2],
            706 => ['coins'=>'coins03','coinsBet'=>0.25,'giftType'=>2],
            707 => ['coins'=>'coins01','coinsBet'=>1.8 ,'giftType'=>3],
            708 => ['coins'=>'coins02','coinsBet'=>1.4 ,'giftType'=>3],
            709 => ['coins'=>'coins03','coinsBet'=>1.2 ,'giftType'=>3],
        ];
    }

    /**
     * 获取等级coins值
     * @param $level
     * @return array
     * Created by: Owen
     * Created on: 2020/8/17 14:56
     */
    public function getCoinsDataByLevel($level){
        $coins = ["coins01","coins02","coins03","coins04","coins05","coins06"];
        $coinsArr = [];
        foreach ($coins as $coin) {
            $coinsArr[$coin] = self::getGoodCoinsByLevelId($level,$coin);
        }
        return $coinsArr;
    }

    /**
     * 获取商城卡片宝箱价格
     * @param $level
     * @return array|mixed
     * Created by: Owen
     * Created on: 2020/8/17 15:09
     */
    public function getCardChestConfig($level){
        $cacheKey = okeys::CardChestConfig();
        $cache    = oo::commonOprRedis('Config')->hGet($cacheKey,$level);
        if(empty($cache)){
            $tb = otable::CardChest();
            $cache = oo::commonOprDb('payment')->getOne("SELECT * FROM {$tb} WHERE levelId={$level} LIMIT 1",MYSQLI_ASSOC);
            oo::commonOprRedis('Config')->hSet($cacheKey,$level,json_encode($cache));
        }else{
            $cache = json_decode($cache,true);
        }
        return $cache;
    }


    public function getGoodTransformConfig(){
        return [
            1=>[
                'name'     =>'spin',
                'character'=>[
                    'tagType'   =>'gattribute',
                    'gid'       =>'gid',
                    'id'        =>'gimg',
                    'addRatio'  =>'gaddRatio',
                    'num'       =>'gbaseReward',
                    'originalNum'=>'goriginReward',
                    'price'     =>'gprice',
                    'priceNum'  =>'gprice',
                    'sku'       =>'gsku',
                    'ggameid'   =>'ggameid',
                    'gdiscount' =>'gdiscount',
                ]
            ],
            2=>[
                'name'     =>'coin',
                'character'=>[
                    'tagType'  =>'gattribute',
                    'id'       =>'gimg',
                    'gid'      =>'gid',
                    'addRatio' =>'gaddRatio',
                    'price'    =>'gprice',
                    'priceNum' =>'gprice',
                    'sku'      =>'gsku',
                    'ggameid'  =>'ggameid',
                    'gdiscount'=>'gdiscount',
                ]
            ],
            3=>[
                'name'     =>'chest',
                'character'=>[
                    'id'        =>'gimg',
                    'gid'       =>'gid',
                    'title'     =>'gname_en',
                    'ggameid'   =>'ggameid',
                    'gdiscount' =>'gdiscount',
                ]
            ],
            5=>[
                'name'     =>'wheel',
                'character'=>[
                    'id'        =>'gimg',
                    'gid'       =>'gid',
                    'addRatio'  =>'gaddRatio',
                    'num'       =>'gbaseReward',
                    'price'     =>'gprice',
                    'priceNum'  =>'gprice',
                    'sku'       =>'gsku',
                    'ggameid'   =>'ggameid',
                    'gdiscount' =>'gdiscount',
                ]
            ],
            6=>[
                'name'     =>'firstPay',
                'character'=>[
                    'id'        =>'gimg',
                    'gid'       =>'gid',
                    'price'     =>'gprice',
                    'priceNum'  =>'gprice',
                    'sku'       =>'gsku',
                    'ggameid'   =>'ggameid',
                    'gdiscount' =>'gdiscount',
                ]
            ],
            7=>[
                'name'     =>'gift',
                'character'=>[
                    'id'         =>'gimg',
                    'gid'        =>'gid',
                    'ggameid'    =>'ggameid',
                    'gdiscount'  =>'gdiscount',
                    'addRatio'   =>'gaddRatio',
                    'spin'       => 'gbaseReward',
                    'spins'      => 'gbaseReward',
                    'price'      => 'gprice',
                    'priceNum'   => 'gprice',
                    'sku'        => 'gsku',
                ]
            ],
            8=>[
                'name'     =>'subscription',
                'character'=>[
                    'id'        =>'gimg',
                    'gid'       =>'gid',
                    'price'     =>'gprice',
                    'priceNum'  =>'gprice',
                    'sku'       =>'gsku',
                    'ggameid'   =>'ggameid',
                    'gdiscount' =>'gdiscount',
                    'addRatio'  =>'gaddRatio',
                ]
            ],
//            9=>[
//                'name'     =>'festival',
//                'character'=>[
//                    'id'       =>'gimg',
//                    'gid'      =>'gid',
//                    'price'    =>'gprice',
//                    'priceNum' =>'gprice',
//                    'sku'      =>'gsku',
//                    'ggameid'  =>'ggameid',
//                    'gdiscount'=>'gdiscount',
//                    'addRatio' =>'gaddRatio',
//                    'maxNum'   =>'gMax',
//                ]
//            ],
            10=>[
                'name'     =>'monthly',
                'character'=>[
                    'id'       =>'gimg',
                    'gid'      =>'gid',
                    'price'    =>'gprice',
                    'priceNum' =>'gprice',
                    'sku'      =>'gsku',
                    'ggameid'  =>'ggameid',
                    'gdiscount'=>'gdiscount',
                    'addRatio' =>'gaddRatio',
                ]
            ],
//            11=>[
//                'name'     =>'bless',
//                'character'=>[
//                    'id'       =>'gimg',
//                    'gid'      =>'gid',
//                    'price'    =>'gprice',
//                    'priceNum' =>'gprice',
//                    'sku'      =>'gsku',
//                    'ggameid'  =>'ggameid',
//                    'gdiscount'=>'gdiscount',
//                    'addRatio' =>'gaddRatio',
//                ]
//            ],
            12=>[
                'name'     =>'luckyDraw',
                'character'=>[
                    'id'       =>'gimg',
                    'gid'      =>'gid',
                    'price'    =>'gprice',
                    'priceNum' =>'gprice',
                    'sku'      =>'gsku',
                    'ggameid'  =>'ggameid',
                    'gdiscount'=>'gdiscount',
                    'addRatio' =>'gaddRatio',
                ]
            ],
            13=>[
                'name'     =>'petFeed',
                'character'=>[
                    'id'      =>'gimg',
                    'gid'     =>'gid',
                    'price'   =>'gprice',
                    'priceNum'=>'gprice',
                    'sku'     =>'gsku',
                    'num'     =>'gbaseReward',
                    'expNum'  =>'goriginReward',
                    'ggameid' =>'ggameid',
                ]
            ],
            14=>[
                'name'     =>'petExp',
                'character'=>[
                    'id'      =>'gimg',
                    'gid'     =>'gid',
                    'price'   =>'gprice',
                    'priceNum'=>'gprice',
                    'sku'     =>'gsku',
                    'num'     =>'gbaseReward',
                    'ggameid' =>'ggameid',
                ]
            ],
            15=>[
                'name'     =>'special',
                'character'=>[
                    'tagType'  =>'gattribute',
                    'id'       =>'gimg',
                    'gid'      =>'gid',
                    'addRatio' =>'gaddRatio',
                    'num'      =>'gbaseReward',
                    'price'    =>'gprice',
                    'priceNum' =>'gprice',
                    'sku'      =>'gsku',
                    'ggameid'  =>'ggameid',
                    'gdiscount'=>'gdiscount',
                ]
            ],
            16=>[
                'name'     =>'gift',
                'character'=>[
                    'gid'      =>'gid',
                    'pid'      =>'gpid',
                    'price'    =>'gprice',
                    'priceNum' =>'gprice',
                    'sku'      =>'gsku',
                    'ggameid'  =>'ggameid',
                    'gdiscount'=>'gdiscount',
                    'addRatio' =>'gaddRatio',
                    'expire'   =>'gExpire',
                    'max'      =>'gMax',
                ]
            ],
            17=>[
                'name'     =>'gift',
                'character'=>[
                    'gid'      =>'gid',
                    'pid'      =>'gpid',
                    'price'    =>'gprice',
                    'priceNum' =>'gprice',
                    'sku'      =>'gsku',
                    'ggameid'  =>'ggameid',
                    'gdiscount'=>'gdiscount',
                    'addRatio' =>'gaddRatio',
                    'expire'   =>'gExpire',
                    'max'      =>'gMax',
                ]
            ],
            18=>[
                'name'     =>'gift',
                'character'=>[
                    'gid'      =>'gid',
                    'pid'      =>'gpid',
                    'price'    =>'gprice',
                    'priceNum' =>'gprice',
                    'sku'      =>'gsku',
                    'ggameid'  =>'ggameid',
                    'gdiscount'=>'gdiscount',
                    'addRatio' =>'gaddRatio',
                    'expire'   =>'gExpire',
                    'max'      =>'gMax',
                ]
            ],
            19=>[
                'name'     =>'gift',
                'character'=>[
                    'gid'      =>'gid',
                    'pid'      =>'gpid',
                    'price'    =>'gprice',
                    'priceNum' =>'gprice',
                    'sku'      =>'gsku',
                    'ggameid'  =>'ggameid',
                    'gdiscount'=>'gdiscount',
                    'addRatio' =>'gaddRatio',
                    'expire'   =>'gExpire',
                    'max'      =>'gMax',
                ]
            ],
            20=>[
                'name'     =>'pass',
                'character'=>[
                    'gid'      =>'gid',
                    'pid'      =>'gpid',
                    'price'    =>'gprice',
                    'priceNum' =>'gprice',
                    'sku'      =>'gsku',
                    'ggameid'  =>'ggameid',
                    'gdiscount'=>'gdiscount',
                    'addRatio' =>'gaddRatio',
                    'expire'   =>'gExpire',
                    'max'      =>'gMax',
                ]
            ],
//            21=>[
//                'name'     =>'diamond',
//                'character'=>[
//                    'tagType'   =>'gattribute',
//                    'gid'       =>'gid',
//                    'id'        =>'gimg',
//                    'pid'       =>'gpid',
//                    'addRatio'  =>'gaddRatio',
//                    'num'       =>'gbaseReward',
//                    'originalNum'=>'goriginReward',
//                    'price'     =>'gprice',
//                    'priceNum'  =>'gprice',
//                    'sku'       =>'gsku',
//                    'ggameid'   =>'ggameid',
//                    'gdiscount' =>'gdiscount',
//                ]
//            ],
//            22=>[
//                'name'     =>'super_serial_pack',
//                'character'=>[
//                    'id'         =>'gimg',
//                    'gid'        =>'gid',
//                    'ggameid'    =>'ggameid',
//                    'gdiscount'  =>'gdiscount',
//                    'addRatio'   =>'gaddRatio',
//                    'price'      => 'gprice',
//                    'priceNum'   => 'gprice',
//                    'sku'        => 'gsku',
//                ]
//            ]
            23=>[
                'name'     =>'safeBox',
                'character'=>[
                    'tagType'   =>'gattribute',
                    'gid'       =>'gid',
                    'id'        =>'gimg',
                    'pid'       =>'gpid',
                    'price'     =>'gprice',
                    'priceNum'  =>'gprice',
                    'sku'       =>'gsku',
                    'ggameid'   =>'ggameid',
                    'gdiscount' =>'gdiscount',
                ]
            ],
            24=>[
                'name'     =>'passLevel',
                'character'=>[
                    'gid'      =>'gid',
                    'pid'      =>'gpid',
                    'price'    =>'gprice',
                    'priceNum' =>'gprice',
                    'sku'      =>'gsku',
                    'ggameid'  =>'ggameid',
                    'gdiscount'=>'gdiscount',
                    'addRatio' =>'gaddRatio',
                    'expire'   =>'gExpire',
                    'max'      =>'gMax',
                ]
            ],
            26=>[
                'name'     =>'fund',
                'character'=>[
                    'gid'      =>'gid',
                    'pid'      =>'gpid',
                    'price'    =>'gprice',
                    'priceNum' =>'gprice',
                    'sku'      =>'gsku',
                    'ggameid'  =>'ggameid',
                    'gdiscount'=>'gdiscount',
                    'addRatio' =>'gaddRatio',
                    'expire'   =>'gExpire',
                    'max'      =>'gMax',
                ]
            ], 
        ];
    }

    /**
     * 推荐商品
     * @param $uid
     * @return array
     * Created by: Owen
     * Created on: 2020/4/23 11:43
     */
    public function getRecommend($uid){
        $recommend = oo::commonOprModel('readconfig')->getSysCon('Shop',"recommend");
        $recommend = json_decode($recommend,true);
        $i = 1;
        $out = [];
        array_multisort(array_column($recommend,'sort'),SORT_ASC,$recommend);
        foreach ($recommend as $row){
            if($row['open'] == 0 || $i>3){
                continue;
            }
            if($row['id'] == 1){
                if(oo::commonOprModel('member')->getUserFirstPayStatus($uid)){
                    if(oo::commonOprModel('activity')->activityLock($uid,1,true)){
                        continue;
                    }
                }
            }
            //if($row['id'] == 4){
            //    $isVip = oo::commonOprModel('newvip')->checkVip($uid);
            //    if($isVip && $isVip['isFreeing'] == 0){
            //        continue;
            //    }
            //}

            if($row['id'] == 2){
                if(oo::commonOprRedis('common')->get(okeys::promotion($uid,703))){
                    if(oo::commonOprModel('activity')->activityLock($uid,5,true)){
                        continue;
                    }
                }
            }
            $out[] = $row;
            $i++;
        }
        return $out;
    }

    /**
     * 获得coins的值
     * @param $uid
     * @param $coins
     * @return int
     * Created by: Owen
     * Created on: 2019/11/6 14:59
     */
    public function getGoodCoins($uid,$coins){
        $property = oo::commonOprModel('member')->getUserAssetsInfo($uid);
        $level = intval($property['levelId']);
        return self::getGoodCoinsByLevelId($level,$coins);
    }

    /**
     * 根据等级获得coins的值
     * @param $level
     * @param $coins
     * @return int
     * Created by: Owen
     * Created on: 2019/12/17 14:41
     */
    public function getGoodCoinsByLevelId($level,$coins){
        $cacheKey = okeys::GoodsCoin($level,$coins);
        $cache    = oo::commonOprRedis('config')->get($cacheKey);
        if($cache){
            return $cache;
        }
        $tb = otable::goodsCoin();
        $sql = "SELECT * FROM {$tb} WHERE gsku='com.gworld.cc.{$coins}' AND levelId={$level}";
        $coinInfo = oo::commonOprDb('payment')->getOne($sql,MYSQLI_ASSOC);
        $num = $coinInfo['num']??0;
        oo::commonOprRedis('config')->setex($cacheKey,$num,7*24*60*60);
        return $num;
    }

    /**
     * 获取限时特惠
     * @param $uid
     * @return array
     * Created by: Owen
     * Created on: 2020/8/17 11:06
     */
    public function specialOffer($uid){
        $giftArr = [
            704 => ['coins'=>'coins01','coinsBet'=>0.25,'giftType'=>2],
            705 => ['coins'=>'coins02','coinsBet'=>0.25,'giftType'=>2],
            706 => ['coins'=>'coins03','coinsBet'=>0.25,'giftType'=>2],
        ];
        $userPayNum = oo::commonOprModel('payment')->getUserTotalPayNum($uid);
        if($userPayNum > 10){
            $gid = 706;
        }else if($userPayNum > 0){
            $gid = 705;
        }else{
            $gid = 704;
        }
        $sid = oo::getDefinedSid($uid);
        $reward = $giftArr[$gid];
        $money  = intval(self::getGoodCoins($uid,$reward['coins']) * $reward['coinsBet']);
        $tb  = otable::goodsCrazy();
        $sql = "SELECT * FROM {$tb} WHERE gid={$gid} limit 1";
        $goodsInfo = oo::commonOprDb('payment')->getOne($sql,1);
        $temp = [];
        $goodsInfo['gsku'] = ($sid==1)?$goodsInfo['gsku']:str_replace('sa.crazygod','newsky.cc',$goodsInfo['gsku']);
        $temp[] = [
            'id'         =>$goodsInfo['gimg'],
            'gid'        =>$goodsInfo['gid'],
            'coin'       =>$money,
            'coins'      =>$money,
            'spin'       =>intval($goodsInfo['gbaseReward']),
            'spins'      =>intval($goodsInfo['gbaseReward']),
            'price'      =>'$'.$goodsInfo['gprice'],
            'sku'        =>$goodsInfo['gsku'],
            'ggameid'    =>$goodsInfo['ggameid'],
            'gdiscount'  =>$goodsInfo['gdiscount'],
            'priceDollar'=>'$',
            'priceCurrencyCode'=>'USD',
            'addRatio'   =>$goodsInfo['gaddRatio'],
        ];
        return $temp;
    }

    /**
     * 限时特惠分段
     * @param $uid
     * @return int
     * Created by: Owen
     * Created on: 2020/8/17 11:05
     */
    public function specialOfferLv($uid){
        $lv = 1;
        $tb = otable::payment($uid);
        $sql = "SELECT SUM(pusd) AS sum FROM {$tb} WHERE uid={$uid} AND status=2";
        $ret = oo::commonOprDb('payment')->getOne($sql,MYSQLI_ASSOC);
        if(!empty($ret)){
            if($ret['sum'] > 0){
                $lv = 2;
            }
            if($ret['sum'] > 10){
                $lv = 3;
            }
        }
        return $lv;
    }

    /**
     * 通过订单号返回对应的商品名称
     * @param int $order
     * @return bool
     * Created by: Owen
     * Created on: 2020/8/17 11:05
     */
    public function getGpidByOrderIdCrazyGod($order = 0){
        $stable = otable::summarylist();
        $sql = " SELECT sl_gid FROM {$stable} WHERE sl_orderid = '{$order}' LIMIT 1";
        $dbData = oo::commonOprDb('payment')->getOne($sql, MYSQLI_ASSOC);
        if (empty($dbData)) {
            return false;
        }
        $sl_gid = $dbData['sl_gid'];
        $gtable = otable::goodsCrazy();
        $gsql = " SELECT gsku FROM {$gtable} WHERE gid = {$sl_gid} LIMIT 1 ";
        $goodsDbData = oo::commonOprDb('payment')->getOne($gsql, MYSQLI_ASSOC);
        if (empty($goodsDbData)) {
            return false;
        }
        return $goodsDbData['gsku'];
    }

    /**
     * 根据uid和gpid(商品名称)获取订单ID
     * @param int $uid
     * @param int $gpid
     * @return bool
     * Created by: Owen
     * Created on: 2020/8/17 11:06
     */
    public function getOrderByUidAndgpidCrazyGod($uid = 0, $gpid = 0){
        if(empty($uid) || empty($gpid)) {
            return false;
        }
        $goodsTable = otable::goodsCrazy();
        $sql_goods = " SELECT gid FROM {$goodsTable} WHERE gpid = '{$gpid}' AND gchannel = 3";
        $retGoodsData = oo::commonOprDb('payment')->getOne($sql_goods, 1);
        oo::logs()->debug3(array('retGoodsData' => $retGoodsData, 'sql_goods' => $sql_goods), 'getOrderByUidAndgpid.log');
        if (empty($retGoodsData)) {
            return false;
        }
        $gid = $retGoodsData['gid'];//商品ID
        $table = otable::payment($uid);
        $sql = " SELECT order_id FROM {$table} WHERE uid = {$uid} AND gid = {$gid} AND status = 1 ORDER BY order_time DESC ";
        $retpayData = oo::commonOprDb('payment')->getOne($sql, 1);
        oo::logs()->debug3(array('retpayData' => $retpayData, 'sql' => $sql), 'getOrderByUidAndgpid.log');
        if (empty($retpayData)) {
            return false;
        }
        $orderId = $retpayData['order_id'];
        return $orderId;
    }

    /**
     * 通过商品id获取商品的信息
     * @param $gid
     * @return mixed
     */
    public function getGoodsInfoByGid($gid){
        $table = otable::goodsCrazy();
        $sql = "SELECT * FROM {$table} WHERE gid = {$gid} LIMIT 1 ";
        $ret = oo::commonOprDb('payment')->getOne($sql, 1);
        return $ret;
    }

    /**
     * 用户商店横条数据
     * @param $uid
     * @return string
     * Created by: Owen
     * Created on: 2021/1/22 12:15
     */
    public function getFreeBarData($uid){
        $conf   = json_decode(oo::commonOprModel('readconfig')->getSysCon('Shop',"freeBar"),true);
        $reward = $conf['reward'];
        foreach ($reward as &$row){
            $pConf = oo::commonOprModel('props')->getChestData($uid,$row['propsId']);
            if($pConf){
                $row['value'] = $pConf;
            }
        }
        $data   = [
            'isOpen' => $conf['isOpen'],
            'time'   => time() + intval(oo::commonOprRedis('User')->ttl(okeys::UserFreeBarTtl($uid))),
            'reward' => $reward,
        ];
        return oo::response(1,$data);
    }

    /**
     * 领取商店横条奖励
     * @param $uid
     * @return string
     * Created by: Owen
     * Created on: 2021/1/22 12:28
     */
    public function rewardFreeBar($uid){
        if(oo::commonOprRedis('User')->ttl(okeys::UserFreeBarTtl($uid)) > 0){
            return oo::response(errorCode::FREE_BAR_TTL_ERROR);
        }
        $conf   = json_decode(oo::commonOprModel('readconfig')->getSysCon('Shop',"freeBar"),true);
        $reward = $conf['reward'];
        foreach ($reward as &$row){
            oo::commonOprModel('member')->sendReward($uid,$row['propsId'],$row['num'],117,'商店横条',[],$row);
        }
        $interval = intval($conf['interval'] ?? 24 *60*60);
        oo::commonOprRedis('User')->setex(okeys::UserFreeBarTtl($uid),1,$interval);
        $time   = time() + $interval;
        $data   = [
            'isOpen' => $conf['isOpen'],
            'time'   => $time,
            'reward' => $reward,
        ];
        oo::commonOprRedis('Usercache')->zAdd(okeys::PushCrontab("FreeBar"),$time,$uid);
        return oo::response(1,$data);
    }
}
