Userbank.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. */
  51. public function bindAlipay() {
  52. $captcha = input('captcha');
  53. if (!$captcha) {
  54. $this->error(__('Invalid parameters'));
  55. }
  56. $result = Sms::check($this->auth->mobile, $captcha, 'changemobile');
  57. if (!$result) {
  58. $this->error(__('Captcha is incorrect'));
  59. }
  60. //
  61. $payNo = input('pay_no');//支付宝账号
  62. if(!$payNo) {
  63. $this->error("请将信息填写完整");
  64. }
  65. $userId = $this->auth->id;
  66. //检测实名认证
  67. $userAuthWhere['user_id'] = $userId;
  68. $userAuth = Db::name('user_idconfirm')->where($userAuthWhere)->find();
  69. if (empty($userAuth)) {
  70. $this->error('请先实名认证');
  71. }
  72. if ($userAuth['status'] != 1) {
  73. $this->error('请先实名认证通过');
  74. }
  75. // 查询是否有过绑定
  76. $bankInfo = Db::name('user_alipay')->where(["user_id"=>$userId])->find();
  77. $data = [];
  78. $data["realname"] = $userAuth['realname'];
  79. $data["pay_no"] = $payNo;
  80. if($bankInfo) {
  81. $res = Db::name('user_alipay')->where(["user_id"=>$userId])->update($data);
  82. } else {
  83. $data["user_id"] = $userId;
  84. $res = Db::name('user_alipay')->insertGetId($data);
  85. }
  86. if($res) {
  87. $this->success("支付宝绑定成功!");
  88. } else {
  89. $this->error("网络异常,请稍后重试!");
  90. }
  91. }
  92. /**
  93. * 获取绑定银行卡信息
  94. */
  95. public function getAlipayInfo() {
  96. // 查询是否有过绑定
  97. $alipayInfo = Db::name('user_alipay')->where(["user_id"=>$this->auth->id])->find();
  98. $this->success("获取成功!",$alipayInfo);
  99. }
  100. /**
  101. * 绑定微信
  102. */
  103. public function bindWechat() {
  104. $captcha = input('captcha');
  105. if (!$captcha) {
  106. $this->error(__('Invalid parameters'));
  107. }
  108. $result = Sms::check($this->auth->mobile, $captcha, 'changemobile');
  109. if (!$result) {
  110. $this->error(__('Captcha is incorrect'));
  111. }
  112. //
  113. $payNo = input('pay_no');//支付宝账号
  114. if(!$payNo) {
  115. $this->error("请将信息填写完整");
  116. }
  117. $userId = $this->auth->id;
  118. //检测实名认证
  119. $userAuthWhere['user_id'] = $userId;
  120. $userAuth = Db::name('user_idconfirm')->where($userAuthWhere)->find();
  121. if (empty($userAuth)) {
  122. $this->error('请先实名认证');
  123. }
  124. if ($userAuth['status'] != 1) {
  125. $this->error('请先实名认证通过');
  126. }
  127. // 查询是否有过绑定
  128. $bankInfo = Db::name('user_wechat')->where(["user_id"=>$userId])->find();
  129. $data = [];
  130. $data["realname"] = $userAuth['realname'];
  131. $data["pay_no"] = $payNo;
  132. if($bankInfo) {
  133. $res = Db::name('user_wechat')->where(["user_id"=>$userId])->update($data);
  134. } else {
  135. $data["user_id"] = $userId;
  136. $res = Db::name('user_wechat')->insertGetId($data);
  137. }
  138. if($res) {
  139. $this->success("绑定成功!");
  140. } else {
  141. $this->error("网络异常,请稍后重试!");
  142. }
  143. }
  144. /**
  145. * 获取绑定银行卡信息
  146. */
  147. public function getWechatInfo() {
  148. // 查询是否有过绑定
  149. $alipayInfo = Db::name('user_wechat')->where(["user_id"=>$this->auth->id])->find();
  150. $this->success("获取成功!",$alipayInfo);
  151. }
  152. }