ソースを参照

Merge branch 'master' of https://git.bjtdba.com/shop/php

hefei 1 年間 前
コミット
2cc3ca3255
共有4 個のファイルを変更した40 個の追加10 個の削除を含む
  1. 28 1
      app/common/repositories/user/UserRepository.php
  2. 2 2
      app/controller/api/Auth.php
  3. 9 6
      app/controller/api/user/User.php
  4. 1 1
      config/database.php

+ 28 - 1
app/common/repositories/user/UserRepository.php

@@ -3199,7 +3199,7 @@ class UserRepository extends BaseRepository
3199
     /*微信登录验证
3199
     /*微信登录验证
3200
      $openid 微信openid
3200
      $openid 微信openid
3201
     */
3201
     */
3202
-    public  function  wechatCheck($openid){
3202
+    public  function  wechatCheck($openid, $nickname = '', $headimgurl = ''){
3203
         $user = Db::name("user")->where(['wechat_user_id'=>$openid])->find();
3203
         $user = Db::name("user")->where(['wechat_user_id'=>$openid])->find();
3204
         //判断是否是第一次登录
3204
         //判断是否是第一次登录
3205
         if($user){
3205
         if($user){
@@ -3207,6 +3207,33 @@ class UserRepository extends BaseRepository
3207
             if (!$user['account']) {
3207
             if (!$user['account']) {
3208
                 return ['code' => 400, 'msg' => '请绑定手机号'];
3208
                 return ['code' => 400, 'msg' => '请绑定手机号'];
3209
             } else {
3209
             } else {
3210
+                $existUid = Db::name('user_extract_openid')->where('openid', $openid)->value('uid');
3211
+                if (!empty($existUid) && $existUid != $user['uid']) {
3212
+                    return ['code' => 400, 'msg' => '此微信号已被绑定'];
3213
+                }
3214
+                $check = Db::name('user_extract_openid')->where('uid', $user['uid'])->value('openid');
3215
+                if (!empty($check)) {
3216
+                    if ($check != $openid) {
3217
+                        return ['code' => 400, 'msg' => '当前用户已绑定其他微信号'];
3218
+                    }
3219
+                } else {
3220
+                    Db::name("user_extract_openid")->insert([
3221
+                        'uid' => $user['uid'],
3222
+                        'openid' => $openid,
3223
+                        'type' => 1
3224
+                    ]);
3225
+                }
3226
+                $this->updateUser(
3227
+                    $user['uid'],
3228
+                    ['wechat_user_id' => $openid],
3229
+                    [
3230
+                        "type" => 1,
3231
+                        "uid" => $user['uid'],
3232
+                        "nickname" => $nickname,
3233
+                        "avater" => $headimgurl,
3234
+                    ]
3235
+                );
3236
+
3210
                 return ['code' => 200, 'msg' => '登陆成功', 'user' => $user];
3237
                 return ['code' => 200, 'msg' => '登陆成功', 'user' => $user];
3211
             }
3238
             }
3212
         }else{
3239
         }else{

+ 2 - 2
app/controller/api/Auth.php

@@ -1629,7 +1629,7 @@ class Auth extends BaseController
1629
 
1629
 
1630
     /*微信授权登录*/
1630
     /*微信授权登录*/
1631
     public function wechatCheck(){
1631
     public function wechatCheck(){
1632
-        $data =  $this->request->params(['openid']);
1632
+        $data =  $this->request->params(['openid', 'nickname', 'avatar']);
1633
         if(!$data['openid'] || $data['openid'] == '' || $data['openid'] =='undefined'){
1633
         if(!$data['openid'] || $data['openid'] == '' || $data['openid'] =='undefined'){
1634
             return app('json')->fail("openid参数缺失");
1634
             return app('json')->fail("openid参数缺失");
1635
         }
1635
         }
@@ -1638,7 +1638,7 @@ class Auth extends BaseController
1638
         if($this->source=='yhc'){
1638
         if($this->source=='yhc'){
1639
             $result =  $repository ->wechatCheckYhc($data['openid']);
1639
             $result =  $repository ->wechatCheckYhc($data['openid']);
1640
         }else{
1640
         }else{
1641
-            $result =  $repository ->wechatCheck($data['openid']);
1641
+            $result =  $repository ->wechatCheck($data['openid'], $data['nickname'], $data['avatar']);
1642
         }
1642
         }
1643
         if(isset($result['code']) && $result['code'] == 200){
1643
         if(isset($result['code']) && $result['code'] == 200){
1644
             $user = $repository->accountByUser($result['user']['account']);
1644
             $user = $repository->accountByUser($result['user']['account']);

+ 9 - 6
app/controller/api/user/User.php

@@ -2656,12 +2656,15 @@ class User extends BaseController
2656
                 $existUid = Db::name('user_extract_openid')->where('openid',$unionId)->value('uid');
2656
                 $existUid = Db::name('user_extract_openid')->where('openid',$unionId)->value('uid');
2657
                 if (!empty($existUid) && $existUid != $uid) throw new \Exception("此微信号已被绑定");
2657
                 if (!empty($existUid) && $existUid != $uid) throw new \Exception("此微信号已被绑定");
2658
                 $check = Db::name('user_extract_openid')->where('uid',$uid)->value('openid');
2658
                 $check = Db::name('user_extract_openid')->where('uid',$uid)->value('openid');
2659
-                if (!empty($check) && $check != $unionId) throw new \Exception("当前用户已绑定其他微信号");
2660
-                Db::name("user_extract_openid")->insert([
2661
-                    'uid' => $uid,
2662
-                    'openid' => $unionId,
2663
-                    'type' => 1
2664
-                ]);
2659
+                if (!empty($check)){
2660
+                    if ($check != $unionId) throw new \Exception("当前用户已绑定其他微信号");
2661
+                } else {
2662
+                    Db::name("user_extract_openid")->insert([
2663
+                        'uid' => $uid,
2664
+                        'openid' => $unionId,
2665
+                        'type' => 1
2666
+                    ]);
2667
+                }
2665
             } else {
2668
             } else {
2666
                 $alinfo = json_decode($alinfo, true);
2669
                 $alinfo = json_decode($alinfo, true);
2667
                 if (!$alinfo) throw new \Exception("参数异常");
2670
                 if (!$alinfo) throw new \Exception("参数异常");

+ 1 - 1
config/database.php

@@ -33,7 +33,7 @@ return [
33
             // 数据库连接参数
33
             // 数据库连接参数
34
             'params'            => [],
34
             'params'            => [],
35
             // 数据库编码默认采用utf8
35
             // 数据库编码默认采用utf8
36
-            'charset'           => env('database.charset', 'utf8'),
36
+            'charset'           => env('database.charset', 'utf8mb4'),
37
             // 数据库表前缀
37
             // 数据库表前缀
38
             'prefix'            => env('database.prefix', ''),
38
             'prefix'            => env('database.prefix', ''),
39
 
39