瀏覽代碼

微信注册用户

lizhen_gitee 1 年之前
父節點
當前提交
83c55fca8b
共有 1 個文件被更改,包括 18 次插入5 次删除
  1. 18 5
      application/api/controller/User.php

+ 18 - 5
application/api/controller/User.php

@@ -627,7 +627,6 @@ class User extends Api
      */
     public function bindmobile()
     {
-        Db::startTrans();
         try {
             $code = $this->request->param('code');
             $mobile = $this->request->param('mobile');
@@ -643,13 +642,29 @@ class User extends Api
             if (!$result) {
                 throw new Exception(__('Captcha is incorrect'));
             }
-            $where['mobile'] = $mobile;
-            $userData = model('User')->where($where)->find();//老用户
+
             $wechatCodeWhere['code'] = $code;
             $wechatCode = Db::name('wechat_code')->where($wechatCodeWhere)->find();
             if (empty($wechatCode)) {
                 throw new Exception('请先微信登录');
             }
+
+            //检查appid绑定的用户
+            $user = Db::name('user')->where('openid',$wechatCode['openid'])->find();
+            if ($user) {
+                if ($user['status'] == -1) {
+                    $this->error('账户已注销');
+                }
+                if ($user['status'] != 1) {
+                    $this->error(__('Account is locked'));
+                }
+                //如果已经有账号则直接登录
+                $ret = $this->auth->direct($user['id']);
+                $this->success('success',$this->userInfo('return'));
+            }
+
+            $where['mobile'] = $mobile;
+            $userData = model('User')->where($where)->find();//老用户
             if (!empty($userData)) {
                 if (empty($userData['openid'])) {
                     model('User')->update(['openid' => $wechatCode['openid']],$where);//老用户更新openid
@@ -670,10 +685,8 @@ class User extends Api
             }
 
             Sms::flush($mobile, 'changemobile');
-            Db::commit();
             $this->success('success',$this->userInfo('return'));
         } catch (Exception $e) {
-            Db::rollback();
             $this->error($e->getMessage());
         }
     }