Browse Source

修改用户资料,申请真人认证,获取用户信息

lizhen_gitee 3 years ago
parent
commit
f713e7de0f
3 changed files with 54 additions and 15 deletions
  1. 33 14
      application/api/controller/User.php
  2. 7 1
      application/common/library/Auth.php
  3. 14 0
      thinkphp/helper.php

+ 33 - 14
application/api/controller/User.php

@@ -150,6 +150,12 @@ class User extends Api
         $this->success(__('success'),$info);
     }
 
+    //申请真人认证
+    public function apply_real_confirm(){
+        Db::name('user')->where('id',$this->auth->id)->update(['real_status'=>1]);
+        $this->success();
+    }
+
     //实名认证信息
     public function idcard_confirm_info(){
         $check = Db::name('user_idconfirm')->where('user_id',$this->auth->id)->order('id desc')->find();
@@ -157,7 +163,7 @@ class User extends Api
     }
 
     //申请实名认证
-    public function idcard_confirm(){
+    public function apply_idcard_confirm(){
         $truename = input('truename','');
         $idcard = input('idcard','');
         $idcard_images = input('idcard_images','');
@@ -241,24 +247,37 @@ class User extends Api
      */
     public function profile()
     {
-        $user = $this->auth->getUser();
+        $field_array = ['nickname','gender','birthday','height','weight','bio','audio_bio','avatar','photo_images','education_id','hobby_ids','job_id','marital_id','tag_ids','wages_id'];
 
-        $nickname = $this->request->post('nickname');
-        $gender = $this->request->post('gender');
-        $birthday = $this->request->post('birthday');
-        $height = $this->request->post('height');
-        $weight = $this->request->post('weight');
+        $data = [];
+        foreach($field_array as $key => $field){
 
+            $newone = input_post($field);
 
-        $bio = $this->request->post('bio');
-        $audio_bio = $this->request->post('audio_bio');
-        $avatar = $this->request->post('avatar', '', 'trim,strip_tags,htmlspecialchars');
-        $avatar = $this->request->post('photo_images', '', 'trim,strip_tags,htmlspecialchars');
+            if($field == 'avatar'){
+                $newone = input_post('avatar', '', 'trim,strip_tags,htmlspecialchars');
+            }
+            if($field == 'photo_images'){
+                $newone = input_post('avatar', '', 'trim,strip_tags,htmlspecialchars');
+            }
 
+            if(!empty($newone)){
+                $data[$field] = $newone;
+            }
+        }
 
-        $user->bio = $bio;
-        $user->avatar = $avatar;
-        $user->save();
+        if(isset($data['birthday'])){
+            $data['birthday'] = strtotime($data['birthday']);
+        }
+        if(isset($data['avatar'])){
+            $data['real_status'] = -1;  //或许应该改成0
+        }
+        //dump($data);
+        if(empty($data)){
+            $this->error('没有任何改变');
+        }
+
+        Db::name('user')->where('id',$this->auth->id)->update($data);
         $this->success();
     }
 

+ 7 - 1
application/common/library/Auth.php

@@ -437,7 +437,13 @@ class Auth
         ];
 
         $userinfo = array_merge($userinfo,$new_data);
-        //
+        //枚举
+        $userinfo['education'] = Db::name('enum_education')->where('id',$this->education_id)->value('name');
+        $userinfo['hobby'] = Db::name('enum_hobby')->where('id','IN',$this->hobby_ids)->column(['id','name']);
+        $userinfo['job'] = Db::name('enum_job')->where('id',$this->job_id)->value('name');
+        $userinfo['marital'] = Db::name('enum_marital')->where('id',$this->marital_id)->value('name');
+        $userinfo['tag'] = Db::name('enum_tag')->where('id','IN',$this->tag_ids)->column(['id','name']);
+        $userinfo['wages'] = Db::name('enum_wages')->where('id',$this->wages_id)->value('name');
 
         return $userinfo;
     }

+ 14 - 0
thinkphp/helper.php

@@ -143,6 +143,20 @@ if (!function_exists('input')) {
     }
 }
 
+if (!function_exists('input_post')) {
+    /**
+     * 获取输入数据 支持默认值和过滤
+     * @param string    $key 获取的变量名
+     * @param mixed     $default 默认值
+     * @param string    $filter 过滤方法
+     * @return mixed
+     */
+    function input_post($key = '', $default = null, $filter = '')
+    {
+        return Request::instance()->post($key, $default, $filter);
+    }
+}
+
 if (!function_exists('widget')) {
     /**
      * 渲染输出Widget