User.php 29.8 KB
Newer Older
D
v1.2.0  
devil_gong 已提交
1 2 3 4
<?php
// +----------------------------------------------------------------------
// | ShopXO 国内领先企业级B2C免费开源电商系统
// +----------------------------------------------------------------------
D
2.0  
Devil 已提交
5
// | Copyright (c) 2011~2099 http://shopxo.net All rights reserved.
D
v1.2.0  
devil_gong 已提交
6
// +----------------------------------------------------------------------
D
2.0  
Devil 已提交
7
// | Licensed ( https://opensource.org/licenses/mit-license.php )
D
v1.2.0  
devil_gong 已提交
8 9 10 11 12
// +----------------------------------------------------------------------
// | Author: Devil
// +----------------------------------------------------------------------
namespace app\api\controller;

D
Devil 已提交
13
use app\service\ApiService;
D
Devil 已提交
14
use app\service\SystemBaseService;
15 16 17 18
use app\service\UserService;
use app\service\OrderService;
use app\service\GoodsService;
use app\service\MessageService;
D
devil_gong 已提交
19
use app\service\AppCenterNavService;
D
devil 已提交
20
use app\service\BuyService;
D
devil 已提交
21 22 23
use app\service\GoodsFavorService;
use app\service\GoodsBrowseService;
use app\service\IntegralService;
G
gongfuxiang 已提交
24
use app\service\AppMiniUserService;
D
v1.2.0  
devil_gong 已提交
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48

/**
 * 用户
 * @author   Devil
 * @blog     http://gong.gg/
 * @version  0.0.1
 * @datetime 2016-12-01T21:51:08+0800
 */
class User extends Common
{
    /**
     * [__construct 构造方法]
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  0.0.1
     * @datetime 2016-12-03T12:39:08+0800
     */
    public function __construct()
    {
        // 调用父类前置方法
        parent::__construct();
    }

    /**
49 50 51 52 53 54
     * 用户登录
     * @author  Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2021-03-04
     * @desc    description
D
v1.2.0  
devil_gong 已提交
55
     */
56
    public function Login()
D
v1.2.0  
devil_gong 已提交
57
    {
D
Devil 已提交
58
        return ApiService::ApiDataReturn(UserService::Login($this->data_post));
59
    }
D
v1.2.0  
devil_gong 已提交
60

61 62 63 64 65 66 67 68 69 70
    /**
     * 用户登录-验证码发送
     * @author  Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2021-03-04
     * @desc    description
     */
    public function LoginVerifySend()
    {
D
Devil 已提交
71
        return ApiService::ApiDataReturn(UserService::LoginVerifySend($this->data_post));
D
v1.2.0  
devil_gong 已提交
72 73 74
    }

    /**
75 76 77 78 79 80 81 82 83
     * 用户注册
     * @author  Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2021-03-04
     * @desc    description
     */
    public function Reg()
    {
D
Devil 已提交
84
        return ApiService::ApiDataReturn(UserService::Reg($this->data_post));
85 86 87 88 89 90 91 92 93
    }

    /**
     * 用户注册-验证码发送
     * @author  Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2021-03-04
     * @desc    description
D
v1.2.0  
devil_gong 已提交
94 95 96
     */
    public function RegVerifySend()
    {
D
Devil 已提交
97
        return ApiService::ApiDataReturn(UserService::RegVerifySend($this->data_post));
98
    }
D
v1.2.0  
devil_gong 已提交
99

100 101 102 103 104 105 106 107 108 109
    /**
     * 密码找回
     * @author  Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2021-03-04
     * @desc    description
     */
    public function ForgetPwd()
    {
D
Devil 已提交
110
        return ApiService::ApiDataReturn(UserService::ForgetPwd($this->data_post));
D
v1.2.0  
devil_gong 已提交
111 112 113
    }

    /**
114 115 116 117 118 119 120 121 122
     * 密码找回-验证码发送
     * @author  Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2021-03-04
     * @desc    description
     */
    public function ForgetPwdVerifySend()
    {
D
Devil 已提交
123
        return ApiService::ApiDataReturn(UserService::ForgetPwdVerifySend($this->data_post));
124 125 126
    }

