| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275 | <?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 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;    }    //生成视频分享海报    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);    }    //申请绑定    //申请绑定记录    //日报    public function ribao(){        $authid = $this->auth->id;        $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下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|agent_id','IN',$down_uid)->column('id');//其下直推+其下代理+代理下直推        }        //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;        //在线用户        $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_user_id = input('get_user_id',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_user_id){                $where['id']= $get_user_id;            }            $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_user_id){                $where['id']= $get_user_id;            }            //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['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;        }        $this->success(1,$downall_uid);    }    //成员收入    public function user_shouyi(){    }    //成员详情    //邀请页    //账户中心 api/withdraw/config    //提现 api/withdraw/withdraw    //账户明细}
 |