<?php
/**
 * 二维码
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author lss <lss@qq.com>
 */
namespace Home\Controller;
class Test2Controller extends BaseController {
    public function refund(){
        $mediaid='1237378768e7q8e7r8qwesafdasdfasdfaxss111';
        $wx = new \Common\Vendor\Jssdk();
        $url_img = $wx->getmedia($mediaid);
        var_dump($url_img);
    }
    public function qiniu(){
        $live= new \Common\Vendor\QiniuLive;
        $streamKey='HC1';
       /* $url=$live->RTMPPublishURL($streamKey);
        echo '推流:'.$url.'<br>';
        $url=$live->RTMPPlayURL($streamKey);
        echo '拉流:'.$url.'<br>';
        $url=$live->HLSPlayURL($streamKey);
        echo '拉流:'.$url.'<br>';
        $result=$live->liveStatus($streamKey);
        echo '状态:';print_r($result);echo '<br>';
        $result=$live->listStreams();
        echo '列表:';print_r($result);echo '<br>';

*/

        $appid = C('APPID');
        
        // $result=$live->listStreams(true,'HC',10);
        // var_dump($result['items']); echo '1211----'; die;
        $streamKeys='HC47';


        // $is_jinbo = $live->liveDisabled('xinlingshou',$streamKey,$time=-1)
        // //avthumb/m3u8/noDomain/1/vb/500k/t/10
        // $start=1543992056;
        // $end=1543992494;
        // $fname='hc47_'.$start.'_'.$end.'.mp4';
        // $notify=U('Home/LiveAnchor/notify','',true,true);
        // $pipeline='hanchao_xinlingshou';
        // $result= $live->liveSaveas($streamKeys,$fname,$start,$end,'mp4',$notify,$pipeline);

        //avthumb/m3u8/noDomain/1/vb/500k/t/10
        /*$start=1543992056;
        $end=1543992494;
        $fname='hc47_'.$start.'_'.$end.'.mp4';
        $notify=U('Home/LiveAnchor/notify','',true,true);
        $pipeline='hanchao_xinlingshou';
        $result= $live->liveSaveas($streamKeys,$fname,$start,$end,'mp4',$notify,$pipeline);
        // $notify = $live->liveSaveas($streamKeys,'','1543829310','1543829397','','',$live_config_hub);
*/      
        $result= $live->liveDisabled($streamKeys);
        // echo '<pre>回放信息:';var_dump($result);

        // $client = new \Common\Vendor\Gateway;
        // $group = '@TGS#aRAPZLQFR';
        // $counts = $client->getClientCountByGroup($group);
        // echo '测试通讯:';print_r($counts);echo '<br>';
        // 
        echo '腾讯云通信----------------';
        $im= new \Common\Vendor\Webim;  //user_sig时空扥
        $uid = 1;
        $key = 'HC62';
        $usersig=$im->getusersig($uid);

       var_dump($usersig); echo ']]]]';

       $im->set_user_sig($usersig['info']);//设置当前用户sig
       
       $ret = $im->account_import($uid);//导入用户

       var_dump($ret); echo '1231-=-=-='; 
       //$liveanchor['user_id']
       
       $gret= $im->create_group($key,$uid);

       var_dump($gret); echo '999991231-=-=-='; 

       $update = $im->account_update('汉潮会员');

       var_dump($update); echo '00001231-=-=-='; 
    }
    public function send_msg(){
        // 推送模板消息 领取微信优惠券
        $uid = 34;
        $id = 10;
        $map['id']=$uid;
        $member_info=M("Member")->where($map)->field('mobile,username,nickname')->find();
        $add_data['to']=$uid;//$member_info['mobile'];
        if($member_info['username']){
            $add_data['user_name']=$member_info['username'];
        }elseif($member_info['nickname']){
            $add_data['user_name']=$member_info['nickname'];
        }else{
            $add_data['user_name']=$member_info['mobile'];
        }
        $add_data['first'] = '领取卡券';
        $where['id']=$id;
        $add_data['coupon_type']='优惠券';
        $add_data['card_sn']=M("Coupons")->where($where)->getField('title');
        // $add_data['goods_name']=M("Coupons")->where($where)->getField('title');
        $add_data['send_time'] = date('Y-m-d H:i:s',NOW_TIME);
        $add_data['remark'] = "尊敬的会员，您获得一张卡券，请及时领取";
        $add_data['type'] = 4;
        $add_data['content'] = "请领取卡券";
        $url=U("Mobile/Index/coupons_give",array('id'=>$id,'uid'=>$uid),true,true);
        $data = sendbytheme($add_data,"MEMBER_CARE_NEW",$url);
        print_r($data);die;
    }
    public function get_min_price(){
        $goods_id=18;
        $shop_id=1;
        if(empty($goods_id))return false;
        if(empty($memberinfo))$memberinfo = checkuserauthtype();
        $name='Goods';
        $map=$tl_map=$return=array();$map['id']=$goods_id;
        $goods_info = M($name)->where($map)->field('id,shop_price,promote_id,promote_price,goods_type')->find();
        if($attr_key){
            $map=array();
            $map['goods_id']=$goods_id;
            $map['attr_key']=$attr_key;
            $shop_price=M('GoodsAttrStock')->where($map)->getField('attr_price');
            $goods_info['shop_price']=$shop_price;
        }
        //给默认值
        $return['attr_price']=$return['goods_price']=$goods_info['shop_price'];
        $return['price_type']=1;

        if(!empty($memberinfo) && $memberinfo['is_tmp'] != 1){//判断是否有会员价
            $member_map = $memberrank_map = array();
            $member_map['id'] = $memberinfo['id'];
            $rank_id = M("Member")->where($member_map)->getField('rank_id');
            $map = array();
            $map['goods_id'] = $goods_info['id'];
            $map['user_rank'] = $rank_id;
            $user_price = M('MemberPrice')->where($map)->getField('user_price');
            if($user_price){//自定义价格
                if($user_price < $return['goods_price'])$return['goods_price'] = $user_price;
            }else{
                if($rank_id){//等级折扣
                    $memberrank_map['id'] = $rank_id;
                    $rank = M("MemberRank")->where($memberrank_map)->getField("goods_price");
                    $return['goods_price']=format_decimal($goods_info['shop_price']*$rank/100);
                }
            }
            if($goods_info['shop_price']<=$return['goods_price']){
                $return['price_type']=1;
            }else {
                $return['price_type'] = 2;
            }
        }
        $act_id=0;
        if($goods_info['promote_id']){
            $tl_map['status'] = 1;
            $tl_map['id'] = $goods_info['promote_id'];
            $act_info = M('PromotAct')->where($tl_map)->order('end_time desc')->field('id,start_time,end_time,shop_id')->find();
            if(($act_info['start_time']<=NOW_TIME && $act_info['end_time']>=NOW_TIME) && ($act_info['shop_id']==0 || str_exists($act_info['shop_id'],','.$shop_id.','))){
                $act_id=$act_info['id'];
            }
        }

        if($act_id && $goods_info['promote_price']>0){//判断促销价是否有效
            if($goods_info['promote_price'] < $return['goods_price']){
                $return['goods_price'] = $goods_info['promote_price'];
                $return['price_type']=3;
                $return['act_id']=$act_id;
            }
        }
        var_dump($memberinfo);
        print_r($return);die;
        return $return;
    }
    public function matter_code(){
        $ret = D('Wxsmall/Login')->get_city_shop(114.46104,38.00407,1);//同城
        $res = D('Wxsmall/Login')->get_express_shop(114.46104,38.00407,1);//快递
        print_r($res);echo '<br>';print_r($ret);die;
    }
    
    public function posters(){
        //百度ip接口
        $ip = get_client_ip();
        $ak = C('BAIDU_WEB_KEY');
        $url = file_get_contents("http://api.map.baidu.com/location/ip?ip=$ip&ak=$ak");
        $res1 = json_decode($url,true);
        $data =$res1;
        if ($data) {
            print_r($data['content']['point']['x']);die;
        }
    }
}