| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549 | <?phpnamespace app\api\controller;use app\common\controller\Api;use think\Db;/** * 代理邀请中心 */class Userintro extends Api{    protected $noNeedLogin = [];    protected $noNeedRight = ['*'];    /*public function __construct(){        parent::__construct();        if($this->auth->group_id == 1){            $this->error('无权进入');        }    }*/    //邀请页    public function introinfo(){        $today = date('Y-m-d');        $starttime = strtotime($today) - 86400;        $endtime   = $starttime + 86399;        $zuori_count = Db::name('user')->where('intro_uid',$this->auth->id)->where('yaoqingtime','BETWEEN',[$starttime,$endtime])->count();        $total_count = Db::name('user')->where('intro_uid',$this->auth->id)->count();        $register_url = config('h5register_url') .'?intro_no='. $this->auth->introcode;        $result = [            'zuori_count' => $zuori_count,            'total_count' => $total_count,            'register_url' => $register_url,        ];        $this->success(1,$result);    }    //生成视频分享海报    public function shareposter() {        $inviteimage = $this->introimage();        $data = [            [                "left"=> "190px",                "top"=> "320px",                "type"=> "img",                "width"=> "110px",                "height"=> "110px",                "src"=> httpurllocal($inviteimage)//"https://metavision.oss-cn-hongkong.aliyuncs.com/uploads/20220615/f00cb545deb4c4e7296f444239d83e84.jpg"            ],        ];        $data = json_encode($data, 320);        $poster = [            'id' => $this->auth->id,            'title' => '珍友',            'waittext' => '您的专属海报正在拼命生成中,请等待片刻...',            'bg_image' => '/assets/img/posteruserbg.png',            'data' => $data,            'status' => 'normal',            'weigh' => 0,            'createtime' => 1653993709,            'updatetime' => 1653994259,        ];        $image = new \addons\poster\library\Image();        $imgurl = $image->createPosterImage($poster, $this->auth->getUser());        if (!$imgurl) {            $this->error('生成海报出错');        }        $imgurl = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"] . '/' . $imgurl;        //echo '<html><body><img src="'.$imgurl.'"></body></html>';        $this->success('', $imgurl);    }    //生成邀请码二维码图片    private function introimage() {        $params['text'] = config('h5register_url') .'?intro_no='. $this->auth->introcode;        $qrcode_service = \addons\qrcode\library\Service::qrcode($params);        $qrcodePath = ROOT_PATH . 'public/uploads/hbplayer/'.date('Ymd');        if (!is_dir($qrcodePath)) {            @mkdir($qrcodePath);        }        if (is_really_writable($qrcodePath)) {            $filename = 'intro_'.$this->auth->introcode . '.png';            $filePath = $qrcodePath .'/'. $filename;            $qrcode_service->writeFile($filePath);        }        return '/uploads/hbplayer/'.date('Ymd') .'/'. $filename;    }    //账户中心 api/withdraw/config    //提现 api/withdraw/withdraw    //账户明细    public function agentjewel_log(){        $map = [            'user_id' => $this->auth->id,        ];        $list = Db::name('user_agentjewel_log')            ->field('id,log_type,before,change_value,remain,remark,createtime')            ->where($map)->order('id desc')->autopage()->select();        $list = $this->list_appen_logtext($list);        $this->success('success',$list);    }    //追加log_text    private function list_appen_logtext($list){        if(!empty($list)){            $conf = config('wallet.logtype');            foreach($list as $key => $val){                $list[$key]['log_text'] = isset($conf[$val['log_type']]) ? $conf[$val['log_type']] : '';            }        }        return $list;    }    //申请绑定查询    public function intro_search(){        $username = input('username',0);        $user_info = Db::name('user')->field('id,username,group_id,nickname,avatar')->where('username',$username)->find();        if(empty($user_info)){            $this->error('不存在的用户');        }        $user_info = info_domain_image($user_info,['avatar']);        $this->success(1,$user_info);    }    //申请绑定    public function apply_intro(){        $down_uid = input('search_uid',0);        $images  = input('images','');        $remark = input('remark','');        if($down_uid == $this->auth->id){            $this->error('不能绑定自己');        }        $where = [            'user_id'   => $this->auth->id,            'down_uid' => $down_uid,            'status'    => 0,        ];        $check = Db::name('user_intro_apply')->where($where)->find();        if($check){            $this->error('您上次的申请还在审核中');        }        $data = [            'user_id'   => $this->auth->id,            'down_uid' => $down_uid,            'images'    => $images,            'remark'    => $remark,            'createtime'=> time(),        ];        Db::name('user_intro_apply')->insertGetId($data);        $this->success('申请成功');    }    //申请绑定记录    public function apply_intro_log(){        $where = [            'user_id'   => $this->auth->id,        ];        $list = Db::name('user_intro_apply')->alias('log')            ->field('log.*,user.username,user.nickname,user.avatar')            ->join('user','log.down_uid = user.id','LEFT')            ->where($where)->autopage()->select();        $list = list_domain_image($list,['avatar']);        $this->success(1,$list);    }    //日报    public function ribao(){        $result = [];        //日期        $today = date('Y-m-d');        $startday  = input('startday',$today);        $starttime = strtotime($startday);        $endtime   = $starttime + 86399;        //传入代理        $down_all_id = input('down_all_id',0);        //代理名        $result['agentname']   = $this->auth->agentname ?: $this->auth->nickname;        $result['yaoqingtime'] = $this->auth->yaoqingtime;        $result['startday']    = $startday;        //一级代理  下拉  可选二级代理        $down_all = $this->select_agent();        $result['down_all'] = $down_all;        //dump($down_all);        //确定收益统计范围        if(!empty($down_all_id)){            $downall_uid = Db::name('user')->where('intro_uid',$down_all_id)->column('id');//其下直推,A1下B0+B1 或 B1下C1            //$downall_uid[] = $down_all_id;        }else{            $down_uid = array_column($down_all,'id');            //dump($down_uid);            $downall_uid = Db::name('user')->where('intro_uid','IN',$down_uid)->column('id');//其下直推B0+代理下直推C1 或 C1        }        //dump($downall_uid);        //邀请奖励收益        $recharge_sum = Db::name('user_agentjewel_log')->where('user_id','IN',$downall_uid)->where('log_type',51)->where('createtime','BETWEEN',[$starttime,$endtime])->sum('change_value');        $result['recharge_sum'] = $recharge_sum;        //视频收益        $video_sum = Db::name('user_match_video_log')->where('to_user_id','IN',$downall_uid)->where('updatetime','BETWEEN',[$starttime,$endtime])->sum('money');        $result['video_sum'] = $video_sum;        //语音收益        $audio_sum = Db::name('user_match_audio_log')->where('to_user_id','IN',$downall_uid)->where('updatetime','BETWEEN',[$starttime,$endtime])->sum('money');        $result['audio_sum'] = $audio_sum;        //私信收益        $typing_sum= Db::name('user_match_typing_log')->where('to_user_id','IN',$downall_uid)->where('createtime','BETWEEN',[$starttime,$endtime])->sum('money');        $result['typing_sum'] = $typing_sum;        //礼物收益        $gift_sum  = Db::name('gift_user_typing')->where('user_to_id','IN',$downall_uid)->where('createtime','BETWEEN',[$starttime,$endtime])->sum('getvalue');        $result['gift_sum'] = $gift_sum;        //总收益        $result['total'] = $recharge_sum + $video_sum + $audio_sum + $typing_sum + $gift_sum;        $result['total'] = bcadd($result['total'],0,2);        //在线用户        $active_num = Db::name('user_active')->where('user_id','IN',$downall_uid)->where('requesttime','BETWEEN',[$starttime,$endtime])->count();        $result['active_num'] = $active_num;        //收益用户        $a = Db::name('user_agentjewel_log')->where('user_id','IN',$downall_uid)->where('log_type',51)->where('createtime','BETWEEN',[$starttime,$endtime])->distinct(true)->field('user_id')->select();        $a1 = array_column($a,'user_id');        $b = Db::name('user_match_video_log')->where('to_user_id','IN',$downall_uid)->where('updatetime','BETWEEN',[$starttime,$endtime])->distinct(true)->field('to_user_id')->select();        $b1 = array_column($b,'to_user_id');        $c = Db::name('user_match_audio_log')->where('to_user_id','IN',$downall_uid)->where('updatetime','BETWEEN',[$starttime,$endtime])->distinct(true)->field('to_user_id')->select();        $c1 = array_column($c,'to_user_id');        $d = Db::name('user_match_typing_log')->where('to_user_id','IN',$downall_uid)->where('createtime','BETWEEN',[$starttime,$endtime])->distinct(true)->field('to_user_id')->select();        $d1 = array_column($d,'to_user_id');        $e = Db::name('gift_user_typing')->where('user_to_id','IN',$downall_uid)->where('createtime','BETWEEN',[$starttime,$endtime])->distinct(true)->field('user_to_id')->select();        $e1 = array_column($e,'user_to_id');//        dump($a);//        dump($a1);//        dump($b);//        dump($b1);//        dump($c);//        dump($c1);//        dump($d);//        dump($d1);//        dump($e);//        dump($e1);        $abcde = array_merge(array_merge($a1,$b1,$c1),$d1,$e1);        $shouyi_user = array_flip(array_flip($abcde));        $result['shouyi_num'] = count($shouyi_user);        $this->success(1,$result);    }    //下拉选择代理    private function select_agent(){        //一级代理下的二级代理        $down_agent_users = [];        if($this->auth->group_id == 3){            $down_agent_users = Db::name('user')->field('id,nickname,agentname')->where('agent_id',$this->auth->id)->select();        }        //追加自己。二级代理的,就只有自己        $self_agent = [['id'=>$this->auth->id,'nickname'=>$this->auth->nickname,'agentname'=>$this->auth->agentname]];        $down_all = array_merge($self_agent,$down_agent_users);        //没有代理名的用昵称        foreach($down_all as $key => $val){            $val['agentname'] = $val['agentname'] ?: $val['nickname'];            unset($val['nickname']);            $down_all[$key] = $val;        }        return $down_all;    }    //成员管理    public function all_user(){        $result = [];        //传入代理        $down_all_id = input('down_all_id',0);        //传入用户id        $get_username = input('get_username',0);        //一级代理  下拉  可选二级代理        $down_all = $this->select_agent();        $result['down_all'] = $down_all;        //dump($down_all);        //确定收益统计范围        if(!empty($down_all_id)){            $where = ['intro_uid' => $down_all_id];            if($get_username){                $where['username']= $get_username;            }            $downall_uid = Db::name('user')->where($where)->field('id,username,avatar,nickname,is_active,intro_uid,yaoqingtime')->order('yaoqingtime desc')->autopage()->select();//其下直推,A1下B0 或 B1下C1            //$downall_uid[] = $down_all_id;        }else{            $down_uid = array_column($down_all,'id');            $where = ['intro_uid' => ['IN',$down_uid]];            if($get_username){                $where['username']= $get_username;            }            //dump($down_uid);            $downall_uid = Db::name('user')->where($where)->field('id,username,avatar,nickname,is_active,intro_uid,yaoqingtime')->order('yaoqingtime desc')->autopage()->select();//其下直推B0+代理下直推C1 或 C1        }        //dump($downall_uid);        foreach($downall_uid as $key => &$user){            $user['avatar'] = one_domain_image($user['avatar']);            $user['agentname'] = Db::name('user')->where('id',$user['intro_uid'])->value('agentname');            //邀请奖励收益            $recharge_sum = Db::name('user_agentjewel_log')->where('user_id',$user['id'])->where('log_type',51)->sum('change_value');            $user['recharge_sum'] = $recharge_sum;            //视频收益            $video_sum = Db::name('user_match_video_log')->where('to_user_id',$user['id'])->sum('money');            $user['video_sum'] = $video_sum;            //语音收益            $audio_sum = Db::name('user_match_audio_log')->where('to_user_id',$user['id'])->sum('money');            $user['audio_sum'] = $audio_sum;            //私信收益            $typing_sum= Db::name('user_match_typing_log')->where('to_user_id',$user['id'])->sum('money');            $user['typing_sum'] = $typing_sum;            //礼物收益            $gift_sum  = Db::name('gift_user_typing')->where('user_to_id',$user['id'])->sum('getvalue');            $user['gift_sum'] = $gift_sum;            //总收益            $user['total'] = $recharge_sum + $video_sum + $audio_sum + $typing_sum + $gift_sum;            $user['total'] = bcadd($user['total'],0,2);        }        //用户列表的排序        if(!empty($downall_uid)){            $column_total = array_column($downall_uid,'total');            array_multisort($column_total, SORT_DESC, $downall_uid);        }        //用户列表的排序        $result['user_list'] = $downall_uid;        $this->success(1,$result);    }    //成员收入    public function user_shouyi(){        $result = [];        //日期        $today = date('Y-m-d');        $startday  = input('startday',$today);        $starttime = strtotime($startday);        $endtime   = $starttime + 86399;        //传入代理        $down_all_id = input('down_all_id',0);        //传入用户id        $get_username = input('get_username',0);        $result['startday']    = $startday;        //一级代理  下拉  可选二级代理        $down_all = $this->select_agent();        $result['down_all'] = $down_all;        //dump($down_all);        //确定收益统计范围        if(!empty($down_all_id)){            $where = ['intro_uid' => $down_all_id];            if($get_username){                $where['username']= $get_username;            }            $downall_uid = Db::name('user')->where($where)->field('id,username,avatar,nickname,intro_uid')->order('yaoqingtime desc')->autopage()->select();//其下直推,A1下B0 或 B1下C1            //$downall_uid[] = $down_all_id;        }else{            $down_uid = array_column($down_all,'id');            $where = ['intro_uid' => ['IN',$down_uid]];            if($get_username){                $where['username']= $get_username;            }            //dump($down_uid);            $downall_uid = Db::name('user')->where($where)->field('id,username,avatar,nickname,intro_uid')->order('yaoqingtime desc')->autopage()->select();//其下直推B0+代理下直推C1 或 C1        }        //dump($downall_uid);        foreach($downall_uid as $key => &$user){            $user['agentname'] = Db::name('user')->where('id',$user['intro_uid'])->value('agentname');            //邀请奖励收益            $recharge_sum = Db::name('user_agentjewel_log')->where('user_id',$user['id'])->where('log_type',51)->where('createtime','BETWEEN',[$starttime,$endtime])->sum('change_value');//            $user['recharge_sum'] = $recharge_sum;            //视频收益            $video_sum = Db::name('user_match_video_log')->where('to_user_id',$user['id'])->where('updatetime','BETWEEN',[$starttime,$endtime])->sum('money');//            $user['video_sum'] = $video_sum;            //语音收益            $audio_sum = Db::name('user_match_audio_log')->where('to_user_id',$user['id'])->where('updatetime','BETWEEN',[$starttime,$endtime])->sum('money');//            $user['audio_sum'] = $audio_sum;            //私信收益            $typing_sum= Db::name('user_match_typing_log')->where('to_user_id',$user['id'])->where('createtime','BETWEEN',[$starttime,$endtime])->sum('money');//            $user['typing_sum'] = $typing_sum;            //礼物收益            $gift_sum  = Db::name('gift_user_typing')->where('user_to_id',$user['id'])->where('createtime','BETWEEN',[$starttime,$endtime])->sum('getvalue');//            $user['gift_sum'] = $gift_sum;            //总收益            $user['total'] = $recharge_sum + $video_sum + $audio_sum + $typing_sum + $gift_sum;            $user['total'] = bcadd($user['total'],0,2);        }        //用户列表的排序        if(!empty($downall_uid)){            $column_total = array_column($downall_uid,'total');            array_multisort($column_total, SORT_DESC, $downall_uid);        }        //用户列表的排序        $result['user_list'] = $downall_uid;        $this->success(1,$result);    }    //成员详情    public function user_info(){        $user_id = input('user_id',0);        $user_info = Db::name('user')->where('id',$user_id)->field('id,username,avatar,nickname,intro_uid,yaoqingtime')->find();        //邀请奖励收益        $recharge_sum = Db::name('user_agentjewel_log')->where('user_id',$user_id)->where('log_type',51)->sum('change_value');        $user_info['recharge_sum'] = $recharge_sum;        //视频收益        $video_sum = Db::name('user_match_video_log')->where('to_user_id',$user_id)->sum('money');        $user_info['video_sum'] = $video_sum;        //语音收益        $audio_sum = Db::name('user_match_audio_log')->where('to_user_id',$user_id)->sum('money');        $user_info['audio_sum'] = $audio_sum;        //私信收益        $typing_sum= Db::name('user_match_typing_log')->where('to_user_id',$user_id)->sum('money');        $user_info['typing_sum'] = $typing_sum;        //礼物收益        $gift_sum  = Db::name('gift_user_typing')->where('user_to_id',$user_id)->sum('getvalue');        $user_info['gift_sum'] = $gift_sum;        //总收益        $user_info['total'] = $recharge_sum + $video_sum + $audio_sum + $typing_sum + $gift_sum;        $user_info['total'] = bcadd($user_info['total'],0,2);        $this->success(1,$user_info);    }    //成员详情-日历数据    public function user_info_date(){        $user_id = input('user_id',0);        $user_info = Db::name('user')->where('id',$user_id)->field('yaoqingtime')->find();        //日期        $todaytime = strtotime(date('Y-m-d'));//今天凌晨        $page      = input('page',1);        //        $datelist = [];        if(empty($user_info['yaoqingtime'])){            $this->success(1,$datelist);        }        //总共查几天,页数        $days = ceil((time() - strtotime(date('Y-m-d',$user_info['yaoqingtime']))) / 86400);        $pagemax = ceil($days/10);        if($page > $pagemax){            $this->success(1,$datelist);        }        $datelist = [];        for($i=0;$i<10;$i++){ //循环10次            $day = ($page-1)*10 + $i;//往前推的天数            $starttime = $todaytime - $day*86400;            $endtime   = $starttime + 86399;            if($endtime <= $user_info['yaoqingtime']){                break;            }            $thisday = [                'date' => date('m-d',$starttime),            ];            //邀请奖励收益            $recharge_sum = Db::name('user_agentjewel_log')->where('user_id',$user_id)->where('log_type',51)->where('createtime','BETWEEN',[$starttime,$endtime])->sum('change_value');            $thisday['recharge_sum'] = $recharge_sum;            //视频收益            $video_sum = Db::name('user_match_video_log')->where('to_user_id',$user_id)->where('updatetime','BETWEEN',[$starttime,$endtime])->sum('money');            $thisday['video_sum'] = $video_sum;            //语音收益            $audio_sum = Db::name('user_match_audio_log')->where('to_user_id',$user_id)->where('updatetime','BETWEEN',[$starttime,$endtime])->sum('money');            $thisday['audio_sum'] = $audio_sum;            //私信收益            $typing_sum= Db::name('user_match_typing_log')->where('to_user_id',$user_id)->where('createtime','BETWEEN',[$starttime,$endtime])->sum('money');            $thisday['typing_sum'] = $typing_sum;            //礼物收益            $gift_sum  = Db::name('gift_user_typing')->where('user_to_id',$user_id)->where('createtime','BETWEEN',[$starttime,$endtime])->sum('getvalue');            $thisday['gift_sum'] = $gift_sum;            //总收益            $thisday['total'] = $recharge_sum + $video_sum + $audio_sum + $typing_sum + $gift_sum;            $thisday['total'] = bcadd($thisday['total'],0,2);            //            $datelist[] = $thisday;        }        $this->success(1,$datelist);    }}
 |