From 94184b89a84a3db013d903b7d3ed279dba996df2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=8D=8E=E6=B8=85?= <18691022700@163.com> Date: Fri, 19 Dec 2025 11:41:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=89=8B=E6=9C=BA=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/api/controller/UserData.php | 52 +++++++++++++++++++++++-- application/api/model/UserData.php | 11 ++++-- 2 files changed, 57 insertions(+), 6 deletions(-) diff --git a/application/api/controller/UserData.php b/application/api/controller/UserData.php index cf3ea1ba..6d96fc3c 100644 --- a/application/api/controller/UserData.php +++ b/application/api/controller/UserData.php @@ -80,8 +80,10 @@ class UserData extends BaseCom { $key_name = "api:user:bind_mobile:" . $this->uid; redis_lock_exit($key_name); + $mobile = input('new_mobile'); $sms_code = input('sms_code', ''); + //default-默认登录,1-更换手机号,2绑定手机号,3-忘记密码,4-设置密码,5-账号注销,6-提现 $reslut = model('sms')->verification_code(2,$mobile, $sms_code); if ($reslut['code'] == 0) { @@ -93,6 +95,8 @@ class UserData extends BaseCom return V($reslut['code'], $reslut['msg'], $reslut['data']); } + //更换手机号 + //default-默认登录,1-更换手机号,2绑定手机号,3-忘记密码,4-设置密码,5-账号注销,6-提现 //更换手机号 public function modify_mobile() { @@ -102,10 +106,13 @@ class UserData extends BaseCom $new_mobile = input('new_mobile'); $sms_code = input('sms_code', ''); $user_mobile = db::name('user')->where('id',$this->uid)->value('mobile'); - if ($user_mobile != $mobile){ - redis_unlock($key_name); - return V(0, "旧手机号错误", null); + if($user_mobile){ + if ($user_mobile != $mobile){ + redis_unlock($key_name); +// return V(0, "旧手机号错误", null); + } } + if ($new_mobile == $user_mobile){ redis_unlock($key_name); return V(0, "新手机号不能与旧手机号一致", null); @@ -121,6 +128,45 @@ class UserData extends BaseCom return V($reslut['code'], $reslut['msg'], $reslut['data']); } + + //更换手机号 + //default-默认登录,1-更换手机号,2绑定手机号,3-忘记密码,4-设置密码,5-账号注销,6-提现 + public function modify_mobiles() + { + $key_name = "api:user:modify_mobile:" . $this->uid; + redis_lock_exit($key_name); + + $mobile = input('mobile'); + $sms_code = input('sms_code', ''); + $user_mobile = db::name('user')->where('id',$this->uid)->value('mobile'); + if ($user_mobile != $mobile){ + redis_unlock($key_name); + return V(0, "旧手机号错误", null); + } + //验证原有手机号 + $reslut = model('sms')->verification_code(1,$mobile, $sms_code); + if ($reslut['code'] == 0) { + redis_unlock($key_name); + return v($reslut['code'], $reslut['msg'], $reslut['data']); + } + $new_mobile = input('new_mobile'); + $new_sms_code = input('new_sms_code', ''); + if ($new_mobile == $user_mobile){ + redis_unlock($key_name); + return V(0, "新手机号不能与旧手机号一致", null); + } + //验证新手机号 + $reslut1 = model('sms')->verification_code(1,$new_mobile, $new_sms_code); + if ($reslut1['code'] == 0) { + redis_unlock($key_name); + return v($reslut1['code'], $reslut1['msg'], $reslut1['data']); + } + + $reslut2 = model('UserData')->modify_mobile($new_mobile,$this->uid); + redis_unlock($key_name); + return V($reslut2['code'], $reslut2['msg'], $reslut2['data']); + } + //实名认证 public function real_name() { diff --git a/application/api/model/UserData.php b/application/api/model/UserData.php index cd05bc9a..54c24c50 100644 --- a/application/api/model/UserData.php +++ b/application/api/model/UserData.php @@ -277,9 +277,14 @@ class UserData extends Model return ['code' => 0, 'msg' => '该手机号已达绑定上限','data' =>null]; } //查询旧手机号 - $mobile = db::name('user')->where(['id' => $user_id])->value('username'); - //查询是否实名 - $is_real = db::name('user_auth')->where(['mobile' => $mobile,'is_real' => 1])->find(); + $mobile = db::name('user')->where(['id' => $user_id])->value('mobile'); + if($mobile){ + //查询是否实名 + $is_real = db::name('user_auth')->where(['mobile' => $mobile,'is_real' => 1])->find(); + }else{ + $is_real = false; + } + if($is_real){ //开启事务 db::startTrans();