Userbank.php 5.6 KB

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