Userbank.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 会员银行卡
  7. */
  8. class Usercenter extends Api
  9. {
  10. protected $noNeedLogin = [];
  11. protected $noNeedRight = '*';
  12. //提现账号添加
  13. public function bankadd() {
  14. $bank_account = input('bank_account', '', 'trim'); //账户真实姓名
  15. $bank_card = input('bank_card', '', 'trim'); //卡号或账号
  16. $bank_name = input('bank_name', '', 'trim'); //银行名称
  17. $bank_branchname = input('bank_branchname', '', 'trim'); //支行名称
  18. if ($bank_account === '' || iconv_strlen($bank_account, 'utf-8') > 30) {
  19. $this->error('账号姓名1-30位');
  20. }
  21. if ($bank_card === '' || iconv_strlen($bank_card, 'utf-8') > 50) {
  22. $this->error('账号1-50位');
  23. }
  24. if ($bank_name === '' || iconv_strlen($bank_name, 'utf-8') > 50) {
  25. $this->error('银行名称1-50位');
  26. }
  27. if ($bank_branchname === '' || iconv_strlen($bank_branchname, 'utf-8') > 50) {
  28. $this->error('支行名称1-50位');
  29. }
  30. //添加
  31. $count = Db::name('user_bank')->where(['user_id' => $this->auth->id])->count('id');
  32. if ($count) {
  33. $this->error('您已经拥有该类型账号,不能再添加');
  34. }
  35. $data['user_id'] = $this->auth->id;
  36. $data['bank_account'] = $bank_account;
  37. $data['bank_card'] = $bank_card;
  38. $data['bank_name'] = $bank_name;
  39. $data['bank_branchname'] = $bank_branchname;
  40. $data['createtime'] = time();
  41. $rs = Db::name('user_bank')->insertGetId($data);
  42. if (!$rs) {
  43. $this->error('添加失败');
  44. }
  45. $this->success('添加成功');
  46. }
  47. //提现账号编辑
  48. public function bankedit(){
  49. $id = input('id', 0, 'intval'); //账号id
  50. $bank_account = input('bank_account', '', 'trim'); //账户真实姓名
  51. $bank_card = input('bank_card', '', 'trim'); //卡号或账号
  52. $bank_name = input('bank_name', '', 'trim'); //银行名称
  53. $bank_branchname = input('bank_branchname', '', 'trim'); //支行名称
  54. if ($bank_account === '' || iconv_strlen($bank_account, 'utf-8') > 30) {
  55. $this->error('账号姓名1-30位');
  56. }
  57. if ($bank_card === '' || iconv_strlen($bank_card, 'utf-8') > 50) {
  58. $this->error('账号1-50位');
  59. }
  60. if ($bank_name === '' || iconv_strlen($bank_name, 'utf-8') > 50) {
  61. $this->error('银行名称1-50位');
  62. }
  63. if ($bank_branchname === '' || iconv_strlen($bank_branchname, 'utf-8') > 50) {
  64. $this->error('支行名称1-50位');
  65. }
  66. //查询账号是否存在
  67. $info = Db::name('user_bank')->where(['id' => $id, 'user_id' => $this->auth->id])->find();
  68. if (!$info) {
  69. $this->error('账号不存在');
  70. }
  71. $data['bank_account'] = $bank_account;
  72. $data['bank_card'] = $bank_card;
  73. $data['bank_name'] = $bank_name;
  74. $data['bank_branchname'] = $bank_branchname;
  75. $data['updatetime'] = time();
  76. $rs = Db::name('user_bank')->where(['id' => $id])->update($data);
  77. if ($rs === false) {
  78. $this->error('修改失败');
  79. }
  80. $this->success('修改成功');
  81. }
  82. //提现账号信息
  83. public function bankinfo() {
  84. $info = Db::name('user_bank')->where(['user_id' => $this->auth->id])->find();
  85. if (!$info) {
  86. $info = (object)[];
  87. }
  88. $this->success('账户信息', $info);
  89. }
  90. }