Browse Source

修改用户资料

lizhen_gitee 1 year ago
parent
commit
d029fff360
1 changed files with 9 additions and 8 deletions
  1. 9 8
      application/api/controller/User.php

+ 9 - 8
application/api/controller/User.php

@@ -50,25 +50,26 @@ class User extends Api
         $introcode = $this->request->post('introcode','');
         $avatar = $this->request->post('avatar', '', 'trim,strip_tags,htmlspecialchars');
 
+        $data = [
+            'nickname'  => $nickname,
+            'avatar'    => $avatar,
+        ];
+
         if ($mobile) {
             $exists = \app\common\model\User::where('mobile', $mobile)->where('id', '<>', $this->auth->id)->find();
             if ($exists) {
                 $this->error('手机号已经被他人注册');
             }
+            $data['mobile'] = $mobile;
         }
         if ($introcode) {
-            $exists = \app\common\model\User::where('introcode', $introcode)->find();
-            if (!$exists) {
+            $intro_uid = \app\common\model\User::where('introcode', $introcode)->value('id');
+            if (!$intro_uid) {
                 $this->error('不存在的邀请码');
             }
+            $data['intro_uid'] = $intro_uid;
         }
 
-        $data = [
-            'nickname'  => $nickname,
-            'mobile'    => $mobile,
-            'introcode' => $introcode,
-            'avatar'    => $avatar,
-        ];
 
         Db::name('user')->where('id',$this->auth->id)->update($data);