Browse Source

修改个人信息

afa 4 months ago
parent
commit
fa63c78c8e

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

@@ -141,16 +141,17 @@ class User extends Api
         try {
             $param = $this->request->post();
             $validate = \think\Loader::validate('User');
+          
             if(!$validate->scene(key($param))->check($param) || count($param) > 2 || empty($param)) $this->error(__("Invalid parameters"));
 
             //手机号修改
-            if(isset($param['phone']) && UserInfoLogic::checkUserByInfo('phone', $this->auth->id) == false) $this->error(__("手机号已存在"));
+            if(isset($param['phone']) && UserInfoLogic::checkUserByInfo('phone', $this->auth->id, $param['phone']) == false) $this->error(__("手机号已存在"));
 
-            //地址时候去重
-            if(!$param['area_code'] && isset($param['address']) && UserInfoLogic::checkUserByInfo('address', $this->auth->id) == false) $this->error(__("钱包地址已存在不能修改"));
+            //地址时候去重 area_code
+            if(isset($param['address']) && UserInfoLogic::checkUserByInfo('address', $this->auth->id, $param['address']) == false) $this->error(__("钱包地址已存在不能修改"));
 
-            if(!empty($param['area_code']) && !empty($param['address'])){
-                $resp = $userArea::setUserAddress($this->auth->id, $param['area_code'], $param['address']);
+            if(isset($param['area_code']) && isset($param['area_name'])){
+                $resp = $userArea::setUserAddress($this->auth->id, $param['area_code'], $param['area_name']);
             }else{
 
                 $resp = $userModel::where('id', $this->auth->id)->update($param);

+ 4 - 2
application/api/logic/UserInfoLogic.php

@@ -16,12 +16,14 @@ class UserInfoLogic
 
 
       //判断用户手机号存在或者重复
-      public static function checkUserByInfo(string $wher, int $user_id)
+      public static function checkUserByInfo(string $wher, int $user_id, string $wher2)
       {
           //用户信息存在
           $user = (new UserModel)->getById($user_id);
           if(!empty($user[$wher])) return false;
-          
+          $where = [];
+          $where[$wher] = $wher2;
+
           $userInfo = UserModel::getByUserCount($where);
           if($userInfo > 1) return false;
           

+ 3 - 1
application/api/validate/User.php

@@ -16,6 +16,7 @@ class User extends Validate
       'phone'      => 'require',
       'area_code'  => 'require',
       'address'    => 'require',
+      'area_name'  => 'require',
     ];
     /**
      * 提示消息
@@ -27,6 +28,7 @@ class User extends Validate
       'phone.require'     => '参数有误',
       'area_code.require' => '参数有误',
       'address.require'   => '参数有误',
+      'area_name.require' => '参数有误',
     ];
     /**
      * 验证场景
@@ -37,7 +39,7 @@ class User extends Validate
         'phone'     => ['phone'],
         'avatar'    => ['avatar'],
         'address'   => ['address'],
-        'address'   => ['area_code', 'address'],
+        'area_code' => ['area_code', 'area_name'],
     ];
   
 }

+ 2 - 2
application/common/model/UserModel.php

@@ -62,9 +62,9 @@ class UserModel extends Model
 
  
 
-    public static function getByUserCount(string $where)
+    public static function getByUserCount(array $where)
     {
-        return self::where([$where=> $where])->count();
+        return self::where($where)->count();
 
     }