|  | @@ -4,6 +4,7 @@ namespace app\api\controller;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  use app\common\library\Sms;
 | 
	
		
			
				|  |  |  use app\api\controller\Common;
 | 
	
		
			
				|  |  | +use fast\Random;
 | 
	
		
			
				|  |  |  use think\Db;
 | 
	
		
			
				|  |  |  use think\Exception;
 | 
	
		
			
				|  |  |  use think\Validate;
 | 
	
	
		
			
				|  | @@ -328,4 +329,122 @@ class Withdraw extends Common
 | 
	
		
			
				|  |  |              $this->error("没有查询到用户信息!请前往app注册!");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | +    public function getEncryptPassword($password, $salt = '')
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        return md5(md5($password) . $salt);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 设置交易密码
 | 
	
		
			
				|  |  | +     * @return void
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    public function setPaypwd()
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            $userId = $this->auth->id;
 | 
	
		
			
				|  |  | +            $payPwd = $this->request->param('pay_pwd','');
 | 
	
		
			
				|  |  | +            $confirmPwd = $this->request->param('confirm_pay_pwd','');
 | 
	
		
			
				|  |  | +            if (empty($payPwd) || empty($confirmPwd)) {
 | 
	
		
			
				|  |  | +                throw new Exception('参数错误');
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if ($payPwd != $confirmPwd) {
 | 
	
		
			
				|  |  | +                throw new Exception('密码不一致');
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            $paySalt = Random::alnum();
 | 
	
		
			
				|  |  | +            $payPassword = $this->getEncryptPassword($payPwd,$paySalt);
 | 
	
		
			
				|  |  | +            $where['id'] = $userId;
 | 
	
		
			
				|  |  | +            $user = model('User')->where($where)->find();
 | 
	
		
			
				|  |  | +            if (empty($user)) {
 | 
	
		
			
				|  |  | +                throw new Exception('未知的用户');
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            $user->pay_password = $payPassword;
 | 
	
		
			
				|  |  | +            $user->pay_salt = $paySalt;
 | 
	
		
			
				|  |  | +            $res = $user->save();
 | 
	
		
			
				|  |  | +            if (!$res) {
 | 
	
		
			
				|  |  | +                throw new Exception('设置失败');
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            $this->success('设置成功');
 | 
	
		
			
				|  |  | +        } catch (Exception $e) {
 | 
	
		
			
				|  |  | +            $this->error($e->getMessage());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 修改交易密码
 | 
	
		
			
				|  |  | +     * @return void
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    public function editPaypwd()
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            $userId = $this->auth->id;
 | 
	
		
			
				|  |  | +            $oldPayPwd = $this->request->param('old_pay_pwd','');
 | 
	
		
			
				|  |  | +            $payPwd = $this->request->param('pay_pwd','');
 | 
	
		
			
				|  |  | +            $confirmPwd = $this->request->param('confirm_pay_pwd','');
 | 
	
		
			
				|  |  | +            if (empty($oldPayPwd) || empty($payPwd) || empty($confirmPwd)) {
 | 
	
		
			
				|  |  | +                throw new Exception('参数错误');
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if ($payPwd != $confirmPwd) {
 | 
	
		
			
				|  |  | +                throw new Exception('密码不一致');
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            $where['id'] = $userId;
 | 
	
		
			
				|  |  | +            $user = model('User')->where($where)->find();
 | 
	
		
			
				|  |  | +            if (empty($user)) {
 | 
	
		
			
				|  |  | +                throw new Exception('未知的用户');
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            $userPaySalt = $user['pay_salt'];
 | 
	
		
			
				|  |  | +            $userPayPassword = $this->getEncryptPassword($oldPayPwd,$userPaySalt);
 | 
	
		
			
				|  |  | +            if ($userPayPassword != $user['pay_password']) {
 | 
	
		
			
				|  |  | +                throw new Exception('旧密码错误');
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            $paySalt = Random::alnum();
 | 
	
		
			
				|  |  | +            $payPassword = $this->getEncryptPassword($payPwd,$paySalt);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            $user->pay_password = $payPassword;
 | 
	
		
			
				|  |  | +            $user->pay_salt = $paySalt;
 | 
	
		
			
				|  |  | +            $res = $user->save();
 | 
	
		
			
				|  |  | +            if (!$res) {
 | 
	
		
			
				|  |  | +                throw new Exception('设置失败');
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            $this->success('设置成功');
 | 
	
		
			
				|  |  | +        } catch (Exception $e) {
 | 
	
		
			
				|  |  | +            $this->error($e->getMessage());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 验证改密码
 | 
	
		
			
				|  |  | +     * @return void
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    public function checkSms()
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            $mobile = $this->request->param('mobile','');
 | 
	
		
			
				|  |  | +            $code = $this->request->param('code','');
 | 
	
		
			
				|  |  | +            //$event = $this->request->param('event','');//事件editpaypwd=修改支付密码,forgetpaypwd=忘记支付密码
 | 
	
		
			
				|  |  | +            if (empty($mobile) || empty($code)) {
 | 
	
		
			
				|  |  | +                throw new Exception('参数错误');
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            $userMobile = $this->auth->mobile;
 | 
	
		
			
				|  |  | +            if (empty($userMobile)) {
 | 
	
		
			
				|  |  | +                throw new Exception('绑定手机号');
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if ($mobile != $userMobile) {
 | 
	
		
			
				|  |  | +                throw new Exception('手机号与绑定不一致');
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            //$where['event'] = $event;
 | 
	
		
			
				|  |  | +            $where['mobile'] = $mobile;
 | 
	
		
			
				|  |  | +            $where['code'] = $code;
 | 
	
		
			
				|  |  | +            $sms = model('Sms')->where($where)->find();
 | 
	
		
			
				|  |  | +            if (empty($sms)) {
 | 
	
		
			
				|  |  | +                throw new Exception('验证码错误');
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            $createtime = $sms['createtime'] - (60 * 2);
 | 
	
		
			
				|  |  | +            if ($sms['createtime'] < $createtime) {
 | 
	
		
			
				|  |  | +                throw new Exception('验证已过期,请重新获取。');
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            $this->success('验证成功');
 | 
	
		
			
				|  |  | +        } catch (Exception $e) {
 | 
	
		
			
				|  |  | +            $this->error($e->getMessage());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  }
 |