    /**
G
gongfuxiang 已提交
127
     * app用户手机绑定
128 129 130 131 132 133
     * @author  Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2021-03-04
     * @desc    description
     */
G
gongfuxiang 已提交
134
    public function AppMobileBind()
135
    {
G
gongfuxiang 已提交
136
        return ApiService::ApiDataReturn(UserService::AppMobileBind($this->data_post));
137 138 139
    }

    /**
G
gongfuxiang 已提交
140
     * app用户手机绑定-验证码发送
141 142 143 144 145 146
     * @author  Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2021-03-04
     * @desc    description
     */
G
gongfuxiang 已提交
147
    public function AppMobileBindVerifySend()
148
    {
G
gongfuxiang 已提交
149
        return ApiService::ApiDataReturn(UserService::AppMobileBindVerifySend($this->data_post));
150 151 152
    }

    /**
G
gongfuxiang 已提交
153
     * 用户-验证码显示
154 155 156 157 158 159
     * @author  Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2021-03-04
     * @desc    description
     */
G
gongfuxiang 已提交
160
    public function UserVerifyEntry()
161
    {
G
gongfuxiang 已提交
162 163 164 165 166 167 168
        $params = [
                'width'         => 100,
                'height'        => 28,
                'key_prefix'    => input('type', 'user_reg'),
            ];
        $verify = new \base\Verify($params);
        $verify->Entry();
169 170
    }

G
gongfuxiang 已提交
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 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 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 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 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383
    /**
     * 支付宝用户授权
     * @author  Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2021-03-04
     * @desc    description
     */
    public function AlipayUserAuth()
    {
        // 参数
        if(!empty($this->data_post['authcode']))
        {
            // 授权
            $result = (new \base\Alipay())->GetAuthSessionKey(MyC('common_app_mini_alipay_appid'), $this->data_post['authcode']);
            if($result['status'] == 0)
            {
                // 先从数据库获取用户信息
                $user = UserService::AppUserInfoHandle(null, 'alipay_openid', $result['data']['user_id']);
                if(empty($user))
                {
                    $ret = DataReturn('授权登录成功', 0, ['is_user_exist'=>0, 'openid'=>$result['data']['user_id']]);
                } else {
                    // 用户状态
                    $ret = UserService::UserStatusCheck('id', $user['id']);
                    if($ret['code'] == 0)
                    {
                        // 标记用户存在
                        $user['is_user_exist'] = 1;
                        $ret = DataReturn('授权登录成功', 0, $user);
                    }
                }
            } else {
                $ret = DataReturn($result['msg'], -100);
            }
        } else {
            $ret = DataReturn('授权码为空', -1);
        }
        return ApiService::ApiDataReturn($ret);
    }

    /**
     * 支付宝小程序获取用户信息
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-11-06
     * @desc    description
     */
    public function AlipayUserInfo()
    {
        // 参数校验
        $p = [
            [
                'checked_type'      => 'empty',
                'key_name'          => 'openid',
                'error_msg'         => 'openid为空',
            ],
        ];
        $ret = ParamsChecked($this->data_post, $p);
        if($ret === true)
        {
            // 先从数据库获取用户信息
            $user = UserService::AppUserInfoHandle(null, 'alipay_openid', $this->data_post['openid']);
            if(empty($user))
            {
                $this->data_post['nickname'] = isset($this->data_post['nickName']) ? $this->data_post['nickName'] : '';
                $this->data_post['gender'] = empty($this->data_post['gender']) ? 0 : (($this->data_post['gender'] == 'f') ? 1 : 2);
                $ret = UserService::AuthUserProgram($this->data_post, 'alipay_openid');
            } else {
                // 用户状态
                $ret = UserService::UserStatusCheck('id', $user['id']);
                if($ret['code'] == 0)
                {
                    $ret = DataReturn('授权成功', 0, $user);
                }
            }
        } else {
            $ret = DataReturn($ret, -1);
        }
        return ApiService::ApiDataReturn($ret);
    }

