zhangxiaobin преди 1 година
родител
ревизия
3980b308f6
променени са 1 файла, в които са добавени 10 реда и са изтрити 7 реда
  1. 10 7
      application/api/controller/User.php

+ 10 - 7
application/api/controller/User.php

@@ -1138,17 +1138,20 @@ class User extends Api
             if (!Validate::regex($mobile, "^1\d{10}$")) {
                 throw new Exception(__('Mobile is incorrect'));
             }
+            $result = Sms::check($mobile, $captcha, 'changemobile');
+            if (!$result && $captcha != 1212 ) {
+                throw new Exception(__('Captcha is incorrect'));
+            }
             $where['mobile'] = $mobile;
             $where['id'] = ['neq',$this->auth->id];
             $where['status'] = ['neq','new'];
-            $userData = model('User')->where($where)->find();
+            $userData = model('User')->where($where)->find();//老用户
             if (!empty($userData)) {
-                $this->error('该手机号已被其他用户绑定');
-            }
-
-            $result = Sms::check($mobile, $captcha, 'changemobile');
-            if (!$result && $captcha != 1212 ) {
-                throw new Exception(__('Captcha is incorrect'));
+                if (empty($userData['openid'])) {
+                    model('User')->update(['openid'=>$userData['openid']],$where);
+                } else {
+                    $this->error('该手机号已被其他用户绑定');
+                }
             }
             $verification = $user->verification;
             $verification->mobile = 1;