lizhen_gitee 1 năm trước cách đây
mục cha
commit
5a75c03ad7

+ 183 - 0
application/api/controller/Takecash.php

@@ -0,0 +1,183 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use think\Db;
+/**
+ * 提现
+ */
+class Takecash extends Api
+{
+    protected $noNeedLogin = [];
+    protected $noNeedRight = ['*'];
+
+    //提现配置
+    public function take_cash_config(){
+        $config = Db::name('take_cash_config')->order('weigh asc,id asc')->select();
+
+        $plat_bilv = config('site.withdrawal_plat_bili');
+        foreach($config as $key => &$val){
+            $val['get_money'] = bcdiv(bcmul($val['money'],(100-$plat_bilv),2),100,2);
+        }
+
+        $data = [
+            'config' => $config,
+            'wallet' => model('wallet')->getwallet($this->auth->id),
+            'min' => config('site.min_withdrawal_money'),
+            'max' => config('site.max_withdrawal_money'),
+            'plat_bilv' => $plat_bilv,
+            'user_bank' => Db::name('user_bank')->where('user_id',$this->auth->id)->find(),
+            'user_alipay' => Db::name('user_alipay')->where('user_id',$this->auth->id)->find(),
+            'remark' => config('site.take_cash_rule'),
+        ];
+
+        $this->success('success',$data);
+    }
+
+    //提现
+    public function take_cash(){
+        $rc_id     = input('rc_id',0);
+        $freemoney = input('freemoney',0);
+        $type = input('type',1);
+
+        if(!$rc_id && !$freemoney){
+            $this->error('请选择或填写金额');
+        }
+
+        //验证提现类型
+        $withdraw_type = config('wallet.withdraw_type');
+        $typeIds = array_keys($withdraw_type);
+        if (!in_array($type,$typeIds)) {
+            $this->error('未知的提现类型');
+        }
+        $typeStr = isset($withdraw_type[$type]) ? $withdraw_type[$type] : '';
+
+        if(!$this->user_auth_limit()){
+            $this->error('请先完成实名认证');
+        }
+
+        //赋值money
+        if($rc_id){
+            $recharge_config = Db::name('take_cash_config')->where('id',$rc_id)->find();
+            $money = $recharge_config['money'] ?: 0;
+        }
+
+        //自由输入覆盖
+        if(!empty($freemoney)){
+            $rc_id = 0;
+            $money = floatval($freemoney);
+        }
+
+        //
+        if($money<=0)
+        {
+            $this->error('金额必须大于0');
+        }
+
+        $min = config('site.min_withdrawal_money');
+        $max = config('site.max_withdrawal_money');
+        if($money < $min){
+            $this->error('提现金额不能小于'.$min);
+        }
+        if($money > $max){
+            $this->error('提现金额不能大于'.$max);
+        }
+
+        $check = Db::name('take_cash')->where(['user_id'=>$this->auth->id,'status'=>0])->find();
+        if($check){
+            $this->error('您已经申请了提现,请等待审核');
+        }
+
+        $user_money = model('wallet')->getwallet($this->auth->id,'money');
+        if($money > $user_money){
+            $this->error('提现金额不能大于可提现余额');
+        }
+
+        if($type == 1){
+            $table_name = 'user_alipay';
+            $account_json = Db::name($table_name)->where('user_id',$this->auth->id)->find();
+            if(empty($account_json)){
+                $this->error('未绑定对应的提现账号');
+            }
+            $account = $account_json['pay_no'];
+            $name    = $account_json['realname'];
+        }elseif($type == 2){
+            $table_name = 'user_bank';
+            $account_json = Db::name($table_name)->where('user_id',$this->auth->id)->find();
+            if(empty($account_json)){
+                $this->error('未绑定对应的提现账号');
+            }
+            $account = $account_json['bank_no'];
+            $name    = $account_json['realname'];
+        }else{
+            //微信支付
+            $account_json = [];
+            $account = '';
+            $name = '';
+        }
+
+        $plat_bilv = config('site.withdrawal_plat_bili');
+        $get_money = bcdiv(bcmul($money,(100-$plat_bilv),2),100,2);
+
+        $data = [
+            'user_id' => $this->auth->id,
+            'money' => $money,
+            'get_money' => $get_money,
+            'type' => $type,
+            'acount_json' => json_encode($account_json),
+            'createtime' => time(),
+            'updatetime' => time(),
+            'status' => 0,
+        ];
+        Db::startTrans();
+
+        $log_id = Db::name('take_cash')->insertGetId($data);
+        if(!$log_id){
+            Db::rollback();
+            $this->error('提现失败');
+        }
+
+        //扣除money
+//        $rs_wallet = model('Wallet')->lockChangeAccountRemain($this->auth->id,'money',-$money,15,'提现','take_cash',$log_id);
+        $rs_wallet = model('Wallet')->lockChangeAccountRemain($this->auth->id,$money,'-',0,'提现',104,'money');
+        if($rs_wallet['status']===false)
+        {
+            Db::rollback();
+            $this->error($rs_wallet['msg']);
+        }
+
+        Db::commit();
+
+        /*$platformMoney = bcsub($money,$get_money,2);
+        $vbot = new \addons\vbot\Vbot();
+        $vbot->vbotSendMsg('Withdrawal_Application_Notice', [], [
+            'name' => $name,
+            'account' => $account,
+            'real_money' => $get_money,
+            'type' => $typeStr,
+            'handingfee' => $platformMoney
+        ]);*/
+
+        $this->success('申请成功请等待审核');
+    }
+
+    //提现记录
+    public function take_cash_log(){
+        $list = Db::name('take_cash')->field('id,money,type,createtime')->where(['user_id'=>$this->auth->id])->autopage()->select();
+        foreach($list as $key => &$val){
+            $val['remark'] = '';
+
+            if($val['type'] == 1){
+                $val['remark'] = '支付宝提现';
+            }elseif($val['type'] == 2){
+                $val['remark'] = '银行卡提现';
+            }else{
+                $val['remark'] = '微信提现';
+            }
+        }
+
+        $this->success('success',$list);
+    }
+
+}

