<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;
/**
 * 匹配 与 匹配的收费
 */
class Match extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    //视频通话记录
    public function video_log(){
        if($this->auth->gender == 0){
            $list = Db::name('user_match_video_log')->alias('log')
                ->field('log.id,log.user_id as the_user_id,log.call_minutes,log.createtime,user.avatar,user.nickname')
                ->join('user','log.user_id = user.id','LEFT')
                ->where('log.to_user_id' , $this->auth->id)
                ->order('log.id desc')->autopage()->select();

        }else{
            $list = Db::name('user_match_video_log')->alias('log')
                ->field('log.id,log.to_user_id as the_user_id,log.call_minutes,log.createtime,user.avatar,user.nickname')
                ->join('user','log.to_user_id = user.id','LEFT')
                ->where('log.user_id' , $this->auth->id)
                ->order('log.id desc')->autopage()->select();
        }

        $list = list_domain_image($list,['avatar']);
        $this->success(1,$list);
    }

    //语音通话记录
    public function audio_log(){
        if($this->auth->gender == 0){
            $list = Db::name('user_match_audio_log')->alias('log')
                ->field('log.id,log.user_id as the_user_id,log.call_minutes,log.createtime,user.avatar,user.nickname')
                ->join('user','log.user_id = user.id','LEFT')
                ->where('log.to_user_id' , $this->auth->id)
                ->order('log.id desc')->autopage()->select();

        }else{
            $list = Db::name('user_match_audio_log')->alias('log')
                ->field('log.id,log.to_user_id as the_user_id,log.call_minutes,log.createtime,user.avatar,user.nickname')
                ->join('user','log.to_user_id = user.id','LEFT')
                ->where('log.user_id' , $this->auth->id)
                ->order('log.id desc')->autopage()->select();
        }

        $list = list_domain_image($list,['avatar']);
        $this->success(1,$list);
    }

    //视频通话每分钟调用一次
    public function video_onemin(){
        if ($this->auth->gender == 0) { //女生不花钱
            $this->error('您的网络开小差啦~');
        }

        //检测用户
        $request_id = input('request_id', '', 'trim'); //唯一请求标识

        $to_user_id = input_post('to_user_id');
        $to_user_info = Db::name('user')->field('id,username,intro_uid,gender,match_video_price')->where('id',$to_user_id)->find();
        if(!$to_user_info){
            $this->error('不存在的用户');
        }

        //客服不收钱
        $kefu_ids = config('site.kefu_user_ids');
        if(in_array($to_user_id,explode(',',$kefu_ids))){
            $rs = [
                'get_jewel_value' => 0,
            ];
            $this->success('success',$rs);
        }

        if ($to_user_info['gender'] != 0) {
            $this->error('同性不能聊天~');
        }

        //正常价格
        $price = $to_user_info['match_video_price'];  //扣费金币
        $gift_plat_scale = config('site.gift_plat_scale');  //抽成比例
        $money = bcdiv(bcmul($price,100 - $gift_plat_scale,2),100,2); //抽成后收益

        Db::startTrans();

        //检查剩余分钟数
        $task_status = 0;//任务状态
        $user_wallet = Db::name('user_wallet')->where('user_id',$this->auth->id)->lock(true)->find();
        if($user_wallet['video_sec'] >= 1){
            //扣分钟数
            $price = 0;
            //补贴给对方0.1金币
            $money = 0.1;
        }else{
            $task_status = 1;
            //需要扣别人的钱,判断钱是否购
            if($price > 0){
                $goldtotal = model('wallet')->getWallettotal($this->auth->id);
                if(bccomp($price,$goldtotal) == 1){
                    Db::rollback();
                    $this->error('金币不足');
                }
            }
        }

        //查询是否有匹配记录
        $user_match_video_log_info = [];
        if ($request_id) {
            $user_match_video_log_info = Db::name('user_match_video_log')->where(['user_id' => $this->auth->id, 'to_user_id' => $to_user_id, 'request_id' => $request_id])->find();
        }
        if ($user_match_video_log_info) {
            //修改记录日志
            $data = [
                'price' => $user_match_video_log_info['price'] + $price,
                'updatetime' => time(),
                'money' => $user_match_video_log_info['money'] + $money,
                'call_minutes' => $user_match_video_log_info['call_minutes'] + 1
            ];

            $log_id = Db::name('user_match_video_log')->where(['id' => $user_match_video_log_info['id']])->setField($data);
            if (!$log_id) {
                Db::rollback();
                $this->error('扣费失败');
            }
        } else {
            //添加记录日志
            $data = [
                'user_id' => $this->auth->id,
                'price' => $price,
                'createtime' => time(),
                'to_user_id' => $to_user_id,
                'money' => $money,
                'request_id' => $request_id,
                'call_minutes' => 1
            ];

            $log_id = Db::name('user_match_video_log')->insertGetId($data);
            if (!$log_id) {
                Db::rollback();
                $this->error('扣费失败');
            }
        }

        //检查剩余分钟数
        if($user_wallet['video_sec'] >= 1){
            //扣分钟数
            $rs_wallet = Db::name('user_wallet')->where('user_id',$this->auth->id)->update(['video_sec'=>$user_wallet['video_sec']-1]);
            if($rs_wallet === false){
                Db::rollback();
                $this->error('扣除分钟数失败');
            }
            //补贴给对方0.1金币
            $money = 0.1;
            $rs = model('wallet')->lockChangeAccountRemain($to_user_id,'jewel',$money,21,$this->auth->username.'使用免费次数的补贴','user_match_video_log',$log_id);
            if($rs['status'] === false){
                Db::rollback();
                $this->error($rs['msg']);
            }
        }else{

            //有性别差,扣费
            if($price > 0){
                $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,'gold',-$price,11,'与'.$to_user_info['username'].'视频通话','user_match_video_log',$log_id);
                if($rs['status'] === false){
                    Db::rollback();
                    $this->error($rs['msg']);
                }
            }
            //另一方加钱,0收费
            if($money > 0){
                $rs = model('wallet')->lockChangeAccountRemain($to_user_id,'jewel',$money,21,'与'.$this->auth->username.'视频通话','user_match_video_log',$log_id);
                if($rs['status'] === false){
                    Db::rollback();
                    $this->error($rs['msg']);
                }
            }

            //增加送礼用户的财富等级
            $res_wealth = \app\common\model\User::add_wealth_level($this->auth->id,$price);
            //增加获赠用户的魅力等级
            $res_wealth = \app\common\model\User::add_charm_level($to_user_id,$price);
        }

        //tag任务赠送金币
        //与1名异性语音通话奖励
        if($task_status == 1){
            $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,11);
            if($task_rs === false){
                Db::rollback();
                $this->error('完成任务赠送奖励失败');
            }
            $task_rs = \app\common\model\TaskLog::tofinish($to_user_id,11);
            if($task_rs === false){
                Db::rollback();
                $this->error('完成任务赠送奖励失败');
            }
        }

        Db::commit();
        $rs = [
            'get_jewel_value' => $data['money'],
        ];
        $this->success('success',$rs);
    }

    //语音通话每分钟调用一次
    public function audio_onemin(){
        if ($this->auth->gender == 0) { //女生不花钱
            $this->error('您的网络开小差啦~');
        }

        //检测用户
        $request_id = input('request_id', '', 'trim'); //唯一请求标识

        $to_user_id = input_post('to_user_id');
        $to_user_info = Db::name('user')->field('id,username,intro_uid,gender,match_audio_price')->where('id',$to_user_id)->find();
        if(!$to_user_info){
            $this->error('不存在的用户');
        }

        //客服不收钱
        $kefu_ids = config('site.kefu_user_ids');
        if(in_array($to_user_id,explode(',',$kefu_ids))){
            $rs = [
                'get_jewel_value' => 0,
            ];
            $this->success('success',$rs);
        }

        if ($to_user_info['gender'] != 0) {
            $this->error('同性不能聊天~');
        }

        //正常价格
        $price = $to_user_info['match_audio_price'];  //扣费金币
        $gift_plat_scale = config('site.gift_plat_scale');  //抽成比例
        $money = bcdiv(bcmul($price,100 - $gift_plat_scale,2),100,2); //抽成后收益

        Db::startTrans();

        //检查剩余分钟数
        $task_status = 0;//任务状态
        $user_wallet = Db::name('user_wallet')->where('user_id',$this->auth->id)->lock(true)->find();
        if($user_wallet['audio_sec'] >= 1){
            //扣分钟数
            $price = 0;
            //补贴给对方0.1金币
            $money = 0.1;
        }else{
            $task_status = 1;
            //需要扣别人的钱,判断钱是否购
            if($price > 0){
                $goldtotal = model('wallet')->getWallettotal($this->auth->id);
                if(bccomp($price,$goldtotal) == 1){
                    Db::rollback();
                    $this->error('金币不足');
                }
            }
        }

        //查询是否有匹配记录
        $user_match_audio_log_info = [];
        if ($request_id) {
            $user_match_audio_log_info = Db::name('user_match_audio_log')->where(['user_id' => $this->auth->id, 'to_user_id' => $to_user_id, 'request_id' => $request_id])->find();
        }
        if ($user_match_audio_log_info) {
            //修改记录日志
            $data = [
                'price' => $user_match_audio_log_info['price'] + $price,
                'updatetime' => time(),
                'money' => $user_match_audio_log_info['money'] + $money,
                'call_minutes' => $user_match_audio_log_info['call_minutes'] + 1
            ];

            $log_id = Db::name('user_match_audio_log')->where(['id' => $user_match_audio_log_info['id']])->setField($data);
            if (!$log_id) {
                Db::rollback();
                $this->error('扣费失败');
            }
        } else {
            //添加记录日志
            $data = [
                'user_id' => $this->auth->id,
                'price' => $price,
                'createtime' => time(),
                'to_user_id' => $to_user_id,
                'money' => $money,
                'request_id' => $request_id,
                'call_minutes' => 1
            ];

            $log_id = Db::name('user_match_audio_log')->insertGetId($data);
            if (!$log_id) {
                Db::rollback();
                $this->error('扣费失败');
            }
        }

        //检查剩余分钟数
        if($user_wallet['audio_sec'] >= 1){
            //扣分钟数
            $rs_wallet = Db::name('user_wallet')->where('user_id',$this->auth->id)->update(['audio_sec'=>$user_wallet['audio_sec']-1]);
            if($rs_wallet === false){
                Db::rollback();
                $this->error('扣除分钟数失败');
            }
            //补贴给对方0.1金币
            $rs = model('wallet')->lockChangeAccountRemain($to_user_id,'jewel',$money,22,$this->auth->username.'使用免费次数的补贴','user_match_audio_log',$log_id);
            if($rs['status'] === false){
                Db::rollback();
                $this->error($rs['msg']);
            }
        }else{

            //有性别差,扣费
            if($price > 0){
                $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,'gold',-$price,12,'与'.$to_user_info['username'].'语音通话','user_match_audio_log',$log_id);
                if($rs['status'] === false){
                    Db::rollback();
                    $this->error($rs['msg']);
                }
            }
            //另一方加钱,0收费
            if($money > 0){
                $rs = model('wallet')->lockChangeAccountRemain($to_user_id,'jewel',$money,22,'与'.$this->auth->username.'语音通话','user_match_audio_log',$log_id);
                if($rs['status'] === false){
                    Db::rollback();
                    $this->error($rs['msg']);
                }
            }

            //增加送礼用户的财富等级
            $res_wealth = \app\common\model\User::add_wealth_level($this->auth->id,$price);
            //增加获赠用户的魅力等级
            $res_wealth = \app\common\model\User::add_charm_level($to_user_id,$price);
        }

        //tag任务赠送金币
        //与1名异性语音通话奖励
        if($task_status == 1){
            $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,11);
            if($task_rs === false){
                Db::rollback();
                $this->error('完成任务赠送奖励失败');
            }
            $task_rs = \app\common\model\TaskLog::tofinish($to_user_id,11);
            if($task_rs === false){
                Db::rollback();
                $this->error('完成任务赠送奖励失败');
            }
        }

        Db::commit();

        $rs = [
            'get_jewel_value' => $data['money'],
        ];
        $this->success('success',$rs);
    }

    //打字聊天每句话调用一次
    public function typing_once(){
        if ($this->auth->gender == 0) { //女生不花钱
            $this->error('您的网络开小差啦~');
        }

        //检测用户
        $to_user_id = input_post('to_user_id');
        $to_user_info = Db::name('user')->field('id,username,intro_uid,gender,match_typing_price')->where('id',$to_user_id)->find();
        if(!$to_user_info){
            $this->error('不存在的用户');
        }

        //客服不收钱
        $kefu_ids = config('site.kefu_user_ids');
        if(in_array($to_user_id,explode(',',$kefu_ids))){
            $rs = [
                'get_jewel_value' => 0,
            ];
            $this->success('success',$rs);
        }

        if ($to_user_info['gender'] != 0) {
            $this->error('同性不能聊天~');
        }

        //正常价格
        $price = $to_user_info['match_typing_price'];  //扣费金币
        $gift_plat_scale = config('site.gift_plat_scale');  //抽成比例
        $money = bcdiv(bcmul($price,100 - $gift_plat_scale,2),100,2); //抽成后收益

        Db::startTrans();

        //检查剩余分钟数
        $user_wallet = Db::name('user_wallet')->where('user_id',$this->auth->id)->lock(true)->find();
        if($user_wallet['typing_times'] >= 1){
            //扣分钟数
            $price = 0;
            //补贴给对方0.1金币
            $money = 0.1;
        }else{
            //需要扣别人的钱,判断钱是否购
            if($price > 0){
                $goldtotal = model('wallet')->getWallettotal($this->auth->id);
                if(bccomp($price,$goldtotal) == 1){
                    Db::rollback();
                    $this->error('金币不足');
                }
            }
        }


        //添加记录日志
        $data = [
            'user_id' => $this->auth->id,
            'price' => $price,
            'createtime' => time(),
            'to_user_id' => $to_user_id,
            'money' => $money,
        ];

        $log_id = Db::name('user_match_typing_log')->insertGetId($data);
        if (!$log_id) {
            Db::rollback();
            $this->error('扣费失败');
        }

        //检查剩余分钟数
        if($user_wallet['typing_times'] >= 1){
            //扣分钟数
            $rs_wallet = Db::name('user_wallet')->where('user_id',$this->auth->id)->update(['typing_times'=>$user_wallet['typing_times']-1]);
            if($rs_wallet === false){
                Db::rollback();
                $this->error('扣除免费次数失败');
            }
            //补贴给对方0.1金币
            $money = 0.1;
            $rs = model('wallet')->lockChangeAccountRemain($to_user_id,'jewel',$money,23,$this->auth->username.'使用免费次数的补贴','user_match_typing_log',$log_id);
            if($rs['status'] === false){
                Db::rollback();
                $this->error($rs['msg']);
            }
        }else{

            //有性别差,扣费
            if($price > 0){
                $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,'gold',-$price,13,'与'.$to_user_info['username'].'聊天','user_match_typing_log',$log_id);
                if($rs['status'] === false){
                    Db::rollback();
                    $this->error($rs['msg']);
                }
            }
            //另一方加钱,0收费
            if($money > 0){
                $rs = model('wallet')->lockChangeAccountRemain($to_user_id,'jewel',$money,23,'与'.$this->auth->username.'聊天','user_match_typing_log',$log_id);
                if($rs['status'] === false){
                    Db::rollback();
                    $this->error($rs['msg']);
                }
            }

            //增加送礼用户的财富等级
            $res_wealth = \app\common\model\User::add_wealth_level($this->auth->id,$price);
            //增加获赠用户的魅力等级
            $res_wealth = \app\common\model\User::add_charm_level($to_user_id,$price);
        }

        Db::commit();

        $rs = [
            'get_jewel_value' => $money,
        ];
        $this->success('success',$rs);
    }

    //语音匹配
    public function getaudiouser(){

        if(config('site.index_match_audio_switch') != 1){
            $this->error('该功能暂未开启');
        }

        //给出备选用户
        $map = [
            'user.status' =>1,                                       //未封禁用户
            'user.gender' => $this->auth->gender == 1 ? 0 : 1,       //异性
            'user.is_active' => 1,                                   //在线的
            'user.open_match_audio' => 1,                            //打开语聊开关
        ];

        if($this->auth->gender == 0){

            //或者未首充用户,且还有免费分钟数
            $map2['user.is_shouchong'] = 0;
            $map2['uw.audio_sec'] = ['gt',0];

            //男性要有最少一分钟的钱
            $map3['uw.gold'] = ['egt',$this->auth->match_audio_price];

        }else{
            $my_gold = Db::name('user_wallet')->where('user_id',$this->auth->id)->value('gold');
            $map2['user.match_audio_price'] = ['elt',$my_gold];
        }

        $lists = Db::name('user')->alias('user')->field('user.id,user.gender,user.birthday,user.avatar,user.nickname,user.match_audio_price')
            ->join('user_wallet uw','user.id = uw.user_id','LEFT')
            ->where($map)->where($map2)->order('user.logintime desc')->page($this->page,100)->select();

        if(empty($lists) && $this->auth->gender == 0){
            $lists = Db::name('user')->alias('user')->field('user.id,user.gender,user.birthday,user.avatar,user.nickname,user.match_audio_price')
                ->join('user_wallet uw','user.id = uw.user_id','LEFT')
                ->where($map)->where($map3)->order('user.logintime desc')->page($this->page,100)->select();
        }

        if(!empty($lists)){
            foreach($lists as $key => &$val){
                $val = info_domain_image($val,['avatar']);

                $val['age'] = birthtime_to_age($val['birthday']);
                unset($val['birthday']);

                $val['match_audio_price'] = $this->auth->gender == 0 ? $this->auth->match_audio_price : $val['match_audio_price'];
            }
        }

        $this->success('success',$lists);
    }

    //视频匹配
    public function getvideouser(){

        if(config('site.index_match_video_switch') != 1){
            $this->error('该功能暂未开启');
        }
        //给出备选用户
        $map = [
            'user.status' =>1,                                       //未封禁用户
            'user.gender' => $this->auth->gender == 1 ? 0 : 1,       //异性
            'user.is_active' => 1,                                   //在线的
            'user.open_match_video' => 1,                            //打开语聊开关
        ];

        if($this->auth->gender == 0){

            //或者未首充用户,且还有免费分钟数
            $map2['user.is_shouchong'] = 0;
            $map2['uw.video_sec'] = ['gt',0];

            //男性要有最少一分钟的钱
            $map3['uw.gold'] = ['egt',$this->auth->match_video_price];

        }else{
            $my_gold = Db::name('user_wallet')->where('user_id',$this->auth->id)->value('gold');
            $map2['user.match_video_price'] = ['elt',$my_gold];
        }

        $lists = Db::name('user')->alias('user')->field('user.id,user.gender,user.birthday,user.avatar,user.nickname,user.match_video_price')
            ->join('user_wallet uw','user.id = uw.user_id','LEFT')
            ->where($map)->where($map2)->order('user.logintime desc')->page($this->page,100)->select();

        if(empty($lists) && $this->auth->gender == 0){
            $lists = Db::name('user')->alias('user')->field('user.id,user.gender,user.birthday,user.avatar,user.nickname,user.match_video_price')
                ->join('user_wallet uw','user.id = uw.user_id','LEFT')
                ->where($map)->where($map3)->order('user.logintime desc')->page($this->page,100)->select();
        }

        if(!empty($lists)){
            foreach($lists as $key => &$val){
                $val = info_domain_image($val,['avatar']);

                $val['age'] = birthtime_to_age($val['birthday']);
                unset($val['birthday']);

                $val['match_video_price'] = $this->auth->gender == 0 ? $this->auth->match_video_price : $val['match_video_price'];
            }
        }

        $this->success('success',$lists);
    }

    //亲密度等级信息
    public function intimacylevel() {
        $user_id = input('user_id', 0, 'intval'); //对方id
        if (!$user_id) {
            $this->error('参数缺失');
        }
        if ($this->auth->id > $user_id) { //大的在后
            $where['uid'] = $user_id;
            $where['other_uid'] = $this->auth->id;
        } else { //小的在前
            $where['uid'] = $this->auth->id;
            $where['other_uid'] = $user_id;
        }

        $level = 0; //当前等级
        $level_name = ''; //当前等级名称
        $qinmi_sum = 0; //当前亲密度

        $next_level_diff = 0; //距下一等级亲密度差值
        $next_level_name = 0; //下一等级名称
        $next_level_value = 0;//下一等级亲密度值

        //亲密度等级列表
        $list = Db::name('intimacy_level')->field('name,level,value')->order('value')->select();

        //当前亲密度信息
        $user_intimacy_info = Db::name('user_intimacy')->where($where)->find();
        if ($user_intimacy_info) {
            //当前亲密度
            $qinmi_sum = $user_intimacy_info['value'];

            //当前等级信息
            $level_info = Db::name('intimacy_level')->where(['value' => ['elt', $user_intimacy_info['value']]])->order('level desc')->find();
            if ($level_info) {
                $level      = $level_info['level'];
                $level_name = $level_info['name'];
            }
            //下一等级信息
            $next_level_info = Db::name('intimacy_level')->where(['value' => ['gt', $user_intimacy_info['value']]])->order('value')->find();
            if ($next_level_info) {
                $next_level_name  = $next_level_info['name'];
                $next_level_value = $next_level_info['value'];
                $next_level_diff = $next_level_info['value'] - $user_intimacy_info['value'];
            }

        } else {
            $level = 1; //当前等级
            $level_name = '初级'; //当前等级名称
            $qinmi_sum = 0; //当前亲密度

            $next_level = Db::name('intimacy_level')->where('level',2)->find();
            $next_level_diff = $next_level['value'];
            $next_level_name = $next_level['name'];
            $next_level_value = $next_level['value'];
        }

        if ($list) {
            foreach ($list as &$v) {
                if ($v['level'] < $level) {
                    $v['is_unlock'] = 1; //当前等级是否解锁: 1已解锁  2当前等级 3未解锁
                } elseif ($v['level'] == $level) {
                    $v['is_unlock'] = 2;
                } else {
                    $v['is_unlock'] = 3;
                }
            }
        }

        $data['level'] = $level; //当前等级
        $data['level_name'] = $level_name; //当前等级名称
        $data['qinmi_sum'] = $qinmi_sum; //当前亲密度
        $data['next_level_diff'] = $next_level_diff; //距下一等级亲密度差值
        $data['next_level_name'] = $next_level_name; //下一等级名称
        $data['next_level_value'] = $next_level_value; //下一等级亲密度值
        $data['level_list'] = $list; //等级列表

        $data['my_avatar'] = localpath_to_netpath($this->auth->avatar);
        $data['my_nickname'] = $this->auth->nickname;

        $other_user = Db::name('user')->field('avatar,nickname')->where('id',$user_id)->find();
        $data['other_avatar'] = localpath_to_netpath($other_user['avatar']);
        $data['other_nickname'] = $other_user['nickname'];

        $data['intimacy_rule'] = config('site.intimacy_rule');


        $this->success('亲密度等级信息', $data);
    }

