Browse Source

充值,给上级,上上级 返佣金

lizhen_gitee 2 months ago
parent
commit
bcb389d39c
2 changed files with 44 additions and 9 deletions
  1. 42 8
      application/api/controller/Notify.php
  2. 2 1
      application/extra/wallet.php

+ 42 - 8
application/api/controller/Notify.php

@@ -110,25 +110,29 @@ class Notify extends Api
             }
         }
 
+        //我的
+        $user_wallet = Db::name('user_wallet')->field('intro_level,intro_uid')->where('user_id',$user_id)->find();
+
+        //上级
+        $intro_uid = $user_wallet['intro_uid'];
+        $up_wallet = Db::name('user_wallet')->field('intro_level,money,intro_uid')->where('user_id',$intro_uid)->find();
+
+        //星级配置
+        $intro_level_config = Db::name('intro_level_config')->order('id asc')->select();
+        $intro_level_column = array_column($intro_level_config,'intro_bili','id'); // [id => intro_bili]
+
         //入金升级
         if($orderInfo['order_amount'] >= config('site.intro_rujin_money')){
 
-            $user_wallet = Db::name('user_wallet')->field('intro_level,intro_uid')->where('user_id',$user_id)->find();//我的
-
             //自己入金
             if($user_wallet['intro_level'] == '-1'){
 
-                //星级配置
-                $intro_level_config = Db::name('intro_level_config')->order('id asc')->select();
-
                 //看看直推了几个,就给升到对应的星级
                 $intro_num = Db::name('user_wallet')->where('intro_uid',$user_id)->where('intro_level','neq','-1')->count();//我直推的个数(入金的)
                 $level = $this->get_intro_level($intro_level_config,$intro_num);
                 Db::name('user_wallet')->where('user_id',$user_id)->update(['intro_level'=>$level]); //我升级了,最低入金,最高顶级
 
                 //上级升级
-                $intro_uid = $user_wallet['intro_uid'];
-                $up_wallet = Db::name('user_wallet')->field('intro_level')->where('user_id',$intro_uid)->find();//上级
                 if($up_wallet && $up_wallet['intro_level'] != 5){
                     //看看直推了几个,就给升到对应的星级
                     $intro_num = Db::name('user_wallet')->where('intro_uid',$intro_uid)->where('intro_level','neq','-1')->count();//直推的个数(入金的)
@@ -139,7 +143,37 @@ class Notify extends Api
 
         }
 
-        //给上级提成
+        //提成
+        $chuju = config('site.intro_chuju_min_money');
+        if($up_wallet && $up_wallet['money'] >= $chuju && $up_wallet['intro_level'] >= 1 && $up_wallet['intro_level'] >= $user_wallet['intro_level']){
+
+            //上级提成
+            $intro_money = bcdiv(bcmul($orderInfo['order_amount'],$intro_level_column[$up_wallet['intro_level']],2),100,2);
+            if($intro_money > 0){
+                $result = model('Wallet')->lockChangeAccountRemain($intro_uid,'intromoney',$intro_money,101, $user_id.'充值'.$orderInfo['order_amount'],'pay_order',$orderInfo['id']);
+                if($result['status']===false)
+                {
+                    Db::rollback();
+                    return false;
+                }
+            }
+
+            //上上级提成
+            $top_uid = $up_wallet['intro_uid'];
+            $top_wallet = Db::name('user_wallet')->field('intro_level,money')->where('user_id',$top_uid)->find();
+            if($top_wallet && $top_wallet['money'] >= $chuju && $top_wallet['intro_level'] >= 1 && $top_wallet['intro_level'] >= $up_wallet['intro_level']){
+                $top_money = bcdiv(bcmul($orderInfo['order_amount'],$intro_level_column[$top_wallet['intro_level']],2),100,2);
+                if($top_money > 0){
+                    $result = model('Wallet')->lockChangeAccountRemain($top_uid,'intromoney',$top_money,102, $user_id.'充值'.$orderInfo['order_amount'],'pay_order',$orderInfo['id']);
+                    if($result['status']===false)
+                    {
+                        Db::rollback();
+                        return false;
+                    }
+                }
+            }
+
+        }
 
 
         //默认提交

+ 2 - 1
application/extra/wallet.php

@@ -13,7 +13,8 @@ return [
         31 => '商城购物',//money -
 //        32 => '商城退款',//money +
 ///////////////////////
-        101 => '',  //intromoney
+        101 => '直推返佣',  //intromoney +
+        102 => '间推返佣',  //intromoney +
 
         121 => '钱包余额提现',//intromoney -
         122 => '提现拒绝返回',//intromoney +