浏览代码

银行卡和支付宝

lizhen_gitee 4 月之前
父节点
当前提交
eb2484f750
共有 2 个文件被更改,包括 121 次插入100 次删除
  1. 0 100
      application/api/controller/User.php
  2. 121 0
      application/api/controller/Userbank.php

+ 0 - 100
application/api/controller/User.php

@@ -1481,107 +1481,7 @@ class User extends Api
         }
     }
 
-    //绑定支付宝
-    public function addalipayaccount() {
-        $id = input('id', 0, 'intval'); //账号id
-        $type = input('type', 0, 'intval'); //账号类型:1=支付宝,2=银行卡
-//        $type = 1;
-        $realname = input('realname', '', 'trim'); //账户真实姓名
-        $banknumber = input('banknumber', '', 'trim'); //卡号或账号
-        $bankname = input('bankname', '', 'trim'); //银行名称
-
-//        if ($id) {
-//            $this->error('您已经拥有该类型账号,请联系后台解绑');
-//        }
-        if (!in_array($type, [1, 2])) {
-            $this->error('参数错误');
-        }
-        /*if ($type == 1) {
-            $this->error('暂不支持绑定支付宝');
-        }*/
-        if ($realname === '' || iconv_strlen($realname, 'utf-8') > 30) {
-            $this->error('账号姓名1-30位');
-        }
-        if ($banknumber === '' || iconv_strlen($banknumber, 'utf-8') > 50) {
-            $this->error('账号1-50位');
-        }
-        if ($type == 1) {
-            if (iconv_strlen($bankname, 'utf-8') != 18) {
-                $this->error('请输入正确身份证号');
-            }
-        }
-        if ($type == 2) {
-            if ($bankname === '' || iconv_strlen($bankname, 'utf-8') > 50) {
-                $this->error('开户行名称1-50位');
-            }
-        }
-
-        $user_bank = Db::name('user_bank');
-        if ($id) {
-            //编辑
-            //查询账号是否存在
-            $info = $user_bank->where(['id' => $id, 'user_id' => $this->auth->id])->find();
-            if (!$info) {
-                $this->error('账号不存在');
-            }
-            if ($info['type'] != $type) {
-                $this->error('账号类型错误');
-            }
-            //查询是否未通过提现记录
-            $count = Db::name('take_cash')->where(['user_id' => $this->auth->id, 'alipay_account' => $info['banknumber'], 'status' => 0])->count('id');
-            if ($count) {
-                $this->error('该账户有未审核的提现记录,暂不可修改');
-            }
-
-            $data['realname'] = $realname;
-            $data['banknumber'] = $banknumber;
-            $data['updatetime'] = time();
-//            if ($type == 2) {
-                $data['bankname'] = $bankname;
-//            }
 
-            $rs = $user_bank->where(['id' => $id, 'user_id' => $this->auth->id])->setField($data);
-            if ($rs === false) {
-                $this->error('修改失败');
-            }
-
-            $this->success('修改成功');
-        } else {
-            //添加
-            //查询是否已经拥有该类型账号
-            $count = $user_bank->where(['user_id' => $this->auth->id, 'type' => $type])->count('id');
-            if ($count) {
-                $this->error('您已经拥有该类型账号,请联系后台解绑');
-            }
-
-            $data['user_id'] = $this->auth->id;
-            $data['type'] = $type;
-            $data['realname'] = $realname;
-            $data['banknumber'] = $banknumber;
-//            if ($type == 2) {
-                $data['bankname'] = $bankname;
-//            }
-            $data['createtime'] = time();
-
-            $rs = $user_bank->insertGetId($data);
-            if (!$rs) {
-                $this->error('添加失败');
-            }
-
-            $this->success('添加成功');
-        }
-    }
-
-    //查询支付宝/银行卡信息
-    public function alipayinfo() {
-        $type = input('type', 0, 'intval'); //账号类型:1=支付宝,2=银行卡
-        $info = Db::name('user_bank')->field('id, realname, banknumber, bankname')->where(['user_id' => $this->auth->id, 'type' => $type])->find();
-        if (!$info) {
-            $info = (object)[];
-        }
-
-        $this->success('success', $info);
-    }
 
     //申请真人认证
     public function realauth() {

+ 121 - 0
application/api/controller/Userbank.php

@@ -0,0 +1,121 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use think\Db;
+/**
+ * 绑定支付宝或银行
+ */
+class Userbank extends Api
+{
+
+    // 无需登录的接口,*表示全部
+    protected $noNeedLogin = [''];
+    // 无需鉴权的接口,*表示全部
+    protected $noNeedRight = ['*'];
+
+    //绑定支付宝
+    public function addalipayaccount() {
+        $id = input('id', 0, 'intval'); //账号id
+        $type = input('type', 0, 'intval'); //账号类型:1=支付宝,2=银行卡
+//        $type = 1;
+        $realname = input('realname', '', 'trim'); //账户真实姓名
+        $banknumber = input('banknumber', '', 'trim'); //卡号或账号
+        $bankname = input('bankname', '', 'trim'); //银行名称
+
+//        if ($id) {
+//            $this->error('您已经拥有该类型账号,请联系后台解绑');
+//        }
+        if (!in_array($type, [1, 2])) {
+            $this->error('参数错误');
+        }
+        /*if ($type == 1) {
+            $this->error('暂不支持绑定支付宝');
+        }*/
+        if ($realname === '' || iconv_strlen($realname, 'utf-8') > 30) {
+            $this->error('账号姓名1-30位');
+        }
+        if ($banknumber === '' || iconv_strlen($banknumber, 'utf-8') > 50) {
+            $this->error('账号1-50位');
+        }
+        if ($type == 1) {
+            if (iconv_strlen($bankname, 'utf-8') != 18) {
+                $this->error('请输入正确身份证号');
+            }
+        }
+        if ($type == 2) {
+            if ($bankname === '' || iconv_strlen($bankname, 'utf-8') > 50) {
+                $this->error('开户行名称1-50位');
+            }
+        }
+
+        $user_bank = Db::name('user_bank');
+        if ($id) {
+            //编辑
+            //查询账号是否存在
+            $info = $user_bank->where(['id' => $id, 'user_id' => $this->auth->id])->find();
+            if (!$info) {
+                $this->error('账号不存在');
+            }
+            if ($info['type'] != $type) {
+                $this->error('账号类型错误');
+            }
+            //查询是否未通过提现记录
+            $count = Db::name('take_cash')->where(['user_id' => $this->auth->id, 'alipay_account' => $info['banknumber'], 'status' => 0])->count('id');
+            if ($count) {
+                $this->error('该账户有未审核的提现记录,暂不可修改');
+            }
+
+            $data['realname'] = $realname;
+            $data['banknumber'] = $banknumber;
+            $data['updatetime'] = time();
+//            if ($type == 2) {
+            $data['bankname'] = $bankname;
+//            }
+
+            $rs = $user_bank->where(['id' => $id, 'user_id' => $this->auth->id])->setField($data);
+            if ($rs === false) {
+                $this->error('修改失败');
+            }
+
+            $this->success('修改成功');
+        } else {
+            //添加
+            //查询是否已经拥有该类型账号
+            $count = $user_bank->where(['user_id' => $this->auth->id, 'type' => $type])->count('id');
+            if ($count) {
+                $this->error('您已经拥有该类型账号,请联系后台解绑');
+            }
+
+            $data['user_id'] = $this->auth->id;
+            $data['type'] = $type;
+            $data['realname'] = $realname;
+            $data['banknumber'] = $banknumber;
+//            if ($type == 2) {
+            $data['bankname'] = $bankname;
+//            }
+            $data['createtime'] = time();
+
+            $rs = $user_bank->insertGetId($data);
+            if (!$rs) {
+                $this->error('添加失败');
+            }
+
+            $this->success('添加成功');
+        }
+    }
+
+    //查询支付宝/银行卡信息
+    public function alipayinfo() {
+        $type = input('type', 0, 'intval'); //账号类型:1=支付宝,2=银行卡
+        $info = Db::name('user_bank')->field('id, realname, banknumber, bankname')->where(['user_id' => $this->auth->id, 'type' => $type])->find();
+        if (!$info) {
+            $info = (object)[];
+        }
+
+        $this->success('success', $info);
+    }
+
+
+}