    /**
     * 微信小程序获取用户授权
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-11-06
     * @desc    description
     */
    public function WechatUserAuth()
    {
        // 授权
        $result = (new \base\Wechat(MyC('common_app_mini_weixin_appid'), MyC('common_app_mini_weixin_appsecret')))->GetAuthSessionKey($this->data_post);
        if($result['status'] == 0)
        {
            // unionid
            $unionid = empty($result['data']['unionid']) ? '' : $result['data']['unionid'];

            // 先从数据库获取用户信息
            $user = UserService::AppUserInfoHandle(null, 'weixin_openid', $result['data']['openid']);
            if(empty($user) && !empty($unionid))
            {
                // 根据unionid获取数据
                $user = UserService::AppUserInfoHandle(null, 'weixin_unionid', $unionid);
            }
            if(empty($user))
            {
                $ret = DataReturn('授权登录成功', 0, ['is_user_exist'=>0, 'openid'=>$result['data']['openid'], 'unionid'=>$unionid]);
            } else {
                // 如果用户openid为空则绑定到用户下面
                if(empty($user['weixin_openid']))
                {
                    if(UserService::UserOpenidBind($user['id'], $result['data']['openid'], 'weixin_openid'))
                    {
                        // 登录数据更新
                        $user = UserService::AppUserInfoHandle($user['id']);
                    }
                }
            }

            // 用户状态
            if(!empty($user))
            {
                $ret = UserService::UserStatusCheck('id', $user['id']);
                if($ret['code'] == 0)
                {
                    // 标记用户存在
                    $user['is_user_exist'] = 1;
                    $ret = DataReturn('授权登录成功', 0, $user);
                }
            }
        } else {
            $ret = DataReturn($result['msg'], -10);
        }
        return ApiService::ApiDataReturn($ret);
    }

    /**
     * 微信小程序获取用户信息
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-11-06
     * @desc    description
     */
    public function WechatUserInfo()
    {
        // 参数校验
        $p = [
            [
                'checked_type'      => 'empty',
                'key_name'          => 'openid',
                'error_msg'         => 'openid为空',
            ],
            [
                'checked_type'      => 'empty',
                'key_name'          => 'auth_data',
                'error_msg'         => '授权数据为空',
            ],
        ];
        $ret = ParamsChecked($this->data_post, $p);
        if($ret === true)
        {
            // 先从数据库获取用户信息
            $user = UserService::AppUserInfoHandle(null, 'weixin_openid', $this->data_post['openid']);
            if(empty($user))
            {
                // 字段名称不一样参数处理
                $auth_data = is_array($this->data_post['auth_data']) ? $this->data_post['auth_data'] : json_decode(htmlspecialchars_decode($this->data_post['auth_data']), true);
                $auth_data['nickname'] = isset($auth_data['nickName']) ? $auth_data['nickName'] : '';
                $auth_data['avatar'] = isset($auth_data['avatarUrl']) ? $auth_data['avatarUrl'] : '';
                $auth_data['gender'] = empty($auth_data['gender']) ? 0 : (($auth_data['gender'] == 2) ? 1 : 2);

                // 公共参数处理
                $auth_data['weixin_unionid'] = isset($this->data_post['unionid']) ? $this->data_post['unionid'] : '';
                $auth_data['openid'] = $this->data_post['openid'];
                $auth_data['referrer']= isset($this->data_post['referrer']) ? $this->data_post['referrer'] : 0;
                $ret = UserService::AuthUserProgram($auth_data, 'weixin_openid');
            } else {
                // 用户状态
                $ret = UserService::UserStatusCheck('id', $user['id']);
                if($ret['code'] == 0)
                {
                    $ret = DataReturn('授权成功', 0, $user);
                }
            }   
        } else {
            $ret = DataReturn($ret, -1);
        }
        return ApiService::ApiDataReturn($ret);
    }

