Userbank.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. use app\common\service\UserService;
  6. /**
  7. *
  8. */
  9. class Userbank extends Api
  10. {
  11. protected $noNeedLogin = [];
  12. protected $noNeedRight = ['*'];
  13. /**
  14. * 绑定银行卡
  15. */
  16. public function bindBank() {
  17. $bank_no = $this->request->request('bank_no');// 银行账号
  18. $open_bank = $this->request->request('open_bank');// 开户行
  19. if(!$bank_no || !$open_bank ) {
  20. $this->error("请将信息填写完整");
  21. }
  22. $userId = $this->auth->id;
  23. //检测实名认证
  24. $userAuthWhere['user_id'] = $userId;
  25. $userAuth = Db::name('user_idconfirm')->where($userAuthWhere)->find();
  26. if (empty($userAuth)) {
  27. $this->error('请先实名认证');
  28. }
  29. if ($userAuth['status'] != 1) {
  30. $this->error('请先实名认证通过');
  31. }
  32. $truename = $userAuth['truename'];
  33. $idCard = $userAuth['idcard'];
  34. // 查询是否有过绑定
  35. $bankInfo = Db::name('user_bank')->where(["user_id"=>$userId])->find();
  36. $data = [];
  37. $data["truename"] = $truename;
  38. $data["idcard"] = $idCard;
  39. $data["bank_no"] = $bank_no;
  40. $data["open_bank"] = $open_bank;
  41. if($bankInfo) {
  42. $res = Db::name('user_bank')->where(["user_id"=>$userId])->update($data);
  43. } else {
  44. $data["user_id"] = $userId;
  45. $res = Db::name('user_bank')->insertGetId($data);
  46. }
  47. $this->success("银行卡绑定成功!");
  48. }
  49. /**
  50. * 获取绑定银行卡信息
  51. */
  52. public function getBankInfo() {
  53. // 查询是否有过绑定
  54. $bankInfo = Db::name('user_bank')->where(["user_id"=>$this->auth->id])->find();
  55. $this->success("获取成功!",$bankInfo);
  56. }
  57. /**
  58. * 绑定支付宝
  59. */
  60. public function bindAlipay() {
  61. $payNo = $this->request->request('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["truename"] = $userAuth['truename'];
  79. $data["pay_no"] = $payNo;
  80. $data["idcard"] = $userAuth['idcard'];
  81. if($bankInfo) {
  82. $res = Db::name('user_alipay')->where(["user_id"=>$userId])->update($data);
  83. } else {
  84. $data["user_id"] = $userId;
  85. $res = Db::name('user_alipay')->insertGetId($data);
  86. }
  87. if($res) {
  88. $this->success("支付宝绑定成功!");
  89. } else {
  90. $this->error("网络异常,请稍后重试!");
  91. }
  92. }
  93. /**
  94. * 获取绑定银行卡信息
  95. */
  96. public function getAlipayInfo() {
  97. // 查询是否有过绑定
  98. $alipayInfo = Db::name('user_alipay')->where(["user_id"=>$this->auth->id])->find();
  99. $this->success("获取成功!",$alipayInfo);
  100. }
  101. }