123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- <?php
- namespace app\api\controller;
- use app\common\library\Sms;
- use app\common\controller\Api;
- use app\common\service\UserService;
- use fast\Random;
- use think\Db;
- use think\Exception;
- use think\Validate;
- use app\common\model\UserAlipay;
- /**
- *
- */
- class Withdraw extends Api
- {
- protected $layout = 'default';
- protected $noNeedLogin = [];
- protected $noNeedRight = ['*'];
- /**
- * 获取用户账户信息
- */
- public function getUserAccountInfo() {
- // 获取用户信息
- $res = \app\common\model\User::field("id,u_id,avatar,mobile,nickname")->where(["id"=>$this->auth->id])->find();
- //用户钱包
- $userwallet = Db::name('user_wallet')->where('user_id',$this->auth->id)->find();
- $res['use_money'] = $userwallet['money'];
- $res['all_money'] = $userwallet['money'];
- // 获取用户实名认证信息
- $res["realname"] = \app\common\model\UserAuth::where(["user_id"=>$res["id"]])->value("realname");
- // 获取用户银行卡信息
- $res["bankInfo"] = \app\common\model\UserBank::where(["user_id"=>$res["id"]])->find();
- $this->success("获取成功!",$res);
- }
- 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('手机号与绑定不一致');
- }
- if ($code == '1212') {
- $this->success('验证成功');
- }
- //$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());
- }
- }
- }
|