    /**
     * 百度小程序获取用户信息
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-11-06
     * @desc    description
     */
    public function BaiduUserAuth()
    {
        $config = [
            'appid'     => MyC('common_app_mini_baidu_appid'),
            'key'       => MyC('common_app_mini_baidu_appkey'),
            'secret'    => MyC('common_app_mini_baidu_appsecret'),
        ];
        $result = (new \base\Baidu($config))->GetAuthSessionKey($this->data_post);
        if($result['status'] == 0)
        {
            // 先从数据库获取用户信息
G
gongfuxiang 已提交
384
            $user = UserService::AppUserInfoHandle(null, 'baidu_openid', $result['data']['openid']);
G
gongfuxiang 已提交
385 386 387 388 389 390 391 392 393 394 395
            if(!empty($user))
            {
                // 用户状态
                $ret = UserService::UserStatusCheck('id', $user['id']);
                if($ret['code'] == 0)
                {
                    // 标记用户存在
                    $user['is_user_exist'] = 1;
                    $ret = DataReturn('授权登录成功', 0, $user);
                }
            } else {
G
gongfuxiang 已提交
396
                $ret = DataReturn('授权登录成功', 0, ['is_user_exist'=>0, 'openid'=>$result['data']['openid']]);
G
gongfuxiang 已提交
397 398 399 400 401 402 403 404 405 406 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
            }
        } else {
            $ret = DataReturn($result['msg'], -10);
        }
        return ApiService::ApiDataReturn($ret);
    }

    /**
     * 百度小程序获取用户信息
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-11-06
     * @desc    description
     */
    public function BaiduUserInfo()
    {
        // 参数校验
        $p = [
            [
                'checked_type'      => 'empty',
                'key_name'          => 'openid',
                'error_msg'         => 'openid为空',
            ],
            [
                'checked_type'      => 'empty',
                'key_name'          => 'encrypted_data',
                'error_msg'         => '解密数据为空',
            ],
            [
                'checked_type'      => 'empty',
                'key_name'          => 'iv',
                'error_msg'         => 'iv为空,请重试',
            ]
        ];
        $ret = ParamsChecked($this->data_post, $p);
        if($ret === true)
        {
            // 先从数据库获取用户信息
            $user = UserService::AppUserInfoHandle(null, 'baidu_openid', $this->data_post['openid']);
            if(empty($user))
            {
                $config = [
                    'appid'     => MyC('common_app_mini_baidu_appid'),
                    'key'       => MyC('common_app_mini_baidu_appkey'),
                    'secret'    => MyC('common_app_mini_baidu_appsecret'),
                ];
                $result = (new \base\Baidu($config))->DecryptData($this->data_post['encrypted_data'], $this->data_post['iv'], $this->data_post['openid']);

                if($result['status'] == 0 && !empty($result['data']))
                {
                    $result['nickname'] = isset($result['data']['nickname']) ? $result['data']['nickname'] : '';
                    $result['avatar'] = isset($result['data']['headimgurl']) ? $result['data']['headimgurl'] : '';
                    $result['gender'] = empty($result['data']['sex']) ? 0 : (($result['data']['sex'] == 2) ? 1 : 2);
                    $result['openid'] = $result['data']['openid'];
                    $result['referrer']= isset($this->data_post['referrer']) ? $this->data_post['referrer'] : 0;
                    $ret = UserService::AuthUserProgram($result, 'baidu_openid');
                } else {
                    $ret = DataReturn($result['msg'], -1);
                }
            } else {
                // 用户状态
                $ret = UserService::UserStatusCheck('id', $user['id']);
                if($ret['code'] == 0)
                {
                    $ret = DataReturn('授权成功', 0, $user);
                }
            }
        } else {
            $ret = DataReturn($ret, -1);
        }
        return ApiService::ApiDataReturn($ret);
    }

