|  | @@ -55,76 +55,43 @@ class User extends Api
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  |      public function profile()
 | 
	
		
			
				|  |  |      {
 | 
	
		
			
				|  |  | -        $user = $this->auth->getUser();
 | 
	
		
			
				|  |  | -        $username = $this->request->post('username');
 | 
	
		
			
				|  |  | -        $nickname = $this->request->post('nickname');
 | 
	
		
			
				|  |  | -        $bio = $this->request->post('bio');
 | 
	
		
			
				|  |  | -        $avatar = $this->request->post('avatar', '', 'trim,strip_tags,htmlspecialchars');
 | 
	
		
			
				|  |  | -        if ($username) {
 | 
	
		
			
				|  |  | -            $exists = \app\common\model\User::where('username', $username)->where('id', '<>', $this->auth->id)->find();
 | 
	
		
			
				|  |  | -            if ($exists) {
 | 
	
		
			
				|  |  | -                $this->error(__('Username already exists'));
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            $user->username = $username;
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        if ($nickname) {
 | 
	
		
			
				|  |  | -            $exists = \app\common\model\User::where('nickname', $nickname)->where('id', '<>', $this->auth->id)->find();
 | 
	
		
			
				|  |  | -            if ($exists) {
 | 
	
		
			
				|  |  | -                $this->error(__('Nickname already exists'));
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            $user->nickname = $nickname;
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        $user->bio = $bio;
 | 
	
		
			
				|  |  | -        $user->avatar = $avatar;
 | 
	
		
			
				|  |  | -        $user->save();
 | 
	
		
			
				|  |  | -        $this->success();
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | +        $avatar = input('avatar', '', 'trim,strip_tags,htmlspecialchars');
 | 
	
		
			
				|  |  | +        $nickname = input('nickname', '');
 | 
	
		
			
				|  |  | +        $mobile = input('mobile', '');
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    /**
 | 
	
		
			
				|  |  | -     * 微信小程序登录+注册
 | 
	
		
			
				|  |  | -     * code得到openid
 | 
	
		
			
				|  |  | -     */
 | 
	
		
			
				|  |  | -    public function wxmini_openid_login() {
 | 
	
		
			
				|  |  | -        $code = input('code');
 | 
	
		
			
				|  |  | -        if (!$code) {
 | 
	
		
			
				|  |  | -            $this->error(__('Invalid parameters'));
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +        //修改用户
 | 
	
		
			
				|  |  | +        $data = [];
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        $config = config('wxMiniProgram');
 | 
	
		
			
				|  |  | -        $getopenid = 'https://api.weixin.qq.com/sns/jscode2session?appid='.$config['appid'].'&secret='.$config['secret'].'&js_code='.$code.'&grant_type=authorization_code';
 | 
	
		
			
				|  |  | -        $openidInfo = $this->getJson($getopenid);
 | 
	
		
			
				|  |  | -        if(!isset($openidInfo['openid'])) {
 | 
	
		
			
				|  |  | -            $this->error('用户openid获取失败',$openidInfo);
 | 
	
		
			
				|  |  | +        if(!empty($avatar))
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            $data['avatar'] = $avatar;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        $openid  = $openidInfo['openid'];
 | 
	
		
			
				|  |  | -        if (!$openid) {
 | 
	
		
			
				|  |  | -            $this->error('用户openid获取失败');
 | 
	
		
			
				|  |  | +        if(!empty($mobile))
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            if (\app\common\model\User::where('mobile', $mobile)->where('id', '<>', $this->auth->id)->find()) {
 | 
	
		
			
				|  |  | +                $this->error('手机号已被占用');
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            $data['mobile'] = $mobile;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        //用户信息
 | 
	
		
			
				|  |  | -        $userInfo = Db::name('user')->where(['mini_openid'=>$openid])->find();
 | 
	
		
			
				|  |  | +        if(!empty($nickname))
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            $data['nickname'] = $nickname;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        if($userInfo) {
 | 
	
		
			
				|  |  | -            if ($userInfo['status'] == 0) {
 | 
	
		
			
				|  |  | -                $this->error('账号已被禁用');
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            if ($userInfo['status'] == -1) {
 | 
	
		
			
				|  |  | -                $this->error('账号已被注销');
 | 
	
		
			
				|  |  | +        if(!empty($data)){
 | 
	
		
			
				|  |  | +            $update_rs = Db::name('user')->where('id',$this->auth->id)->update($data);
 | 
	
		
			
				|  |  | +            if($update_rs === false){
 | 
	
		
			
				|  |  | +                $this->error('修改资料失败');
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            //如果已经有账号则直接登录
 | 
	
		
			
				|  |  | -            $res = $this->auth->direct($userInfo['id']);
 | 
	
		
			
				|  |  | -        } else {
 | 
	
		
			
				|  |  | -            $res = $this->auth->openid_register($openid);
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        if($res) {
 | 
	
		
			
				|  |  | -            $this->success("登录成功!",$this->auth->getUserinfo());
 | 
	
		
			
				|  |  | -        } else {
 | 
	
		
			
				|  |  | -            $this->error($this->auth->getError());
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +        $this->success();
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  |       * 微信小程序登录+注册
 | 
	
		
			
				|  |  |       * code得到注册手机号,此手机号登录+注册
 | 
	
	
		
			
				|  | @@ -182,6 +149,52 @@ class User extends Api
 | 
	
		
			
				|  |  |      ////////////////////////////////下面的都没用到///////////////////////////////
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  | +     * 微信小程序登录+注册
 | 
	
		
			
				|  |  | +     * code得到openid
 | 
	
		
			
				|  |  | +     * 没用到
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    public function wxmini_openid_login() {
 | 
	
		
			
				|  |  | +        $code = input('code');
 | 
	
		
			
				|  |  | +        if (!$code) {
 | 
	
		
			
				|  |  | +            $this->error(__('Invalid parameters'));
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        $config = config('wxMiniProgram');
 | 
	
		
			
				|  |  | +        $getopenid = 'https://api.weixin.qq.com/sns/jscode2session?appid='.$config['appid'].'&secret='.$config['secret'].'&js_code='.$code.'&grant_type=authorization_code';
 | 
	
		
			
				|  |  | +        $openidInfo = $this->getJson($getopenid);
 | 
	
		
			
				|  |  | +        if(!isset($openidInfo['openid'])) {
 | 
	
		
			
				|  |  | +            $this->error('用户openid获取失败',$openidInfo);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        $openid  = $openidInfo['openid'];
 | 
	
		
			
				|  |  | +        if (!$openid) {
 | 
	
		
			
				|  |  | +            $this->error('用户openid获取失败');
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        //用户信息
 | 
	
		
			
				|  |  | +        $userInfo = Db::name('user')->where(['mini_openid'=>$openid])->find();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if($userInfo) {
 | 
	
		
			
				|  |  | +            if ($userInfo['status'] == 0) {
 | 
	
		
			
				|  |  | +                $this->error('账号已被禁用');
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if ($userInfo['status'] == -1) {
 | 
	
		
			
				|  |  | +                $this->error('账号已被注销');
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            //如果已经有账号则直接登录
 | 
	
		
			
				|  |  | +            $res = $this->auth->direct($userInfo['id']);
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            $res = $this->auth->openid_register($openid);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if($res) {
 | 
	
		
			
				|  |  | +            $this->success("登录成功!",$this->auth->getUserinfo());
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            $this->error($this->auth->getError());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  |       * 会员中心
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  |      public function index()
 |