//////////////////////////////////////////////////////////////
    //聊天匹配
    public function gettypinguser(){

        //给出备选用户
        $map = [
            'user.status' =>1,                                       //未封禁用户
            'user.gender' => $this->auth->gender == 1 ? 0 : 1,       //异性
        ];

        if($this->auth->gender == 0){

            //或者未首充用户,且还有免费分钟数
            $map2['user.is_shouchong'] = 0;
            $map2['uw.typing_times'] = ['gt',0];

            //男性要有最少一分钟的钱
            $map3['uw.gold'] = ['egt',$this->auth->match_typing_price];

        }else{
            $my_gold = Db::name('user_wallet')->where('user_id',$this->auth->id)->value('gold');
            $map2['user.match_typing_price'] = ['elt',$my_gold];
        }

        $lists = Db::name('user')->alias('user')->field('user.id')
            ->join('user_wallet uw','user.id = uw.user_id','LEFT')
            ->where($map)->where($map2)->order('user.logintime desc')->page($this->page,100)->select();

        if(empty($lists) && $this->auth->gender == 0){
            $lists = Db::name('user')->alias('user')->field('user.id')
                ->join('user_wallet uw','user.id = uw.user_id','LEFT')
                ->where($map)->where($map3)->order('user.logintime desc')->page($this->page,100)->select();
        }

        $this->success('success',$lists);
    }

    //过滤规则
    private function fliter_user($lists){

        if(empty($lists)){
            return $lists;
        }


        //过滤掉通话中的
        foreach($lists as $key => $val){
            if(redis_matching_get($val['id']) == 1){
                unset($lists[$key]);
            }
        }


        return $lists;
    }



}