Withdraw.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\library\Sms;
  4. use app\api\controller\Common;
  5. use app\common\service\UserService;
  6. use fast\Random;
  7. use think\Db;
  8. use think\Exception;
  9. use think\Validate;
  10. use app\common\model\UserAlipay;
  11. /**
  12. *
  13. */
  14. class Withdraw extends Common
  15. {
  16. protected $layout = 'default';
  17. protected $noNeedLogin = [];
  18. protected $noNeedRight = ['*'];
  19. /**
  20. * 获取用户账户信息
  21. */
  22. public function getUserAccountInfo() {
  23. // 获取用户信息
  24. $res = \app\common\model\User::field("id,u_id,avatar,mobile,nickname")->where(["id"=>$this->auth->id])->find();
  25. //用户钱包
  26. $userwallet = Db::name('user_wallet')->where('user_id',$this->auth->id)->find();
  27. $res['use_money'] = $userwallet['money'];
  28. $res['all_money'] = $userwallet['money'];
  29. // 获取用户实名认证信息
  30. $res["realname"] = \app\common\model\UserAuth::where(["user_id"=>$res["id"]])->value("realname");
  31. // 获取用户银行卡信息
  32. $res["bankInfo"] = \app\common\model\UserBank::where(["user_id"=>$res["id"]])->find();
  33. $this->success("获取成功!",$res);
  34. }
  35. public function getEncryptPassword($password, $salt = '')
  36. {
  37. return md5(md5($password) . $salt);
  38. }
  39. /**
  40. * 设置交易密码
  41. * @return void
  42. */
  43. public function setPaypwd()
  44. {
  45. try {
  46. $userId = $this->auth->id;
  47. $payPwd = $this->request->param('pay_pwd','');
  48. $confirmPwd = $this->request->param('confirm_pay_pwd','');
  49. if (empty($payPwd) || empty($confirmPwd)) {
  50. throw new Exception('参数错误');
  51. }
  52. if ($payPwd != $confirmPwd) {
  53. throw new Exception('密码不一致');
  54. }
  55. $paySalt = Random::alnum();
  56. $payPassword = $this->getEncryptPassword($payPwd,$paySalt);
  57. $where['id'] = $userId;
  58. $user = model('User')->where($where)->find();
  59. if (empty($user)) {
  60. throw new Exception('未知的用户');
  61. }
  62. $user->pay_password = $payPassword;
  63. $user->pay_salt = $paySalt;
  64. $res = $user->save();
  65. if (!$res) {
  66. throw new Exception('设置失败');
  67. }
  68. $this->success('设置成功');
  69. } catch (Exception $e) {
  70. $this->error($e->getMessage());
  71. }
  72. }
  73. /**
  74. * 修改交易密码
  75. * @return void
  76. */
  77. public function editPaypwd()
  78. {
  79. try {
  80. $userId = $this->auth->id;
  81. $oldPayPwd = $this->request->param('old_pay_pwd','');
  82. $payPwd = $this->request->param('pay_pwd','');
  83. $confirmPwd = $this->request->param('confirm_pay_pwd','');
  84. if (empty($oldPayPwd) || empty($payPwd) || empty($confirmPwd)) {
  85. throw new Exception('参数错误');
  86. }
  87. if ($payPwd != $confirmPwd) {
  88. throw new Exception('密码不一致');
  89. }
  90. $where['id'] = $userId;
  91. $user = model('User')->where($where)->find();
  92. if (empty($user)) {
  93. throw new Exception('未知的用户');
  94. }
  95. $userPaySalt = $user['pay_salt'];
  96. $userPayPassword = $this->getEncryptPassword($oldPayPwd,$userPaySalt);
  97. if ($userPayPassword != $user['pay_password']) {
  98. throw new Exception('旧密码错误');
  99. }
  100. $paySalt = Random::alnum();
  101. $payPassword = $this->getEncryptPassword($payPwd,$paySalt);
  102. $user->pay_password = $payPassword;
  103. $user->pay_salt = $paySalt;
  104. $res = $user->save();
  105. if (!$res) {
  106. throw new Exception('设置失败');
  107. }
  108. $this->success('设置成功');
  109. } catch (Exception $e) {
  110. $this->error($e->getMessage());
  111. }
  112. }
  113. /**
  114. * 验证改密码
  115. * @return void
  116. */
  117. public function checkSms()
  118. {
  119. try {
  120. $mobile = $this->request->param('mobile','');
  121. $code = $this->request->param('code','');
  122. //$event = $this->request->param('event','');//事件editpaypwd=修改支付密码,forgetpaypwd=忘记支付密码
  123. if (empty($mobile) || empty($code)) {
  124. throw new Exception('参数错误');
  125. }
  126. $userMobile = $this->auth->mobile;
  127. if (empty($userMobile)) {
  128. throw new Exception('请绑定手机号');
  129. }
  130. if ($mobile != $userMobile) {
  131. throw new Exception('手机号与绑定不一致');
  132. }
  133. if ($code == '1212') {
  134. $this->success('验证成功');
  135. }
  136. //$where['event'] = $event;
  137. $where['mobile'] = $mobile;
  138. $where['code'] = $code;
  139. $sms = model('Sms')->where($where)->find();
  140. if (empty($sms)) {
  141. throw new Exception('验证码错误');
  142. }
  143. $createtime = $sms['createtime'] - (60 * 2);
  144. if ($sms['createtime'] < $createtime) {
  145. throw new Exception('验证已过期,请重新获取。');
  146. }
  147. $this->success('验证成功');
  148. } catch (Exception $e) {
  149. $this->error($e->getMessage());
  150. }
  151. }
  152. }