lizhen_gitee 3 hónapja
szülő
commit
022b8e1c59
1 módosított fájl, 159 hozzáadás és 159 törlés
  1. 159 159
      application/api/controller/User.php

+ 159 - 159
application/api/controller/User.php

@@ -150,62 +150,119 @@ class User extends Api
         }
     }
 
-    /**
-     * 重置密码
-     *
-     * @ApiMethod (POST)
-     * @param string $mobile      手机号
-     * @param string $newpassword 新密码
-     * @param string $captcha     验证码
-     */
-    public function resetpwd()
-    {
-        //$type = input("type");
-        $type = 'email';
-        $mobile = input("mobile");
-        $email = input("email");
-        $newpassword = input("newpassword");
-        $captcha = input("captcha");
-        if (!$newpassword || !$captcha) {
-            $this->error(__('Invalid parameters'));
+    //注册设置性别
+    public function setgender() {
+        $user_id = $this->auth->id;
+
+        $gender = input('gender', -1, 'intval'); //性别:1=男,0=女
+        if (!in_array($gender, [1, 0])) {
+            $this->error('性别错误');
         }
-        if ($type == 'mobile') {
-            if (!Validate::regex($mobile, "^1\d{10}$")) {
-                $this->error(__('Mobile is incorrect'));
-            }
-            $user = \app\common\model\User::getByMobile($mobile);
-            if (!$user) {
-                $this->error(__('User not found'));
+
+        $edit_data['gender'] = $gender;
+        $edit_data['avatar'] = $gender == 1 ? config('avatar_boy') : config('avatar_girl'); //头像
+
+        $rs = Db::name('user')->where(['id' => $user_id, 'gender' => $this->auth->gender])->setField($edit_data);
+        if (!$rs) {
+            $this->error('您的网络开小差啦~');
+        }
+
+        //$data = $this->userInfo('return');
+        $data['gender'] = $edit_data['gender'];
+        $data['avatar'] = $edit_data['avatar'];
+
+        $this->success('success', $data);
+
+    }
+
+    //注册完善资料
+    public function perfect_info() {
+        $avatar = input('avatar', '', 'trim'); //头像
+        $nickname = input('nickname', '', 'trim'); //昵称
+        $birthday = input('birthday', '', 'strtotime'); //生日
+        $hometown_cityid = input('hometown_cityid', '', 'trim'); //城市id
+        $hobby = input('hobby', '', 'trim'); //爱好
+        $marital = input('marital', '', 'trim'); //婚姻
+        $introcode = input('introcode', '', 'trim'); //邀请码
+
+        $data = [];
+        if ($avatar) {
+            $data['avatar'] = $avatar;
+        }
+        if ($nickname !== '') {
+            if (iconv_strlen($nickname, 'utf-8') > 10) {
+                $this->error('昵称最多10个字~');
             }
-            $ret = Sms::check($mobile, $captcha, 'resetpwd');
-            if (!$ret) {
-                $this->error(__('Captcha is incorrect'));
+            $data['nickname'] = $nickname;
+        }
+        if ($birthday) {
+            $data['birthday'] = $birthday;
+        }
+        if ($hometown_cityid) {
+            $count = Db::name('area')->where('id', $hometown_cityid)->count('id');
+            if (!$count) {
+                $this->error('城市不存在');
             }
-            Sms::flush($mobile, 'resetpwd');
-        } else {
-            if (!Validate::is($email, "email")) {
-                $this->error(__('Email is incorrect'));
+            $data['hometown_cityid'] = $hometown_cityid;
+        }
+        if ($hobby) {
+            $data['hobby'] = $hobby;
+        }
+        if ($marital) {
+            $data['marital'] = $marital;
+        }
+        if ($introcode && !$this->auth->intro_uid) {
+
+
+            $intro_user = Db::name('user')->field('id, intro_uid')->where('introcode', $introcode)->find();
+            if ($intro_user && $intro_user['id'] != $this->auth->id && $intro_user['intro_uid'] != $this->auth->id) {
+                $data['intro_uid'] = $intro_user['id'];
+                $data['invite_time'] = time();
             }
-            $user = \app\common\model\User::getByEmail($email);
-            if (!$user) {
-                $this->error(__('User not found'));
+        }
+
+
+
+        //开启事务
+        Db::startTrans();
+        $update_rs = Db::name('user')->where('id',$this->auth->id)->setField($data);
+        if($update_rs === false){
+            Db::rollback();
+            $this->error('修改失败');
+        }
+
+        //给上级发放钻石
+        if(isset($data['intro_uid'])){
+            $intro_jewel = config('site.new_user_intro_jewel');
+            if($intro_jewel > 0){
+                $rs_wallet = model('wallet')->lockChangeAccountRemain($data['intro_uid'], 0,'jewel',$intro_jewel,34,'邀请'.$this->auth->username.'注册奖励');
+                if($rs_wallet['status'] === false){
+                    Db::rollback();
+                    $this->error('邀请新人奖励赠送失败');
+                }
             }
-            $ret = Ems::check($email, $captcha, 'resetpwd');
-            if (!$ret) {
-                $this->error(__('Captcha is incorrect'));
+        }
+
+        //上传头像加5金币
+        if(isset($data['avatar'])){
+            $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,19);
+            if($task_rs === false){
+                Db::rollback();
+                $this->error('完成任务赠送奖励失败');
             }
-            Ems::flush($email, 'resetpwd');
         }
-        //模拟一次登录
-        $this->auth->direct($user->id);
-        $ret = $this->auth->changepwd($newpassword, '', true);
-        if ($ret) {
-            $this->success(__('Reset password successful'));
-        } else {
-            $this->error($this->auth->getError());
+        if (isset($data['birthday'])) {
+            //完成设置生日  +5金币
+            $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,1);
+            if($task_rs === false){
+                Db::rollback();
+                $this->error('完成任务赠送奖励失败');
+            }
         }
-    }
 
+        Db::commit();
+        $this->success('修改成功');
+    }
 
     //用户详细资料
     public function userInfo($type = 1){
@@ -390,6 +447,61 @@ class User extends Api
     }
 
 
+    /**
+     * 重置密码
+     *
+     * @ApiMethod (POST)
+     * @param string $mobile      手机号
+     * @param string $newpassword 新密码
+     * @param string $captcha     验证码
+     */
+    public function resetpwd()
+    {
+        //$type = input("type");
+        $type = 'email';
+        $mobile = input("mobile");
+        $email = input("email");
+        $newpassword = input("newpassword");
+        $captcha = input("captcha");
+        if (!$newpassword || !$captcha) {
+            $this->error(__('Invalid parameters'));
+        }
+        if ($type == 'mobile') {
+            if (!Validate::regex($mobile, "^1\d{10}$")) {
+                $this->error(__('Mobile is incorrect'));
+            }
+            $user = \app\common\model\User::getByMobile($mobile);
+            if (!$user) {
+                $this->error(__('User not found'));
+            }
+            $ret = Sms::check($mobile, $captcha, 'resetpwd');
+            if (!$ret) {
+                $this->error(__('Captcha is incorrect'));
+            }
+            Sms::flush($mobile, 'resetpwd');
+        } else {
+            if (!Validate::is($email, "email")) {
+                $this->error(__('Email is incorrect'));
+            }
+            $user = \app\common\model\User::getByEmail($email);
+            if (!$user) {
+                $this->error(__('User not found'));
+            }
+            $ret = Ems::check($email, $captcha, 'resetpwd');
+            if (!$ret) {
+                $this->error(__('Captcha is incorrect'));
+            }
+            Ems::flush($email, 'resetpwd');
+        }
+        //模拟一次登录
+        $this->auth->direct($user->id);
+        $ret = $this->auth->changepwd($newpassword, '', true);
+        if ($ret) {
+            $this->success(__('Reset password successful'));
+        } else {
+            $this->error($this->auth->getError());
+        }
+    }
 
     /**
      * 手机验证码验证
@@ -1233,94 +1345,6 @@ class User extends Api
         }
     }*/
     
-    //注册完善资料
-    public function perfect_info() {
-        $avatar = input('avatar', '', 'trim'); //头像
-        $nickname = input('nickname', '', 'trim'); //昵称
-        $birthday = input('birthday', '', 'strtotime'); //生日
-        $hometown_cityid = input('hometown_cityid', '', 'trim'); //城市id
-        $hobby = input('hobby', '', 'trim'); //爱好
-        $marital = input('marital', '', 'trim'); //婚姻
-        $introcode = input('introcode', '', 'trim'); //邀请码
-
-        $data = [];
-        if ($avatar) {
-            $data['avatar'] = $avatar;
-        }
-        if ($nickname !== '') {
-            if (iconv_strlen($nickname, 'utf-8') > 10) {
-                $this->error('昵称最多10个字~');
-            }
-            $data['nickname'] = $nickname;
-        }
-        if ($birthday) {
-            $data['birthday'] = $birthday;
-        }
-        if ($hometown_cityid) {
-            $count = Db::name('area')->where('id', $hometown_cityid)->count('id');
-            if (!$count) {
-                $this->error('城市不存在');
-            }
-            $data['hometown_cityid'] = $hometown_cityid;
-        }
-        if ($hobby) {
-            $data['hobby'] = $hobby;
-        }
-        if ($marital) {
-            $data['marital'] = $marital;
-        }
-        if ($introcode && !$this->auth->intro_uid) {
-
-
-            $intro_user = Db::name('user')->field('id, intro_uid')->where('introcode', $introcode)->find();
-            if ($intro_user && $intro_user['id'] != $this->auth->id && $intro_user['intro_uid'] != $this->auth->id) {
-                $data['intro_uid'] = $intro_user['id'];
-                $data['invite_time'] = time();
-            }
-        }
-
-
-
-        //开启事务
-        Db::startTrans();
-        $update_rs = Db::name('user')->where('id',$this->auth->id)->setField($data);
-        if($update_rs === false){
-            Db::rollback();
-            $this->error('修改失败');
-        }
-
-        //给上级发放钻石
-        if(isset($data['intro_uid'])){
-            $intro_jewel = config('site.new_user_intro_jewel');
-            if($intro_jewel > 0){
-                $rs_wallet = model('wallet')->lockChangeAccountRemain($data['intro_uid'], 0,'jewel',$intro_jewel,34,'邀请'.$this->auth->username.'注册奖励');
-                if($rs_wallet['status'] === false){
-                    Db::rollback();
-                    $this->error('邀请新人奖励赠送失败');
-                }
-            }
-        }
-
-        //上传头像加5金币
-        if(isset($data['avatar'])){
-            $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,19);
-            if($task_rs === false){
-                Db::rollback();
-                $this->error('完成任务赠送奖励失败');
-            }
-        }
-        if (isset($data['birthday'])) {
-            //完成设置生日  +5金币
-            $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,1);
-            if($task_rs === false){
-                Db::rollback();
-                $this->error('完成任务赠送奖励失败');
-            }
-        }
-
-        Db::commit();
-        $this->success('修改成功');
-    }
 
     //实名认证
     public function idcard_auth() {
@@ -1830,30 +1854,6 @@ class User extends Api
 //        $this->success('success', $haibao);
     }
 
-    //注册设置性别
-    public function setgender() {
-        $user_id = $this->auth->id;
-
-        $gender = input('gender', -1, 'intval'); //性别:1=男,0=女
-        if (!in_array($gender, [1, 0])) {
-            $this->error('性别错误');
-        }
-
-        $edit_data['gender'] = $gender;
-        $edit_data['avatar'] = $gender == 1 ? config('avatar_boy') : config('avatar_girl'); //头像
-
-        $rs = Db::name('user')->where(['id' => $user_id, 'gender' => $this->auth->gender])->setField($edit_data);
-        if (!$rs) {
-            $this->error('您的网络开小差啦~');
-        }
-
-        //$data = $this->userInfo('return');
-        $data['gender'] = $edit_data['gender'];
-        $data['avatar'] = $edit_data['avatar'];
-
-        $this->success('success', $data);
-
-    }
 
     //真人认证后修改头像前比对
     public function realavatar_auit() {