| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 | <?phpnamespace app\api\controller;use app\common\controller\Api;use think\Db;/** * 会员中心 */class Usercenter extends Api{    protected $noNeedLogin = [];    protected $noNeedRight = '*';    //我的下级    public function myintro(){        $list = Db::name('user')->field('id,nickname,avatar,jointime')->where('intro_uid',$this->auth->id)->autopage()->order('id desc')->select();        $list = list_domain_image($list,['avatar']);        $this->success(1,$list);    }    //用户的业绩总额等    public function my_intro_data(){        //从lib/auth ->getUserinfo 拿过来        $userinfo['score'] = model('wallet')->getWallet($this->auth->id,'score');//积分        $userinfo['withdraw_score'] = Db::name('user_withdraw')->where('user_id',$this->auth->id)->where('status',1)->sum('score');//已兑换积分        $userinfo['share_score'] = Db::name('user_score_log')->where('user_id',$this->auth->id)->where('log_type',3)->sum('change_value');//分享奖励        $userinfo['intro_number'] = Db::name('user')->where('intro_uid',$this->auth->id)->count('id');//我的粉丝        //我的销售总额        $yeji = $this->jiesuan_yeji($this->auth->id);        $userinfo['yeji'] = $yeji;        //我自己的提成        $rule = $this->jiesuan_daili_level($yeji);        $my_agent_score = bcdiv(bcmul($yeji,$rule['bili'],0),100,0);        //我的下级贡献上来的极差提成        $my_down_all_jicha_score = 0; //所有下级极差总额        $my_down_uids = Db::name('user')->where('intro_uid',$this->auth->id)->column('id'); //下级用户ids        if(!empty($my_down_uids)){            foreach($my_down_uids as $down_uid){                $down_yeji = $this->jiesuan_yeji($down_uid);                $down_rule = $this->jiesuan_daili_level($down_yeji);                $jicha_bili = $rule['bili'] - $down_rule['bili'];                $my_down_all_jicha_score = bcadd($my_down_all_jicha_score,bcmul($jicha_bili,$down_yeji));            }        }        //我的提成+下级极差提成        $userinfo['agent_score'] = bcadd($my_agent_score,$my_down_all_jicha_score);        $this->success(1,$userinfo);    }    //生成我的视频海报    //生成邀请码二维码图片    public function inviteimage($introcode) {        $params['text'] = config('h5_url') . '/#/pages/login/register?introcode=' . $introcode;        $qrcode_service = \addons\qrcode\library\Service::qrcode($params);//        $mimetype = 'image/png';//        $response = Response::create()->header("Content-Type", $mimetype);        // 直接显示二维码//        header('Content-Type: ' . $qrcode_service->getContentType());//        $response->content($qrcode_service->writeString());        $qrcodePath = ROOT_PATH . 'public/uploads/qrcode/';        if (!is_dir($qrcodePath)) {            @mkdir($qrcodePath);        }        if (is_really_writable($qrcodePath)) {            $filename = md5(implode('', $params)) . '.png';            $filePath = $qrcodePath . $filename;            $qrcode_service->writeFile($filePath);        }        return '/uploads/qrcode/' . $filename;    }    //生成视频分享海报    public function shareposter() {        $inviteimage = $this->inviteimage($this->auth->introcode);        $data = [            [                "left"=> "100px",                "top"=> "424px",                "type"=> "nickname",                "width"=> "166px",                "height"=> "38px",                "size"=> "11px",                "color"=> "#333333",                "content" => '邀请码:'.$this->auth->introcode,            ],            [                "left"=> "90px",                "top"=> "260px",                "type"=> "img",                "width"=> "140px",                "height"=> "140px",                "src"=> httpurllocal($inviteimage)//"https://metavision.oss-cn-hongkong.aliyuncs.com/uploads/20220615/f00cb545deb4c4e7296f444239d83e84.jpg"            ],        ];        $data = json_encode($data, 320);        $poster = [            'id' => 1,            '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_user($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 jiesuan_yeji($user_id){        //找到所有下级        $commonuser = new \app\common\model\User();        $user_ids = $commonuser->my_down_all($user_id,[$user_id]);        if(empty($user_ids)){            return 0;        }        $map = [            'status' => 1,            'have_paid' => ['gt',0],            'user_id' => ['IN',$user_ids],        ];        $yeji = Db::name('unishop_order')->where($map)->sum('order_price');        //减去提现的        $map = [            'status' => 1,            'user_id' => ['IN',$user_ids],        ];        $take_cash = Db::name('user_withdraw')->where($map)->sum('score');        $yeji = $yeji - $take_cash;        return $yeji;    }    //确认代理等级及规则    private function jiesuan_daili_level($yeji){        $data = Db::name('zongdai')->order('id asc')->select();        $return = $data[0]; //默认第0个        foreach($data as $key => $rule){            if($yeji >= $rule['yeji']){                $return = $rule;            }        }        return $return;    }}
 |