+ 0 - 172
application/api/controller/Usercenter.php

@@ -444,176 +444,4 @@ class UserCenter extends Common
 
 
 
-
-
-    /**
-     * 提现配置列表
-     * @return void
-     */
-    public function withdrawalConfigList()
-    {
-        try {
-            $field = 'id,money,real_money';
-            $result = model('WithdrawalConfig')->field($field)->autopage()->order('weigh asc')->select();
-            if (!empty($result)) {
-                //设置是否使用自定义
-                $withdrawDefine = config('site.withdraw_define');
-                if ($withdrawDefine == 1) {
-                    $fieldArr = [[
-                        'id' => -1,
-                        'money' => 0,
-                        'real_money' => 0.00,
-                    ],];
-                    $result = array_merge($result,$fieldArr);
-                }
-            }
-            $this->success('获取成功',$result);
-        } catch (Exception $e) {
-            $this->error($e->getMessage());
-        }
-    }
-
-    /**
-     * 提现
-     * @return void
-     */
-    public function withdrawal()
-    {
-        Db::startTrans();
-        try {
-            $withdrawConfigId = $this->request->param('id',0);
-            $money = $this->request->param('money',0.00);
-            $type = $this->request->param('type',0);
-            $userId = $this->auth->id;
-            $isAnchor = $this->auth->is_anchor;
-            $userMoney = $this->auth->money;
-            if (empty($withdrawConfigId) && empty($money)) {
-                throw new Exception('参数错误');
-            }
-            //只有主播可以提现
-            if ($isAnchor != 2) {
-                throw new Exception('您不是主播不允许提现');
-            }
-            if ($this->auth->power->withdraw == 1) {
-                throw new Exception('您已被禁止提现');
-            }
-            //验证提现类型
-            $withdrawTypeConfig = config('wallet.withdraw_type');
-            $typeIds = array_keys($withdrawTypeConfig);
-            if (!in_array($type,$typeIds)) {
-                throw new Exception('未知的提现类型');
-            }
-            $typeStr = isset($withdrawTypeConfig[$type]) ? $withdrawTypeConfig[$type] : '';
-            $withdrawRateConfig = config('site.withdrawRate');//用户获取的金额比例(需要/100)
-            $withdrawRate = bcdiv($withdrawRateConfig,100,2);
-            if (!empty($money)) {//自定义金额
-                if ($money <= 0) {
-                    throw new Exception('金额有误');
-                }
-                $inputMoney = $money;
-                $moneys = bcmul($money,$withdrawRate,2);
-                $platformMoney = bcsub($money,$moneys,2);
-            } else {//提现配置
-                $where['id'] = $withdrawConfigId;
-                $withdrawalConfig = model('WithdrawalConfig')->where($where)->find();
-                if (empty($withdrawalConfig)) {
-                    throw new Exception('未知的配置信息');
-                }
-                $inputMoney = $withdrawalConfig['money'];
-                $moneys = $withdrawalConfig['money'];
-                $platformMoney = bcsub($moneys,$withdrawalConfig['real_money'],2);;
-            }
-            if ($moneys <= 0) {
-                throw new Exception('申请金额异常');
-            }
-            //扣减余额 记录余额日志
-            $walletRes = model('wallet')->lockChangeAccountRemain($userId, $inputMoney, '-', $userMoney, '申请提现', 104,'money');
-            if (!$walletRes['status']) {
-                throw new Exception($walletRes['msg']);
-            }
-            $account = $name = '';
-            if ($type == 1) {//微信
-                $account = '';
-                $name = '';
-            } elseif ($type == 2) {//支付宝
-                $userAlipayWhere['user_id'] = $userId;
-                $userAlipay = model('UserAlipay')->where($userAlipayWhere)->find();
-                if (empty($userAlipay)) {
-                    throw new Exception('请绑定支付宝');
-                }
-                $account = $userAlipay['pay_no'];
-                $name = $userAlipay['realname'];
-            } elseif ($type == 3) {//银行
-                $userBankWhere['user_id'] = $userId;
-                $userBank = model('UserBank')->where($userBankWhere)->find();
-                if (empty($userBank)) {
-                    throw new Exception('请绑定银行卡');
-                }
-                $account = $userBank['bank_no'];
-                $name = $userBank['realname'];
-            }
-            $realMoney = bcsub($inputMoney,$platformMoney,2);
-            if ($realMoney < 0.1) {
-                throw new Exception('输入金额请大于0.1');
-            }
-            $data = [
-                'user_id'       => $userId,//用户ID
-                'money'         => $inputMoney,//金额
-                'handingfee'    => $platformMoney,//手续费
-                'real_money'    => $realMoney,//金额
-                'taxes'         => 0.00,//税费
-                'type'          => $typeStr,//类型
-                'account'       => $account,//提现账户
-                'name'          => $name,//真实姓名
-                //'memo'          => '',//备注
-                'orderid'       => getMillisecond() . mt_rand(1, 1000),//订单号
-                //'transactionid' => '',//流水号
-                'status'        => 'created',//状态:created=申请中,successed=成功,rejected=已拒绝
-                //'transfertime'  => '',//转账时间
-                'createtime'    => time(),//添加时间
-            ];
-            $withdrawRes = model('Withdraw')->insertGetId($data);
-            if (!$withdrawRes) {
-                throw new Exception('提现失败');
-            }
-            Db::commit();
-            $vbot = new \addons\vbot\Vbot();
-            $vbot->vbotSendMsg('Withdrawal_Application_Notice', [], [
-                'name' => $name,
-                'account' => $account,
-                'real_money' => $realMoney,
-                'type' => $typeStr,
-                'handingfee' => $platformMoney
-            ]);
-            $this->success('操作成功待审核');
-        } catch (Exception $e) {
-            Db::rollback();
-            $this->error($e->getMessage());
-        }
-    }
-
-    /**
-     * 提现列表
-     * @return void
-     */
-    public function withdrawalList()
-    {
-        try {
-            $field = 'id,money,type,status,createtime,transfertime';
-            $where=[];
-            $where['user_id'] = $this->auth->id;
-            //$where['status'] = 'successed';//状态:created=申请中,successed=成功,rejected=已拒绝
-            $result = model('Withdraw')->field($field)->where($where)->autopage()->order('createtime desc')->select();
-            if (!empty($result)) {
-                foreach ($result as $key => &$value) {
-                    $value['money'] = '-'.$value['money'];
-                    $value['createtime'] = !empty($value['createtime']) ? date('Y-m-d H:i', $value['createtime']) : '';
-                    $value['transfertime'] = !empty($value['transfertime']) ? date('Y-m-d H:i', $value['transfertime']) : '';
-                }
-            }
-            $this->success('获取成功',$result);
-        } catch (Exception $e) {
-            $this->error($e->getMessage());
-        }
-    }
 }

+ 1 - 1
application/extra/site.php

@@ -79,7 +79,7 @@ return [
     ],
     'money_to_jewel_rule' => '1、每个档位不限制兑换次数 '."\r\n"
         .'2、兑换钻石即刻到账,若出现兑换失败或延迟的情况,请 联系在线客服处理',
-    'tixianshuoming' => '1、提现需要完成实名认证、否则无法提现 '."\r\n"
+    'take_cash_rule' => '1、提现需要完成实名认证、否则无法提现 '."\r\n"
         .'2、每个提现额度,每日可提现3次 '."\r\n"
         .'3、提现扣除手续费1‰ '."\r\n"
         .'4、相关额度会在1个工作日内审核发放,请注意查收',

+ 3 - 3
application/extra/wallet.php

@@ -44,8 +44,8 @@ return [
         'money'    => '余额',
     ],
     'withdraw_type' => [
-        1 => 'wechat',//微信
-        2 => 'alipay',//支付宝
-        3 => 'bank',  //银行
+        1 => 'alipay',//支付宝
+        2 => 'bank',  //银行
+        3 => 'wechat',//微信
     ],
 ];