    /**
     * 头条小程序用户授权
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2019-10-27
     * @desc    description
     */
    public function ToutiaoUserAuth()
    {
        $config = [
            'appid'     => MyC('common_app_mini_toutiao_appid'),
            'secret'    => MyC('common_app_mini_toutiao_appsecret'),
        ];
        $result = (new \base\Toutiao($config))->GetAuthSessionKey($this->data_post);
        if($result['status'] == 0)
        {
            // 先从数据库获取用户信息
G
gongfuxiang 已提交
489
            $user = UserService::AppUserInfoHandle(null, 'toutiao_openid', $result['data']['openid']);
G
gongfuxiang 已提交
490 491
            if(empty($user))
            {
G
gongfuxiang 已提交
492
                $ret = DataReturn('授权登录成功', 0, ['is_user_exist'=>0, 'openid'=>$result['data']['openid']]);
G
gongfuxiang 已提交
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 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
            } else {
                // 用户状态
                $ret = UserService::UserStatusCheck('id', $user['id']);
                if($ret['code'] == 0)
                {
                    // 标记用户存在
                    $user['is_user_exist'] = 1;
                    $ret = DataReturn('授权登录成功', 0, $user);
                }
            }
        } else {
            $ret = DataReturn($result['msg'], -10);
        }
        return ApiService::ApiDataReturn($ret);
    }

    /**
     * 头条小程序获取用户信息
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2019-10-27
     * @desc    description
     */
    public function ToutiaoUserInfo()
    {
        // 参数校验
        $p = [
            [
                'checked_type'      => 'empty',
                'key_name'          => 'openid',
                'error_msg'         => 'openid为空',
            ],
            [
                'checked_type'      => 'empty',
                'key_name'          => 'userinfo',
                'error_msg'         => '用户信息为空',
            ],
        ];
        $ret = ParamsChecked($this->data_post, $p);
        if($ret === true)
        {
            // 先从数据库获取用户信息
            $user = UserService::AppUserInfoHandle(null, 'toutiao_openid', $this->data_post['openid']);
            if(empty($user))
            {
                $result = json_decode(htmlspecialchars_decode($this->data_post['userinfo']), true);
                if(is_array($result))
                {
                    $result['nickname'] = isset($result['nickName']) ? $result['nickName'] : '';
                    $result['avatar'] = isset($result['avatarUrl']) ? $result['avatarUrl'] : '';
                    $result['gender'] = empty($result['gender']) ? 0 : (($result['gender'] == 2) ? 1 : 2);
                    $result['openid'] = $this->data_post['openid'];
                    $result['referrer']= isset($this->data_post['referrer']) ? $this->data_post['referrer'] : 0;
                    $ret = UserService::AuthUserProgram($result, 'toutiao_openid');
                } else {
                    $ret = DataReturn(empty($result) ? '获取用户信息失败' : $result, -1);
                }
            } else {
                // 用户状态
                $ret = UserService::UserStatusCheck('id', $user['id']);
                if($ret['code'] == 0)
                {
                    $ret = DataReturn('授权成功', 0, $user);
                }
            }
        } else {
            $ret = DataReturn($ret, -1);
        }
        return ApiService::ApiDataReturn($ret);
    }

    /**
     * QQ小程序获取用户授权
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2019-10-31
     * @desc    description
     */
    public function QQUserAuth()
    {
        // 参数
        if(!empty($this->data_post['authcode']))
        {
            // 授权
            $result = (new \base\QQ(MyC('common_app_mini_qq_appid'), MyC('common_app_mini_qq_appsecret')))->GetAuthSessionKey($this->data_post['authcode']);
G
gongfuxiang 已提交
580
            if($result['status'] == 0)
G
gongfuxiang 已提交
581 582
            {
                // 先从数据库获取用户信息
G
gongfuxiang 已提交
583
                $user = UserService::AppUserInfoHandle(null, 'qq_openid', $result['data']['openid']);
G
gongfuxiang 已提交
584 585
                if(empty($user))
                {
G
gongfuxiang 已提交
586
                    $ret = DataReturn('授权登录成功', 0, ['is_user_exist'=>0, 'openid'=>$result['data']['openid']]);
G
gongfuxiang 已提交
587 588 589 590 591 592 593 594 595 596 597
                } else {
                    // 用户状态
                    $ret = UserService::UserStatusCheck('id', $user['id']);
                    if($ret['code'] == 0)
                    {
                        // 标记用户存在
                        $user['is_user_exist'] = 1;
                        $ret = DataReturn('授权登录成功', 0, $user);
                    }
                }
            } else {
G
gongfuxiang 已提交
598
                $ret = DataReturn($result['msg'], -10);
G
gongfuxiang 已提交
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669
            }
        } else {
            $ret = DataReturn('授权码为空', -1);
        }
        return ApiService::ApiDataReturn($ret);
    }

