Userbank.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. use app\common\library\Sms;
  6. /**
  7. *
  8. */
  9. class Userbank extends Api
  10. {
  11. protected $noNeedLogin = [];
  12. protected $noNeedRight = ['*'];
  13. /**
  14. * 绑定银行卡
  15. */
  16. public function bindbank() {
  17. //
  18. $bank_no = input('bank_no');// 银行账号
  19. $open_bank = input('open_bank');// 开户行
  20. $realname = input('realname');// 姓名
  21. if(!$bank_no || !$open_bank || !$realname ) {
  22. $this->error("请将信息填写完整");
  23. }
  24. $userId = $this->auth->id;
  25. // 查询是否有过绑定
  26. $bankInfo = Db::name('user_bank')->where(["user_id"=>$userId])->find();
  27. $data = [];
  28. $data["realname"] = $realname;
  29. $data["bank_no"] = $bank_no;
  30. $data["open_bank"] = $open_bank;
  31. if($bankInfo) {
  32. $res = Db::name('user_bank')->where(["user_id"=>$userId])->update($data);
  33. } else {
  34. $data["user_id"] = $userId;
  35. $res = Db::name('user_bank')->insertGetId($data);
  36. }
  37. $this->success("银行卡绑定成功!");
  38. }
  39. /**
  40. * 获取绑定银行卡信息
  41. */
  42. public function getbankinfo() {
  43. // 查询是否有过绑定
  44. $bankInfo = Db::name('user_bank')->where(["user_id"=>$this->auth->id])->find();
  45. $this->success("获取成功!",$bankInfo);
  46. }
  47. /**
  48. * 绑定支付宝
  49. */
  50. public function bindAlipay() {
  51. $captcha = input('captcha');
  52. if (!$captcha) {
  53. $this->error(__('Invalid parameters'));
  54. }
  55. $result = Sms::check($this->auth->mobile, $captcha, 'changemobile');
  56. if (!$result) {
  57. $this->error(__('Captcha is incorrect'));
  58. }
  59. //
  60. $payNo = input('pay_no');//支付宝账号
  61. if(!$payNo) {
  62. $this->error("请将信息填写完整");
  63. }
  64. $userId = $this->auth->id;
  65. //检测实名认证
  66. $userAuthWhere['user_id'] = $userId;
  67. $userAuth = Db::name('user_idconfirm')->where($userAuthWhere)->find();
  68. if (empty($userAuth)) {
  69. $this->error('请先实名认证');
  70. }
  71. if ($userAuth['status'] != 1) {
  72. $this->error('请先实名认证通过');
  73. }
  74. // 查询是否有过绑定
  75. $bankInfo = Db::name('user_alipay')->where(["user_id"=>$userId])->find();
  76. $data = [];
  77. $data["realname"] = $userAuth['realname'];
  78. $data["pay_no"] = $payNo;
  79. if($bankInfo) {
  80. $res = Db::name('user_alipay')->where(["user_id"=>$userId])->update($data);
  81. } else {
  82. $data["user_id"] = $userId;
  83. $res = Db::name('user_alipay')->insertGetId($data);
  84. }
  85. if($res) {
  86. $this->success("支付宝绑定成功!");
  87. } else {
  88. $this->error("网络异常,请稍后重试!");
  89. }
  90. }
  91. /**
  92. * 获取绑定银行卡信息
  93. */
  94. public function getAlipayInfo() {
  95. // 查询是否有过绑定
  96. $alipayInfo = Db::name('user_alipay')->where(["user_id"=>$this->auth->id])->find();
  97. $this->success("获取成功!",$alipayInfo);
  98. }
  99. /**
  100. * 绑定微信
  101. */
  102. public function bindWechat() {
  103. $captcha = input('captcha');
  104. if (!$captcha) {
  105. $this->error(__('Invalid parameters'));
  106. }
  107. $result = Sms::check($this->auth->mobile, $captcha, 'changemobile');
  108. if (!$result) {
  109. $this->error(__('Captcha is incorrect'));
  110. }
  111. //
  112. $payNo = input('pay_no');//支付宝账号
  113. if(!$payNo) {
  114. $this->error("请将信息填写完整");
  115. }
  116. $userId = $this->auth->id;
  117. //检测实名认证
  118. $userAuthWhere['user_id'] = $userId;
  119. $userAuth = Db::name('user_idconfirm')->where($userAuthWhere)->find();
  120. if (empty($userAuth)) {
  121. $this->error('请先实名认证');
  122. }
  123. if ($userAuth['status'] != 1) {
  124. $this->error('请先实名认证通过');
  125. }
  126. // 查询是否有过绑定
  127. $bankInfo = Db::name('user_wechat')->where(["user_id"=>$userId])->find();
  128. $data = [];
  129. $data["realname"] = $userAuth['realname'];
  130. $data["pay_no"] = $payNo;
  131. if($bankInfo) {
  132. $res = Db::name('user_wechat')->where(["user_id"=>$userId])->update($data);
  133. } else {
  134. $data["user_id"] = $userId;
  135. $res = Db::name('user_wechat')->insertGetId($data);
  136. }
  137. if($res) {
  138. $this->success("绑定成功!");
  139. } else {
  140. $this->error("网络异常,请稍后重试!");
  141. }
  142. }
  143. /**
  144. * 获取绑定银行卡信息
  145. */
  146. public function getWechatInfo() {
  147. // 查询是否有过绑定
  148. $alipayInfo = Db::name('user_wechat')->where(["user_id"=>$this->auth->id])->find();
  149. $this->success("获取成功!",$alipayInfo);
  150. }
  151. }