审查视图

application/api/controller/User.php 24.5 KB
1 2
<?php
何书鹏 authored
3
namespace app\api\controller;
4
Karson authored
5
use app\common\library\Ems;
6 7 8
use app\common\library\Sms;
use fast\Random;
use think\Validate;
何书鹏 authored
9 10 11 12 13
use addons\shopro\library\Wechat;
use think\Db;
use addons\shopro\model\UserOauth;
use addons\shopro\model\User as UserModel;
use addons\shopro\model\UserStore;
何书鹏 authored
14
use app\api\model\PackageOrder;
何书鹏 authored
15
use app\api\model\Package;
16 17 18 19

/**
 * 会员接口
 */
何书鹏 authored
20
class User extends Base
21
{
macbook authored
22
    protected $noNeedLogin = ['package','login', 'mobilelogin', 'accountLogin', 'wxMiniProgramLogin', 'getWxMiniProgramSessionKey', 'getUserDefaultFields','serviePhone'];
23 24 25 26
    protected $noNeedRight = '*';

    public function _initialize()
    {
何书鹏 authored
27
        return parent::_initialize();
28 29 30
    }

    /**
何书鹏 authored
31 32 33 34 35 36 37 38 39 40
     * @ApiWeigh    (99)
     * @ApiTitle    (会员中心)
     * @ApiSummary  (会员中心)
     * @ApiMethod   (GET)
     *
     * @ApiHeaders (name=token, type=string, required=true, description="请求的token")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "用户信息",
何书鹏 authored
41
        "time": "1607908165",
何书鹏 authored
42 43
        "data": {
            "id": 1, //用户ID
何书鹏 authored
44 45 46 47 48
            "group_id": 1, //分组ID
            "nickname": "123", //昵称
            "avatar": "shuoshenme", //头像
            "money": "0.00", //余额
            "score": 0, //积分
何书鹏 authored
49 50 51 52 53 54 55 56
            "token": "1419ae8b-dd47-4ab5-9c10-c88d42dc4cb3",
            "user_id": 1,
            "createtime": 1607397247,
            "expiretime": 1609989247,
            "expires_in": 2081082,
            "group": {
            "name": "默认组",
            "image": "http://www.ant.top"
何书鹏 authored
57
            },
何书鹏 authored
58
            "coupons_num": 0, //优惠券数量
何书鹏 authored
59 60
            "is_store": 1,
            "store_id": 1,
何书鹏 authored
61 62
            "avatar_full": "http://www.ant.topshuoshenme", //头像全路径
            "is_vip": 1, //是否会员:0=否,1=是
何书鹏 authored
63 64
            "vip_start_time": "2020/08/02", //开通会员初始时间
            "vip_end_time": "2021/08/02", //会员到期时间
何书鹏 authored
65
            "commission": 0", //待提现佣金
何书鹏 authored
66 67
        }
    })
68 69 70
     */
    public function index()
    {
何书鹏 authored
71
        $auth = \app\common\library\Auth::instance();
何书鹏 authored
72
        $auth->setAllowFields(['id', 'nickname', 'avatar', 'score', 'money','group_id','vip_start_time','vip_end_time','commission']);
何书鹏 authored
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
        $data = $auth->getUserinfo();
        if (!isset($data['group'])) {
            $data['group'] = \addons\shopro\model\UserGroup::get($data['group_id']);
        }

        // 查询用户优惠券数量
        $userCoupons = \addons\shopro\model\Coupons::getCouponsList(1);
        $data['coupons_num'] = count($userCoupons);

        // 查询用户是否是门店管理员
        $userStores = UserStore::where('user_id', $data['id'])->select();
        $data['is_store'] = $userStores ? 1 : 0;
        $data['store_id'] = 0;
        if (count($userStores) == 1) {
            // 只有一个店铺 直接进入店铺
            $data['store_id'] = $userStores[0]['store_id'];
        }
何书鹏 authored
90
        // 头像全路径
何书鹏 authored
91
        $data['avatar_full'] = !empty($data['avatar']) ? cdnurl($data['avatar'],true) : '';
何书鹏 authored
92
        // 是否会员:0=否,1=是
何书鹏 authored
93 94 95
        $data['is_vip'] = $data['vip_end_time'] > time() ? 1 : 0;
        $data['vip_start_time'] = date('Y/m/d',$data['vip_start_time']);
        $data['vip_end_time'] = date('Y/m/d',$data['vip_end_time']);
何书鹏 authored
96
        $this->success('用户信息', $data);
97 98 99
    }

    /**
何书鹏 authored
100 101 102 103 104 105 106 107 108
     * @ApiWeigh    (98)
     * @ApiTitle    (会员套餐)
     * @ApiSummary  (会员套餐)
     * @ApiMethod   (GET)
     *
     * @ApiReturn({
        "code": 1,
        "msg": "会员套餐",
        "time": "1608621344",
何书鹏 authored
109 110 111 112 113 114 115
        "data": [{ //会员套餐列表
            "id": 1, //套餐ID
            "package_name": "季度会员", //套餐名称
            "package_price": "150.00", //套餐价格
            "month": 3, //会员持续月数
            "content": "富文本内容" //会员权益
        }],
何书鹏 authored
116 117 118 119
    })
     */
    public function package()
    {
何书鹏 authored
120
        $data = Package::field('id,package_name,package_price,month,content')
何书鹏 authored
121 122
            ->order('weigh desc')
            ->select();
何书鹏 authored
123
        $this->success('会员套餐',$data);
何书鹏 authored
124 125 126 127
    }

    /**
     * @ApiWeigh    (98)
何书鹏 authored
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
     * @ApiTitle    (会员套餐-购买记录)
     * @ApiSummary  (会员套餐-购买记录)
     * @ApiMethod   (GET)
     *
     * @ApiHeaders (name=token, type=string, required=true, description="请求的token")
     * @ApiParams (name=page, type=inter, required=true, description="分页")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "会员套餐-购买记录",
        "time": "1608723584",
        "data": {
            "total": 2, //数据总数
            "per_page": 10,
            "current_page": 1,
            "last_page": 1,
            "data": [{ //记录列表
                "id": 4, //记录ID
                "remark": "续费(12个月)", //注释
                "pay_fee": "150.00", //支付费用
                "paytime": "2020.12.23" //充值时间
            }]
        }
    })
     */
    public function packageOrderList()
    {
        $list = PackageOrder::where('user_id',$this->auth->id)
            ->where('status',1)
            ->field('id,remark,pay_fee,paytime')
            ->order('paytime desc')
            ->paginate(10)
            ->each(function($v){
                $v->paytime = date('Y.m.d',$v['paytime']);
            });
        $this->success('会员套餐-购买记录',$list);
    }

    /**
     * @ApiWeigh    (98)
何书鹏 authored
168 169 170 171 172 173
     * @ApiTitle    (会员登录)
     * @ApiSummary  (会员登录)
     * @ApiMethod   (POST)
     *
     * @ApiParams (name=account, type=string, required=true, description="账号")
     * @ApiParams (name=password, type=string, required=true, description="密码")
174
     *
何书鹏 authored
175
     * @ApiReturn()
176
     */
何书鹏 authored
177
    public function accountLogin()
178
    {
何书鹏 authored
179 180
        $account = $this->request->post('account');
        $password = $this->request->post('password');
181
        if (!$account || !$password) {
182 183 184
            $this->error(__('Invalid parameters'));
        }
        $ret = $this->auth->login($account, $password);
185
        if ($ret) {
186 187
            $data = ['userinfo' => $this->auth->getUserinfo()];
            $this->success(__('Logged in successful'), $data);
188
        } else {
189 190 191 192 193
            $this->error($this->auth->getError());
        }
    }

    /**
何书鹏 authored
194 195 196 197
     * @ApiWeigh    (97)
     * @ApiTitle    (获取微信小程序session_key)
     * @ApiSummary  (获取微信小程序session_key)
     * @ApiMethod   (POST)
198
     *
何书鹏 authored
199 200
     * @ApiParams (name=code, type=string, required=true, description="加密code")
     *
何书鹏 authored
201 202 203 204 205 206 207 208 209
     * @ApiReturn({
        "code": 1,
        "msg": "用户信息",
        "time": "1607588102",
        "data": {
            "openid": 123456, //openid
            "session_key": 123456, //session_key
        }
    })
210
     */
何书鹏 authored
211
    public function getWxMiniProgramSessionKey()
212
    {
何书鹏 authored
213 214 215 216
        $post = $this->request->post();
        $wechat = new Wechat('wxMiniProgram');
        $decryptSession = $wechat->code($post['code']);
        $this->success('获取session_key', $decryptSession);
217 218 219
    }

    /**
何书鹏 authored
220 221 222 223 224 225 226 227
     * @ApiWeigh    (97)
     * @ApiTitle    (微信小程序登录)
     * @ApiSummary  (微信小程序登录)
     * @ApiMethod   (POST)
     *
     * @ApiParams (name=session_key, type=string, required=true, description="session_key")
     * @ApiParams (name=iv, type=string, required=true, description="iv")
     * @ApiParams (name=encryptedData, type=string, required=true, description="encryptedData")
何书鹏 authored
228
     * @ApiParams (name=user_id, type=inter, required=false, description="扫码获取的用户ID")
229
     *
何书鹏 authored
230 231 232 233 234 235 236
     * @ApiReturn({
        'code':'1',
        'msg':'返回成功',
        "data": {
            "token": "9e4648c7-c640-4e41-b758-dd1a8ef7a7ae",
        }
    })
237
     */
何书鹏 authored
238
    public function wxMiniProgramLogin()
239
    {
何书鹏 authored
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
        $post = $this->request->post();
        $wechat = new Wechat('wxMiniProgram');
        $decryptUserInfo = $wechat->decryptData($post['session_key'], $post['iv'], $post['encryptedData']);
//        array(10) {
//        ["openId"] => string(28) "oD9ko40ZEoru7bjzN2f0Wnm3uNmA"
//        ["nickName"] => string(12) "Civilization"
//        ["gender"] => int(1)
//        ["language"] => string(5) "zh_CN"
//        ["city"] => string(0) ""
//        ["province"] => string(0) ""
//        ["country"] => string(7) "Iceland"
//        ["avatarUrl"] => string(124) "https://wx.qlogo.cn/mmopen/vi_32/bKchg38ErVBnuJBb4NfCOYkMsxgzZ3vZGu7y7V0BQG8clImsyvZge2HzGGYfxXKBNv8dbQOvyvmjKPEtRyrniaA/132"
//        ["unionId"] => string(28) "odsYQ1MLsGSGL6Gp5f6y3at2j7Hg"
//        ["watermark"] => array(2) {
//            ["timestamp"] => int(1590344429)
//            ["appid"] => string(18) "wx39cd0799d4567dd0"
//             }
//        }
        //组装decryptData
        $decryptData = array_change_key_case($decryptUserInfo, CASE_LOWER);
        $decryptData['headimgurl'] = $decryptData['avatarurl'];
        $decryptData['sex'] = $decryptData['gender'];
        $decryptData['session_key'] = $post['session_key'];
        if (empty($decryptData['openid'])) {
            $this->error(__('code错误'), $decryptData);
        }
何书鹏 authored
266 267
        $pid = isset($post['user_id']) ? $post['user_id'] : 0;
        $ret = $this->oauthLoginOrRegister($decryptData, 'wxMiniProgram', 'Wechat',0, $pid);
268
        if ($ret) {
何书鹏 authored
269
            $data = $ret->getUserinfo();
270
何书鹏 authored
271 272
            if (!isset($data['group'])) {
                $data['group'] = \addons\shopro\model\UserGroup::get($data['group_id']);
273
            }
何书鹏 authored
274
            $this->success(__('Logged in successful'), $data);
275 276
        }
何书鹏 authored
277
        $this->error($this->auth->getError());
278 279 280
    }

    /**
何书鹏 authored
281
     * 第三方登录或自动注册
282
     *
何书鹏 authored
283
     * @param string $decryptData 解密参数
284
     * @param string $platform 平台名称
何书鹏 authored
285 286
     * @param string $provider 厂商名称
     * @param string $keeptime 有效时长
何书鹏 authored
287
     * @param string $pid 绑定上级
288
     */
何书鹏 authored
289
    private function oauthLoginOrRegister($decryptData, $platform, $provider, $keeptime = 0, $pid = 0)
290
    {
何书鹏 authored
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
        extract($decryptData);
        @$oauthData = compact('provider', 'unionid', 'platform', 'openid', 'nickname', 'sex', 'city', 'province', 'country', 'headimgurl', 'session_key', 'refresh_token', 'access_token');
        $oauthData['logintime'] = time();
        $oauthData['logincount'] = 1;
        if ($platform === 'wxMiniProgram' || $platform === 'App') {
            $oauthData['expire_in'] = 7200;
            $oauthData['expiretime'] = time() + 7200;
        }
        $auth = \app\common\library\Auth::instance();
        $auth->keeptime($keeptime);
        $auth->setAllowFields(['id', 'username', 'nickname', 'mobile', 'avatar', 'score', 'money', 'group', 'group_id']);

        $userOauth = UserOauth::get(['openid' => $openid]);
        if (isset($decryptData['nickname'])) {
            $fields['nickname'] = $decryptData['nickname'];
        }
        if (isset($decryptData['headimgurl'])) {
            $fields['avatar'] = $decryptData['headimgurl'];
        }
        //开启事务
        Db::startTrans();
        try {
            if ($userOauth) {
                //找到对应已注册用户,更新oauthData数据和用户数据直接发起登录
                $user_id = $userOauth->user_id;
                $user = UserModel::get($user_id);
                $oauthData['logincount'] = $userOauth->logincount + 1;
                $userOauth->save($oauthData);
            } else {
                //添加新的oauthData数据

                //默认创建新用户
                $createNewUser = true;
                // 判断是否有unionid 并且已存在oauth数据中
                if (isset($unionid)) {
                    //存在同厂商信息,添加oauthData数据,合并用户
                    $user_id = UserOauth::where(['unionid' => $unionid])->value('user_id');
                    $user = UserModel::get($user_id);
                    if ($user) {
                        $createNewUser = false;
                    }
                }
                if ($createNewUser) {
                    // 创建空用户
                    $username = Random::alnum(20);
                    $password = '';
                    $domain = request()->host();
                    $extend = $this->getUserDefaultFields();
何书鹏 authored
339 340 341
                    if($pid > 0){ //绑定上级
                        $extend['pid'] = $pid;
                    }
何书鹏 authored
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
                    $result = $auth->register($username, $password, $username . '@' . $domain, '', $extend, $keeptime);
                    if (!$result) {
                        return false;
                    }
                    $user = $auth->getUser();
                    if (!isset($fields['nickname'])) {
                        //默认昵称
                        $fields['nickname'] = $extend['nickname'] . $user->id;
                    }
                    // 更新会员资料
                    $user = UserModel::get($user->id);
                    // 保存第三方信息
                    $user_id = $user->id;
                }
                $oauthData['user_id'] = $user_id;
                UserOauth::create($oauthData);
358
            }
何书鹏 authored
359 360 361 362 363 364 365
            if (isset($fields)) $user->save($fields);
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
            $auth->logout();
            $this->error($e->getMessage());
            return false;
366
        }
何书鹏 authored
367 368 369 370

        $auth->direct($user_id);

        return $auth;
371 372
    }
何书鹏 authored
373 374
    /**
     * @ApiWeigh    (97)
何书鹏 authored
375 376
     * @ApiTitle    (修改会员个人信息)
     * @ApiSummary  (修改会员个人信息)
何书鹏 authored
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406
     * @ApiMethod   (POST)
     *
     * @ApiParams (name=nickname, type=string, required=true, description="昵称")
     * @ApiParams (name=avatar, type=string, required=true, description="头像")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "",
        "time": "1607398637",
        "data": null
    })
     */
    public function profile()
    {
        $user = $this->auth->getUser();
        $nickname = $this->request->post('nickname');
        $avatar = $this->request->post('avatar', '', 'trim,strip_tags,htmlspecialchars');
        if(empty($nickname) && empty($avatar)){
            $this->error('请填写修改内容');
        }
        if(!empty($nickname)){
            $user->nickname = $nickname;
        }
        if(!empty($avatar)){
            $user->avatar = $avatar;
        }
        $user->save();
        $this->success();
    }
何书鹏 authored
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490
    /**
     * @ApiWeigh    (95)
     * @ApiTitle    (分销中心-我的下级-1级)
     * @ApiSummary  (分销中心-我的下级-1级)
     * @ApiMethod   (GET)
     *
     * @ApiHeaders (name=token, type=string, required=true, description="请求的token")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "分销中心-我的下级-1级",
        "time": "1608727151",
        "data": {
            "total": 1, //数据总数
            "per_page": 10,
            "current_page": 1,
            "last_page": 1,
            "data": [{ //列表
                "id": 2, //用户ID
                "nickname": "wn56", //昵称
                "avatar": "https://yixiaoxian.qiniu.broing.cn/uploads/20201214/8f6a49f6873028e0e7aba28b28eb9d56.png", //头像
                "createtime": "2020/12/11", //时间
                "url": "/u/2"
            }]
        }
    })
     */
    public function lowerList()
    {
        $first_id_arr = UserModel::where('pid',$this->auth->id)->column('id');
        $where = $first_id_arr ? ['id'=>['in',$first_id_arr]] : ['id'=>0];
        $list = UserModel::where($where)
            ->paginate(10)
            ->each(function($v){
                $v->createtime = date('Y/m/d',$v['createtime']);
                $v->visible(['id','createtime','avatar','nickname']);
            });
        $this->success('分销中心-我的下级-1级',$list);
    }

    /**
     * @ApiWeigh    (95)
     * @ApiTitle    (分销中心-我的下级-2级)
     * @ApiSummary  (分销中心-我的下级-2级)
     * @ApiMethod   (GET)
     *
     * @ApiHeaders (name=token, type=string, required=true, description="请求的token")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "分销中心-我的下级-2级",
        "time": "1608727151",
        "data": {
            "total": 1, //数据总数
            "per_page": 10,
            "current_page": 1,
            "last_page": 1,
            "data": [{ //列表
                "id": 2, //用户ID
                "nickname": "wn56", //昵称
                "avatar": "https://yixiaoxian.qiniu.broing.cn/uploads/20201214/8f6a49f6873028e0e7aba28b28eb9d56.png", //头像
                "createtime": "2020/12/11", //时间
                "url": "/u/2"
            }]
        }
    })
     */
    public function lowersList()
    {
        $second_id_arr = [];
        $first_id_arr = UserModel::where('pid',$this->auth->id)->column('id');
        foreach ($first_id_arr as $first_id){
            $second_id_arr = array_merge(UserModel::where('pid',$first_id)->column('id'),$second_id_arr);
        }
        $where = $second_id_arr ? ['id'=>['in',$second_id_arr]] : ['id'=>0];
        $list = UserModel::where($where)
            ->paginate(10)
            ->each(function($v){
                $v->createtime = date('Y/m/d',$v['createtime']);
                $v->visible(['id','createtime','avatar','nickname']);
            });
        $this->success('分销中心-我的下级-2级',$list);
    }
何书鹏 authored
491
    private function getUserDefaultFields()
492
    {
何书鹏 authored
493 494
        $userConfig = json_decode(\addons\shopro\model\Config::get(['name' => 'user'])->value,true);
        return $userConfig;
495
    }
何书鹏 authored
496 497 498 499 500 501 502 503 504 505

    /**
     * @ApiWeigh    (85)
     * @ApiTitle    (我的二维码)
     * @ApiSummary  (我的二维码)
     * @ApiMethod   (GET)
     *
     * @ApiHeaders  (name="token", type="string", required=true, description="请求的token")
     *
     * @ApiReturn   ({
何书鹏 authored
506 507 508
        "code": 1,
        "msg": "成功",
        "time": "1609056357",
何书鹏 authored
509
        "data": {
何书鹏 authored
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589
            "url": "http://www.ant.top/uploads/user/1.png?v=1609056359", //海报地址
            "goods": { //免费领取海报商品
                "id": 1, //商品ID
                "type": "normal",
                "title": "分销海报",
                "subtitle": "分销海报",
                "weigh": 0,
                "category_ids": "3",
                "image": "https://yixiaoxian.qiniu.broing.cn/uploads/20201224/FpqzUt7YTrXlZUsarlqD8heEHA4O.png",
                "images": [
                    "https://yixiaoxian.qiniu.broing.cn/uploads/20201224/FpqzUt7YTrXlZUsarlqD8heEHA4O.png"
                ],
                "params": [],
                "content": "海报",
                "price": "0",
                "original_price": "100.00",
                "is_sku": 0,
                "likes": 0,
                "views": 100,
                "sales": 0,
                "show_sales": 0,
                "service_ids": "",
                "dispatch_type": "express",
                "dispatch_ids": "1",
                "deletetime": null,
                "activity": null,
                "activity_type": null,
                "sku_price": [{ //商品规格
                    "id": 1, //规格ID
                    "goods_sku_ids": null,
                    "goods_id": 1,
                    "weigh": 0,
                    "image": null,
                    "stock": 999999,
                    "sales": 0,
                    "sn": "",
                    "weight": 0,
                    "price": "0.00", //商品价格
                    "goods_sku_text": null,
                    "status": "up",
                    "goods_sku_id_arr": [
                        ""
                    ]
                }],
                "stock": 999999,
                "favorite": {
                    "id": 6,
                    "user_id": 1,
                    "goods_id": 1,
                    "deletetime": null
                },
                "dispatch_type_arr": [
                    "express"
                ],
                "service": [],
                "sku": [],
                "coupons": [{
                    "id": 1,
                    "name": "满100减10",
                    "type": "cash",
                    "goods_ids": "0",
                    "amount": "10.00",
                    "enough": "100.00",
                    "stock": 0,
                    "limit": 1,
                    "gettime": {
                        "start": 1607875200,
                        "end": 1610640000
                    },
                    "usetime": {
                        "start": "2020.12.18",
                        "end": "2021.01.30"
                    },
                    "description": "满100减10",
                    "usetimestart": 1608220800,
                    "usetimeend": 1611936000,
                    "gettimestart": 1607875200,
                    "gettimeend": 1610640000
                }]
            }
何书鹏 authored
590 591 592 593 594 595 596 597 598
        }
    })
     */
    public function userPoster()
    {
        $user = UserModel::get($this->auth->id);
        $avatar_url = !empty($user['avatar']) ? cdnurl($user['avatar']) : '';
        empty($avatar_url) && $this->error('请先上传头像');
        !url_exists($avatar_url) && $this->error('头像失效,请更新头像');
1  
macbook authored
599
        // 本地路径
何书鹏 authored
600 601 602 603 604 605
        $dir = 'uploads/user';
        if (!file_exists($dir)){
            mkdir($dir,0777,true);
        }

        // 用户小程序码
1  
macbook authored
606
        $qrcode = $dir.'/qrcode_'.$user['id'].'.png';
1  
macbook authored
607
        if(!file_exists($qrcode)){
1  
macbook authored
608 609
            $wechat = new Wechat('wxMiniProgram');
            $response = $wechat->getApp()->app_code->getUnlimit($user['id'], [
1  
macbook authored
610
               'page'  => 'pages/vip/vip',
macbook authored
611 612 613
               'width' => 280, //最小宽度280
            ]);
            if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) {
1  
macbook authored
614
               $response->saveAs($dir, str_replace($dir.'/','',$qrcode));
macbook authored
615 616
            }
            // 280不满足,再缩小
何书鹏 authored
617
            \think\Image::open($qrcode)->thumb(211,211)->save($qrcode);
1  
macbook authored
618 619
        }
macbook authored
620
        // $qrcode = ROOT_PATH.'public/assets/img/miniProgram/qrcode.png';
何书鹏 authored
621 622 623 624

        //将用户头像保存到本地
        $avatar = $dir.'/avatar_'.$user['id'].'.png';
        file_put_contents($avatar,file_get_contents($avatar_url));
何书鹏 authored
625
        \think\Image::open($avatar)->thumb(115,115,\think\Image::THUMB_CENTER)->save($avatar);
何书鹏 authored
626 627
        createRoundImg($avatar);
1  
macbook authored
628
        $path_ttf = ROOT_PATH.'public/assets/fonts/PingFang.ttf';
何书鹏 authored
629 630 631 632
        $filename = $dir.'/'.$user['id'].'.png';

        //将海报背景保存到本地
        $share = json_decode(\addons\shopro\model\Config::where(['name' => 'share'])->value('value'), true);
何书鹏 authored
633
        $user_poster_bg = $dir.'/user_poster_bg.png';
何书鹏 authored
634
        file_put_contents($user_poster_bg,file_get_contents(cdnurl($share['user_poster_bg'])));
1  
macbook authored
635
        // halt(request()->domain().'/'.$qrcode);
何书鹏 authored
636 637
        // 生成海报
        \think\Image::open($user_poster_bg)
何书鹏 authored
638 639 640 641 642
            ->water($avatar,[123,1343])
            ->text($user['nickname'],$path_ttf,30,'#ffffff',[262,1382])
            ->text($user['nickname'],$path_ttf,30,'#ffffff',[262+0.5,1382+0.5])
            ->text($user['nickname'],$path_ttf,30,'#ffffff',[262+0.5+0.5,1382+0.5+0.5])
            ->water($qrcode,[718,1314])
何书鹏 authored
643 644
            ->save($filename);
        $url = request()->domain().'/'.$filename.'?v='.time();
何书鹏 authored
645
        // 免费领取推广海报商品
macbook authored
646
        $goods = \addons\shopro\model\Goods::where('status','up')->where('id',1)->find();
macbook authored
647 648 649 650 651
        if($goods){
            $goods = $goods->append(['service', 'sku', 'coupons']);
            // 处理活动规格
            $goods = \addons\shopro\model\Goods::operActivitySkuPrice($goods, $goods->sku_price);
        }
何书鹏 authored
652
        $this->success('成功',compact('url','goods'));
何书鹏 authored
653
    }
何书鹏 authored
654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674

    /**
     * @ApiWeigh    (83)
     * @ApiTitle    (分销说明)
     * @ApiSummary  (分销说明)
     * @ApiMethod   (GET)
     *
     * @ApiReturn({
        "code": 1,
        "msg": "会员套餐",
        "time": "1608621344",
        "data": {
            "description": "富文本内容" //会员权益
        }
    })
     */
    public function distribution()
    {
        $description = \addons\shopro\model\Richtext::get(2)['content'];
        $this->success('分销说明',compact('description'));
    }
macbook authored
675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697

    /**
     * @ApiWeigh    (81)
     * @ApiTitle    (联系客服)
     * @ApiSummary  (联系客服)
     * @ApiMethod   (GET)
     *
     * @ApiReturn({
        "code": 1,
        "msg": "联系客服",
        "time": "1608621344",
        "data": {
            "service_phone": "0311-02056" //客服电话
        }
    })
     */
    public function serviePhone()
    {
        $user = json_decode(\addons\shopro\model\Config::where(['name' => 'user'])->value('value'), true);
        $this->success('联系客服',[
            'service_phone' => $user['service_phone']
        ]);
    }
698
}