Browse Source

feat:版本

super-yimizi 2 months ago
parent
commit
07a4a6c20e

+ 13 - 11
application/api/controller/User.php

@@ -86,18 +86,21 @@ class User extends Base
     {
         $user = $this->auth->getUser();
         $params = $this->request->param();
+        // 字段不传就报错 所以默认给值
+        $username = $params['username'] ?? '';
+        $avatar   = $params['avatar'] ?? '';
+        $nickname = $params['nickname'] ?? '';
+        $bio      = $params['bio'] ?? '';
+        $age = $params['age'] ?? '';
+        $gender = $params['gender'] ?? '';
         // 验证器
+        //  替换有域名的头像
+        $avatar = str_replace(cdnurl('', true), '', $avatar);
+        $params['avatar'] = $avatar;
         $validate = new \app\api\validate\User();
         if (!$validate->check($params, [], 'profile')) {
             $this->error($validate->getError());
         }
-        $username = $params['username'] ?? '';
-        // $avatar   = $params['avatar'];
-        $nickname = $params['nickname'];
-        $bio      = $params['bio'] ??'';
-        $age = $params['age'];
-        $gender = $params['gender'];
-       // $avatar = str_replace(cdnurl('', true), '', $avatar);
         // username 不传,则不修改
         if ($username) {
             $user->username = $username;
@@ -106,11 +109,10 @@ class User extends Base
                 $this->error(__('Username already exists'));
             }
         }
-        if ($bio) {
-            $user->bio = $bio;
-        }
+        $user->bio = $bio;        
         $user->nickname = $nickname;
-        // $user->avatar = $avatar;
+        $user->username = $username;
+        $user->avatar = $avatar;
         $user->age = $age;
         $user->gender = $gender;
         $user->save();

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

@@ -27,8 +27,8 @@ class User extends Validate
         // 验证头像  验证文件后缀
 
         'avatar'    => [
-            // 'require',
-            'regex'=>'/^\/uploads\/.+\\.(?:jpg|jpeg|png|gif|bmp|webp)$/i'
+            'require',
+            'regex'=>'/\\.(jpg|jpeg|png|gif|bmp|webp)$/i'
         ],
 
         // 'gender'    => 'require|in:' .implode(',', UserEnum::getGenderList()),
@@ -56,7 +56,7 @@ class User extends Validate
         'mobile.regex'      => '手机号格式不正确',
         'mobile.require'    => '手机号不能为空',
         'email'             => '邮箱格式不正确',
-        // 'avatar.require'    => '头像不能为空',
+        'avatar.require'    => '头像不能为空',
         'avatar.regex'      => '头像格式不正确',
         'gender.in'         => '性别只能是未知、男、女',
         'gender.require'    => '性别不能为空',

+ 1 - 1
application/common/model/Address.php

@@ -37,7 +37,7 @@ class Address extends Model
                     $info->save();
                 }
             }
-            $row['address'] = $row->address_full;
+            //$row['address'] = $row->address_full;
         });
     }