    /**
     * QQ小程序获取用户信息
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2019-10-31
     * @desc    description
     */
    public function QQUserInfo()
    {
        // 参数校验
        $p = [
            [
                'checked_type'      => 'empty',
                'key_name'          => 'openid',
                'error_msg'         => 'openid为空',
            ],
            [
                'checked_type'      => 'empty',
                'key_name'          => 'encrypted_data',
                'error_msg'         => '解密数据为空',
            ],
            [
                'checked_type'      => 'empty',
                'key_name'          => 'iv',
                'error_msg'         => 'iv为空,请重试',
            ]
        ];
        $ret = ParamsChecked($this->data_post, $p);
        if($ret === true)
        {
            // 先从数据库获取用户信息
            $user = UserService::AppUserInfoHandle(null, 'qq_openid', $this->data_post['openid']);
            if(empty($user))
            {
                $result = (new \base\QQ(MyC('common_app_mini_qq_appid'), MyC('common_app_mini_qq_appsecret')))->DecryptData($this->data_post['encrypted_data'], $this->data_post['iv'], $this->data_post['openid']);
                if(is_array($result))
                {
                    $result['nickname'] = isset($result['nickName']) ? $result['nickName'] : '';
                    $result['avatar'] = isset($result['avatarUrl']) ? $result['avatarUrl'] : '';
                    $result['gender'] = empty($result['gender']) ? 0 : (($result['gender'] == 2) ? 1 : 2);
                    $result['qq_unionid'] = isset($result['unionId']) ? $result['unionId'] : '';
                    $result['openid'] = $result['openId'];
                    $result['referrer']= isset($this->data_post['referrer']) ? $this->data_post['referrer'] : 0;
                    $ret = UserService::AuthUserProgram($result, 'qq_openid');
                } else {
                    $ret = DataReturn(empty($result) ? '获取用户信息失败' : $result, -1);
                }
            } else {
                // 用户状态
                $ret = UserService::UserStatusCheck('id', $user['id']);
                if($ret['code'] == 0)
                {
                    $ret = DataReturn('授权成功', 0, $user);
                }
            }   
        } else {
            $ret = DataReturn($ret, -1);
        }
        return ApiService::ApiDataReturn($ret);
    }

    

670
    /**
G
gongfuxiang 已提交
671
     * 小程序用户授权
672 673 674
     * @author  Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
G
gongfuxiang 已提交
675
     * @date    2021-11-15
D
v1.2.0  
devil_gong 已提交
676 677
     * @desc    description
     */
G
gongfuxiang 已提交
678
    public function AppMiniUserAuth()
D
v1.2.0  
devil_gong 已提交
679
    {
G
gongfuxiang 已提交
680 681 682
        $module = '\app\service\AppMiniUserService';
        $action = ucfirst(APPLICATION_CLIENT_TYPE).'UserAuth';
        if(method_exists($module, $action))
D
v1.2.0  
devil_gong 已提交
683
        {
G
gongfuxiang 已提交
684
            $ret = AppMiniUserService::$action($this->data_post);
D
Devil 已提交
685
        } else {
G
gongfuxiang 已提交
686
            $ret = DataReturn('方法未定义['.$action.']', -1);
D
v1.2.0  
devil_gong 已提交
687
        }
D
Devil 已提交
688
        return ApiService::ApiDataReturn($ret);
D
v1.2.0  
devil_gong 已提交
689 690
    }

D
devil_gong 已提交
691
    /**
G
gongfuxiang 已提交
692 693
     * 小程序用户信息
     * @author  Devil
D
devil_gong 已提交
694 695
     * @blog    http://gong.gg/
     * @version 1.0.0
G
gongfuxiang 已提交
696
     * @date    2021-11-15
D
devil_gong 已提交
697 698
     * @desc    description
     */
G
gongfuxiang 已提交
699
    public function AppMiniUserInfo()
D
devil_gong 已提交
700
    {
G
gongfuxiang 已提交
701 702 703
        $module = '\app\service\AppMiniUserService';
        $action = ucfirst(APPLICATION_CLIENT_TYPE).'UserInfo';
        if(method_exists($module, $action))
D
devil_gong 已提交
704
        {
G
gongfuxiang 已提交
705
            $ret = AppMiniUserService::$action($this->data_post);
D
devil_gong 已提交
706
        } else {
G
gongfuxiang 已提交
707
            $ret = DataReturn('方法未定义['.$action.']', -1);
D
devil_gong 已提交
708
        }
D
Devil 已提交
709
        return ApiService::ApiDataReturn($ret);
D
devil_gong 已提交
710 711
    }

D
v1.2.0  
devil_gong 已提交
712 713 714 715 716 717 718 719 720 721
    /**
     * [ClientCenter 用户中心]
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  1.0.0
     * @datetime 2018-05-21T15:21:52+0800
     */
    public function Center()
    {
        // 登录校验
G
gongfuxiang 已提交
722
        $this->IsLogin();
D
v1.2.0  
devil_gong 已提交
723 724

        // 订单总数
D
devil_gong 已提交
725
        $where = ['user_id'=>$this->user['id'], 'is_delete_time'=>0, 'user_is_delete_time'=>0];
D
v1.2.0  
devil_gong 已提交
726 727 728 729
        $user_order_count = OrderService::OrderTotal($where);

        // 商品收藏总数
        $where = ['user_id'=>$this->user['id']];
D
devil 已提交
730
        $user_goods_favor_count = GoodsFavorService::GoodsFavorTotal($where);
D
v1.2.0  
devil_gong 已提交
731 732 733

        // 商品浏览总数
        $where = ['user_id'=>$this->user['id']];
D
devil 已提交
734
        $user_goods_browse_count = GoodsBrowseService::GoodsBrowseTotal($where);
D
v1.2.0  
devil_gong 已提交
735 736

        // 未读消息总数
D
devil_gong 已提交
737
        $params = ['user'=>$this->user, 'is_more'=>1, 'is_read'=>0];
D
v1.2.0  
devil_gong 已提交
738 739 740
        $common_message_total = MessageService::UserMessageTotal($params);

        // 用户订单状态
D
Devil 已提交
741
        $user_order_status = OrderService::OrderStatusStepTotal(['user_type'=>'user', 'user'=>$this->user, 'is_comments'=>1, 'is_aftersale'=>1]);
D
v1.2.0  
devil_gong 已提交
742

D
devil 已提交
743
        // 用户积分
D
Devil 已提交
744 745
        $integral = IntegralService::UserIntegral($params['user']['id']);
        $user_integral = (!empty($integral) && !empty($integral['integral'])) ? $integral['integral'] : 0;
D
devil 已提交
746

D
v1.2.0  
devil_gong 已提交
747 748
        // 初始化数据
        $result = array(
D
devil 已提交
749
            'integral'                          => $user_integral,
D
v1.2.0  
devil_gong 已提交
750 751 752
            'avatar'                            => $this->user['avatar'],
            'nickname'                          => $this->user['nickname'],
            'username'                          => $this->user['username'],
D
Devil 已提交
753
            'user_name_view'                    => $this->user['user_name_view'],
D
v1.2.0  
devil_gong 已提交
754 755 756 757 758
            'user_order_status'                 => $user_order_status['data'],
            'user_order_count'                  => $user_order_count,
            'user_goods_favor_count'            => $user_goods_favor_count,
            'user_goods_browse_count'           => $user_goods_browse_count,
            'common_message_total'              => $common_message_total,
D
devil_gong 已提交
759
            'navigation'                        => AppCenterNavService::AppCenterNav(),
D
devil 已提交
760
            'common_cart_total'                 => BuyService::UserCartTotal(['user'=>$this->user]),
D
v1.2.0  
devil_gong 已提交
761 762 763
        );

        // 返回数据
D
Devil 已提交
764
        return ApiService::ApiDataReturn(SystemBaseService::DataReturn($result));
D
v1.2.0  
devil_gong 已提交
765
    }
766 767

