Browse Source

提现与日志

lizhen_gitee 1 year ago
parent
commit
3dc22198e2
2 changed files with 64 additions and 10 deletions
  1. 61 9
      application/api/controller/Takecash.php
  2. 3 1
      application/extra/wallet.php

+ 61 - 9
application/api/controller/Takecash.php

@@ -36,10 +36,39 @@ class Takecash extends Api
 
     //提现
     public function take_cash(){
-        $money = floatval(input_post('money',0));
+        $rc_id     = input_post('rc_id',0);
+        $freemoney = input_post('freemoney',0);
+        $type = input_post('type',1);
 
-        if(empty($money)){
-            $this->error();
+        if(!$rc_id && !$freemoney){
+            $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);
         }
 
         if(empty($this->auth->idcard_status)){
@@ -56,19 +85,42 @@ class Takecash extends Api
             $this->error('提现金额不能大于可提现余额');
         }
 
-        $idcard_confirm = Db::name('user_idconfirm')->where('user_id',$this->auth->id)->find();
+        $table_name = $type == 1 ? 'user_alipay' : 'user_bank';
+        $account_json = Db::name($table_name)->where('user_id',$this->auth->id)->find();
+        if(empty($account_json)){
+            $this->error('未绑定对应的提现账号');
+        }
+
+        $plat_bilv = config('site.withdrawal_plat_bili');
+        $get_money = bcdiv(bcmul($money,(100-$plat_bilv),2),100,2);
+
         $data = [
             'user_id' => $this->auth->id,
-            'number' => $money,
-            'alipay_account' => $idcard_confirm['alipay_account'],
-            'status' => 0,
+            '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('提现失败');
+        }
 
-        Db::name('take_cash')->insertGetId($data);
+        //扣除money
+        $rs_wallet = model('Wallet')->lockChangeAccountRemain($this->auth->id,'money',-$money,15,'提现','take_cash',$log_id);
+        if($rs_wallet['status']===false)
+        {
+            Db::rollback();
+            $this->error($rs_wallet['msg']);
+        }
 
-        //审核时候再扣,或者这里先扣,等需求方确认
+        Db::commit();
         $this->success('申请成功请等待审核');
     }
 

+ 3 - 1
application/extra/wallet.php

@@ -9,7 +9,9 @@ return [
 
         10 => '金币充值',//gold +
         14 => '金币首充赠送',
-        15 => '提现',      //money
+
+        15 => '提现',      //money-
+        16 => '提现拒绝返回',  //money+
 
         21 => '收益兑换金币',//money -
         22 => '收益兑换金币',//gold +