lizhen_gitee 1 год назад
Родитель
Сommit
31fe4ba384

+ 3 - 3
application/admin/controller/Userwithdraw.php

@@ -138,10 +138,10 @@ class Userwithdraw extends Backend
 
                 //部分提现:日志的提现id,改为0
                 if($info['from'] == 2){
-                    $rs_bufen = Db::name('user_score_log')->where('withdraw_id',$info['id'])->update(['withdraw_id'=>0]);
-                    if ($rs_bufen === false) {
+                    $wallet_rs = model('wallet')->lockChangeAccountRemain($info['user_id'],'shouyi',$info['score'],21,'兑换被拒绝','user_withdraw',$info['id']);
+                    if($wallet_rs['status'] === false){
                         Db::rollback();
-                        $this->error('申请兑换失败');
+                        $this->error($wallet_rs['msg']);
                     }
                 }
             }

+ 11 - 45
application/api/controller/Money.php

@@ -15,25 +15,10 @@ class Money extends Api
 
     //配置
     public function withdraw_config(){
-        //部分提现,直推返佣+下单收益
-        $map1 = [
-            'user_id'  => $this->auth->id,
-            'log_type' => 3,
-            'withdraw_id' => 0,
-        ];
-        $zhitui = Db::name('user_score_log')->where($map1)->sum('change_value');
-
-        $map2 = [
-            'user_id'  => $this->auth->id,
-            'log_type' => 5,
-            'withdraw_id' => 0,
-        ];
-        $shouyi = Db::name('user_score_log')->where($map2)->sum('shouyi');
-
 
         $data = [
             'score' => model('wallet')->getWallet($this->auth->id,'score'),
-            'score_bufen' => bcadd($zhitui,$shouyi),
+            'score_bufen' => model('wallet')->getWallet($this->auth->id,'shouyi'),
             'min_withdrawal_money' => config('site.min_withdrawal_money'),
             'max_withdrawal_money' => config('site.max_withdrawal_money'),
             'type_1' => Db::name('user_withdraw')->where('user_id',$this->auth->id)->where('type',1)->where('status',1)->field('realname,banknumber,bankname')->find(),
@@ -61,36 +46,18 @@ class Money extends Api
             $this->error('目前还有兑换在审核中,请稍后在兑换');
         }
 
+        //开启事务
+        Db::startTrans();
+
         //余额查询
         if($from == 'all'){
             $user_money = model('wallet')->getWallet($this->auth->id,'score');
         }else{
-
-            //部分提现,直推返佣+下单收益
-            $map1 = [
-                'user_id'  => $this->auth->id,
-                'log_type' => 3,
-                'withdraw_id' => 0,
-            ];
-            $zhitui = Db::name('user_score_log')->where($map1)->sum('change_value');
-
-            $map2 = [
-                'user_id'  => $this->auth->id,
-                'log_type' => 5,
-                'withdraw_id' => 0,
-            ];
-            $shouyi = Db::name('user_score_log')->where($map2)->sum('shouyi');
-
-            $user_money = bcadd($zhitui,$shouyi);
-
-            //记录id,等会修改状态
-            $user_score_log_ids_1 = Db::name('user_score_log')->where($map1)->column('id');
-            $user_score_log_ids_2 = Db::name('user_score_log')->where($map2)->column('id');
-
-            $user_score_log_ids = array_merge($user_score_log_ids_1,$user_score_log_ids_2);
+            $user_money =  model('wallet')->getWallet($this->auth->id,'shouyi');
         }
 
         if ($user_money <= 0) {
+            Db::rollback();
             $this->error('积分不足');
         }
 
@@ -107,8 +74,7 @@ class Money extends Api
         $data['from'] = ($from == 'all') ? 1 : 2; //all=1,bufen=2
 
 
-        //开启事务
-        Db::startTrans();
+
         //添加提现记录
         $log_id = Db::name('user_withdraw')->insertGetId($data);
         if (!$log_id) {
@@ -116,12 +82,12 @@ class Money extends Api
             $this->error('申请兑换失败');
         }
 
-        //积分日志改状态
+        //扣收益
         if($from == 'bufen'){
-            $rs_bufen = Db::name('user_score_log')->where('id','IN',$user_score_log_ids)->update(['withdraw_id'=>$log_id]);
-            if ($rs_bufen === false) {
+            $rs_wallet = model('wallet')->lockChangeAccountRemain($this->auth->id,'shouyi',-$data['score'],2,'积分兑换','user_withdraw',$log_id);
+            if ($rs_wallet['status'] == false) {
+                $this->error($rs_wallet['msg']);
                 Db::rollback();
-                $this->error('申请兑换失败');
             }
         }
 

+ 1 - 2
application/common/model/Wallet.php

@@ -67,7 +67,7 @@ class Wallet extends Model
      * @return array[log_table]
      * @return array[log_id]
      */
-    public function lockChangeAccountRemain($user_id,$accountType='money',$number,$logtype='',$remark='',$table='',$table_id=0,$table_uid=0,$shouyi = 0)
+    public function lockChangeAccountRemain($user_id,$accountType='money',$number,$logtype='',$remark='',$table='',$table_id=0,$table_uid=0)
     {
         //初始化
         $result = array(
@@ -126,7 +126,6 @@ class Wallet extends Model
             $data['table'] = $table;
             $data['table_id'] = $table_id;
             $data['table_uid'] = $table_uid;
-            $data['shouyi'] = $shouyi;
             $data['remark'] = $remark;
             $data['createtime'] = time();
             $data['updatetime'] = time();

+ 5 - 3
application/extra/wallet.php

@@ -8,12 +8,14 @@ return [
         21 => '积分兑换(被拒返回)', //score +
 
         3  => '直推代理奖励', //支付后立刻获得 score +
-        4  => '间推代理奖励', //支付后立刻获得 score +   废弃了
+        31  => '直推代理奖励', //支付后立刻获得 shouyi +
+//        4  => '间推代理奖励', //支付后立刻获得 score +   废弃了
 
         5  => '下单收益',    //订单10日结算 score +  (包含本金+收益)
+        51  => '下单纯收益',    //订单10日结算 shouyi +  (包含收益)
 
-        6  => '总代奖励',    //订单10日结算 score +     废弃了
-        7  => '总代奖励(间推)',//订单10日结算 score +    废弃了
+//        6  => '总代奖励',    //订单10日结算 score +     废弃了
+//        7  => '总代奖励(间推)',//订单10日结算 score +    废弃了
     ],
     'moneyname' => [
         'money'    => '佣金',

+ 17 - 1
application/index/controller/Plantask.php

@@ -66,6 +66,13 @@ class Plantask extends Controller
                         Db::rollback();
                         exit;
                     }
+
+                    $rs_wallet = $walletmodel->lockChangeAccountRemain($intro_uid,'shouyi',$score,31,'直推代理奖励'.$remark_shaoshang,'unishop_order',$order['id'],$order['user_id']);
+                    if($rs_wallet['status'] === false){
+                        echo $rs_wallet['msg'];
+                        Db::rollback();
+                        exit;
+                    }
                 }
             }
 
@@ -116,12 +123,21 @@ class Plantask extends Controller
         if($order['order_shouyi'] > 0){
             $shouyi = bcsub($order['order_shouyi'],$order['order_benjin']);  //可提现收益
             $remark = '本金:'.$order['order_benjin'].',收益:'.$shouyi;
-            $rs_wallet = model('wallet')->lockChangeAccountRemain($order['user_id'],'score',$order['order_shouyi'],5,$remark,'unishop_order',$order['id'],$order['user_id'],$shouyi);
+            $rs_wallet = model('wallet')->lockChangeAccountRemain($order['user_id'],'score',$order['order_shouyi'],5,$remark,'unishop_order',$order['id'],$order['user_id']);
             if($rs_wallet['status'] === false){
                 echo $rs_wallet['msg'];
                 Db::rollback();
                 exit;
             }
+
+            if($shouyi > 0){
+                $rs_wallet = model('wallet')->lockChangeAccountRemain($order['user_id'],'shouyi',$shouyi,51,$remark,'unishop_order',$order['id'],$order['user_id']);
+                if($rs_wallet['status'] === false){
+                    echo $rs_wallet['msg'];
+                    Db::rollback();
+                    exit;
+                }
+            }
         }
 
 /*