Browse Source

提现先扣款

lizhen_gitee 10 months ago
parent
commit
a924c092da

+ 16 - 6
application/admin/controller/Takecash.php

@@ -99,21 +99,31 @@ class Takecash extends Backend
             Db::startTrans();
 
             $rs = Db::name('take_cash')->where('id',$id)->update($data);
-
+            if($rs === false){
+                Db::rollback();
+                $this->error('审核失败');
+            }
 
             //tag任务赠送金币
             if($status == 1){
-                //扣钱
-                $wallet_rs = model('wallet')->lockChangeAccountRemain($info['user_id'],0,'money',-$info['number'],15,'提现:'.$info['number'],'take_cash',$info['id']);
+                $remark = '提现(成功)';
+                Db::name('user_money_log')->where('table','take_cash')->where('table_id',$id)->update(['remark'=>$remark]);
+
+                //系统消息
+                $msg_id = \app\common\model\Message::addMessage($info['user_id'],'提现审核','提现审核已经审核通过');
+            }elseif($status == 2){
+
+                $remark = '提现(驳回)';
+                Db::name('user_money_log')->where('table','take_cash')->where('table_id',$id)->update(['remark'=>$remark]);
+
+                //还钱
+                $wallet_rs = model('wallet')->lockChangeAccountRemain($info['user_id'],0,'money',$info['number'],115,'提现被拒返回:'.$info['number'],'take_cash',$info['id']);
                 if($wallet_rs['status'] === false){
                     Db::rollback();
                     $this->error($wallet_rs['msg']);
                 }
 
                 //系统消息
-                $msg_id = \app\common\model\Message::addMessage($info['user_id'],'提现审核','提现审核已经审核通过');
-            }elseif($status == 2){
-                //系统消息
                 $msg_id = \app\common\model\Message::addMessage($info['user_id'],'提现审核','提现审核审核不通过');
             }
             Db::commit();

+ 29 - 32
application/api/controller/Userwallet.php

@@ -201,17 +201,23 @@ class Userwallet extends Api
 
     //提现
     public function withdrawal() {
-        if ($this->auth->idcard_status != 1) {
-            $this->error('请先完成实名认证~');
-        }
 
-        $id = input('id', 0, 'intval');
-        $type = input('type', 0, 'intval'); //账户类型:1=支付宝,2=银行卡
-        $freemoney = input_post('freemoney', 0, 'intval'); //自定义金额
+        $id        = input('id', 0, 'intval');
+        $type      = input('type', 0, 'intval'); //账户类型:1=支付宝,2=银行卡
+        $freemoney = input('freemoney', 0, 'intval'); //自定义金额
 
         if (!$id && !$freemoney) {
             $this->error('请选择或填写提现金额');
         }
+
+        if (!in_array($type, [1, 2])) {
+            $this->error('请选择提现账户~');
+        }
+
+        if ($this->auth->idcard_status != 1) {
+            $this->error('请先完成实名认证~');
+        }
+
         if ($id > 0) {
             $withdrawal_config = Db::name('withdrawal_config')->find($id);
             if (!$withdrawal_config) {
@@ -225,35 +231,31 @@ class Userwallet extends Api
             }
 
             //扣除金额
-            $money = floatval($withdrawal_config['money']);
+            $money = $withdrawal_config['money'];
             //实际获得金额
             $real_money = $withdrawal_config['real_money'];
         }
         if ($freemoney > 0) {
             //扣除金额
             $money = $freemoney;
-            //实际获得金额
+            //平台手续费
             $bili = config('site.withdrawal_rate') >= 0 ? config('site.withdrawal_rate') : 10;
-            $real_money = number_format($money * (100 - $bili) / 100, 2, '.', '');
+            $plat_money = bcdiv(bcmul($money,$bili,2),100,2);
+
+            //减去手续费,得实得金额
+            $real_money = bcsub($money,$plat_money,2);
         }
 
-        if ($money <= 0) {
+        if ($money <= 0 || $real_money <= 0) {
             $this->error('提现金额异常');
         }
 
-        if (!in_array($type, [1, 2])) {
-            $this->error('请选择提现账户~');
-        }
+
 
         $check = Db::name('take_cash')->where(['user_id'=>$this->auth->id,'status'=>0])->find();
         if($check){
             $this->error('您有一笔提现在审核中,待审核通过后再申请提现。');
         }
-        $time = strtotime(date('Y-m-d'));
-        $check = Db::name('take_cash')->where(['user_id'=>$this->auth->id, 'wallet_id'=>$id, 'createtime' => ['egt', $time]])->find();
-        if($check){
-            $this->error('您今日已经提现过该额度');
-        }
 
         $user_money = model('wallet')->getwallet($this->auth->id,'money');
         if($money > $user_money){
@@ -281,19 +283,6 @@ class Userwallet extends Api
             'type' => $type,
             'realname' => $realname
         ];
-        //计算上级可获得金额
-        /*if ($this->auth->intro_uid) {
-            $data['intro_uid'] = $this->auth->intro_uid;
-            //获取返利比率
-            $intro_withdrawal_rebate_rate = (int)config('site.intro_withdrawal_rebate_rate');
-            if ($intro_withdrawal_rebate_rate > 0 && $intro_withdrawal_rebate_rate <= 100) {
-                //上级获得金额数量
-                $intro_uid_money = number_format($money * $intro_withdrawal_rebate_rate / 100, 2, '.', '');
-                if ($intro_uid_money > 0) {
-                    $data['intro_money'] = $intro_uid_money;
-                }
-            }
-        }*/
 
         $msg = '申请成功请等待审核';
 
@@ -305,8 +294,16 @@ class Userwallet extends Api
             $this->error('您的网络开小差啦~');
         }
 
+        //扣除money
+        $rs_wallet = model('Wallet')->lockChangeAccountRemain($this->auth->id,0,'money',-$data['number'],15,'提现(审核中)','take_cash',$log_id);
+        if($rs_wallet['status']===false)
+        {
+            Db::rollback();
+            $this->error($rs_wallet['msg']);
+        }
+
         Db::commit();
-        //审核时候再扣,或者这里先扣,等需求方确认
+
         $this->success($msg);
     }
 

+ 2 - 1
application/extra/wallet.php

@@ -12,7 +12,8 @@ return [
         12 => '语音通话消费',
         13 => '文字聊天消费',
         14 => '金币首充赠送',
-        15 => '提现',      //money
+        15 => '提现',      //money 减少
+        115 => '提现被拒返回',      //money 增加
         16 => '开通会员', //money
         17 => '开通会员赠送金币',
         18 => '兑换金币', //money