    /**
D
devil 已提交
768
     * 小程序用户手机一键绑定
769 770 771 772 773 774
     * @author  Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2020-09-20
     * @desc    description
     */
D
devil 已提交
775
    public function OnekeyUserMobileBind()
776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795
    {
        // 参数校验
        $p = [
            [
                'checked_type'      => 'empty',
                'key_name'          => 'openid',
                'error_msg'         => 'openid为空',
            ],
            [
                'checked_type'      => 'empty',
                'key_name'          => 'encrypted_data',
                'error_msg'         => '解密数据为空',
            ],
            [
                'checked_type'      => 'empty',
                'key_name'          => 'iv',
                'error_msg'         => 'iv为空,请重试',
            ]
        ];
        $ret = ParamsChecked($this->data_post, $p);
D
Devil 已提交
796
        if($ret === true)
797
        {
D
Devil 已提交
798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828
            // 根据不同平台处理数据解密逻辑
            $mobile = '';
            $error_msg = '';
            switch(APPLICATION_CLIENT_TYPE)
            {
                // 微信
                case 'weixin' :
                    $result = (new \base\Wechat(MyC('common_app_mini_weixin_appid'), MyC('common_app_mini_weixin_appsecret')))->DecryptData($this->data_post['encrypted_data'], $this->data_post['iv'], $this->data_post['openid']);
                    if($result['status'] == 0 && !empty($result['data']) && !empty($result['data']['purePhoneNumber']))
                    {
                        $mobile = $result['data']['purePhoneNumber'];
                    } else {
                        $error_msg = $result['msg'];
                    }
                    break;

                // 百度
                case 'baidu' :
                    $config = [
                        'appid'     => MyC('common_app_mini_baidu_appid'),
                        'key'       => MyC('common_app_mini_baidu_appkey'),
                        'secret'    => MyC('common_app_mini_baidu_appsecret'),
                    ];
                    $result = (new \base\Baidu($config))->DecryptData($this->data_post['encrypted_data'], $this->data_post['iv'], $this->data_post['openid'], 'mobile_bind');
                    if($result['status'] == 0 && !empty($result['data']) && !empty($result['data']['mobile']))
                    {
                        $mobile = $result['data']['mobile'];
                    } else {
                        $error_msg = $result['msg'];
                    }
                    break;
D
devil 已提交
829

D
Devil 已提交
830 831 832 833 834 835 836 837 838 839 840 841 842 843 844
                // 默认
                default :
                    $error_msg = APPLICATION_CLIENT_TYPE.'平台还未开发手机一键登录';
            }
            if(empty($mobile) || !empty($error_msg))
            {
                $ret = DataReturn(empty($error_msg) ? '数据解密失败' : $error_msg, -1);
            } else {
                // 用户信息处理
                $this->data_post['mobile'] = $mobile;
                $this->data_post['is_onekey_mobile_bind'] = 1;
                $ret = UserService::AuthUserProgram($this->data_post, APPLICATION_CLIENT_TYPE.'_openid');
            }
        } else {
            $ret = DataReturn($ret, -1);
845
        }
D
Devil 已提交
846
        return ApiService::ApiDataReturn($ret);
847
    }
D
v1.2.0  
devil_gong 已提交
848 849
}
?>