afa 5 сар өмнө
parent
commit
c119bb1c67

+ 1 - 1
application/api/controller/Order.php

@@ -215,7 +215,7 @@ class Order extends Api
                 //等级分佣
                 if($this->auth->team_level_id > 0){
                     list($inc, $asset, $action) = CommonLogic::getFrozenIsChabao($token, $frozen); //
-                    CommonLogic::setTeamLevelIncome($this->auth->id, $inc, $this->auth->team_level_id, $asset, $action);
+                    CommonLogic::setTeamLevelIncome($this->auth->id, $inc, $asset, $action);
                 }
             }
         

+ 1 - 1
application/api/controller/Pledge.php

@@ -143,7 +143,7 @@ class Pledge extends Api
             Db::startTrans();
             try {
                   // 质抵押订单
-                  $res = $pledgeLogic::getPledgeCollect($this->auth->id, $this->auth->team_level_id);
+                  $res = $pledgeLogic::getPledgeCollect($this->auth->id);
 
                   //请求限制      
                   cache('collect_'.$this->auth->id, time(), 300);

+ 2 - 3
application/api/controller/Teac.php

@@ -130,8 +130,7 @@ class Teac extends Api
             $teacLogin::setCreateSellOrder($this->auth->id, $row['user_id'], $row['price'], $params['num'], $fee);
 
             //等级分润
-            $teamLeavel = $userModel::getTeamLevelId($row['user_id']);
-            if($teamLeavel > 0) CommonLogic::setTeamLevelIncome($row['user_id'], $fees, $teamLeavel, Asset::TEAC, LedgerTeacChangeModel::TeamLevel);
+            CommonLogic::setTeamLevelIncome($row['user_id'], $fees, Asset::TEAC, LedgerTeacChangeModel::TeamLevel);
 
             //修改状态
             if($row->stock - $row->num == $params['num']) $row->status = ProductTeac::Complete;
@@ -170,7 +169,7 @@ class Teac extends Api
             $userTeac::setUserCreateOrder($this->auth->id, $row['id'], ProductTeac::Buying, $params['num'], $row['price'],  $fee);
 
             //添加扣除相应茶宝Teac
-            $teacLogin::setCreateBuyingOrder($this->auth->id, $this->auth->team_level_id, $row['user_id'], $row['price'], $params['num'], $fee);
+            $teacLogin::setCreateBuyingOrder($this->auth->id,  $row['user_id'], $row['price'], $params['num'], $fee);
             
             //修改状态
             if($row->stock - $row->num == $params['num']) $row->status = ProductTeac::Complete;

+ 24 - 10
application/api/logic/CommonLogic.php

@@ -114,19 +114,33 @@ class CommonLogic
 
 
       //发放层级收益
-      public static function setTeamLevelIncome(int $user_id, float $num, int $team_level_id, string $asset, string $action)
+      public static function setTeamLevelIncome(int $user_id, float $num,string $asset, string $action)
       {     
-            $config = config('team_level_where');
-            $team_level_id = $team_level_id - 1;
-            $paths  = UserPathModel::where('user_id', $user_id)->where('distance', '<=', $config[$team_level_id]['level'])->order('distance', 'asc')->column('parent_id');
             $income = bcmul($num, config('team_level_inc'), 2); //收益
-            if(count($paths) > 0 && $income > 0){
-                  //余额记录
-                  foreach($paths as $pathId){
-                        if(!empty(Loader::model('UserModel')::getTeamLevelId($pathId))) {
-                              Loader::model('LedgerWalletModel')->changeWalletAccount($pathId, $asset, $income, $action, $user_id);
-                        }
+            $parents_info = UserPathModel::where('p.user_id', $user_id)
+                  ->alias('p')
+                  ->join('user u', 'u.id = p.parent_id', 'left')
+                  ->field('u.id, u.address_level, u.team_level_id,u.parent_id, p.distance')
+                  ->where('u.team_level_id', '>', 0)
+                  ->order('p.distance asc')
+                  ->select();
+            if(empty($parents_info) || empty($income)) return true;
+      
+            //分享 1 个拿 3 层,分享 2 个拿 7 层
+            foreach ($parents_info as $parent){
+                  $send_user_id = 0;  //需要发放的会员ID列表
+                  if($parent['team_level_id'] >= 1 && $parent['distance'] <= 3){
+                        $send_user_id = $parent['id'];
+                  }else if($parent['team_level_id'] >= 2 && $parent['distance'] <= 7){
+                        $send_user_id = $parent['id'];
+                  }else if($parent['team_level_id'] >= 3 && $parent['distance'] <= 13){
+                        $send_user_id = $parent['id'];
+                  }else if($parent['team_level_id'] >= 4 && $parent['distance'] <= 21){
+                        $send_user_id = $parent['id'];
+                  }else if($parent['team_level_id'] >= 5 && $parent['distance'] <= 31){
+                        $send_user_id = $parent['id'];
                   }
+                  if($send_user_id > 0)  Loader::model('LedgerWalletModel')->changeWalletAccount($send_user_id, $asset, $income, $action, $user_id);
             }
             return true;
       }

+ 1 - 2
application/api/logic/OrderLogic.php

@@ -101,8 +101,7 @@ class OrderLogic
                         $userModel::updateForRwaNum($uid, $puid, 1, '+');
                   }
                   //等级分佣
-                  $teamLevel    = $userModel::getTeamLevelId($item->user_id);
-                  if($teamLevel > 0) CommonLogic::setTeamLevelIncome($item->user_id, $item->fees, $teamLevel, Asset::TOKEN, $ledgerTokenChangeModel::TeamLevel);
+                  CommonLogic::setTeamLevelIncome($item->user_id, $item->fees, Asset::TOKEN, $ledgerTokenChangeModel::TeamLevel);
                   //修改原订单状态
                   $popular_order->status=$productOrder::Closure;
                   $popular_order->save();

+ 2 - 2
application/api/logic/PledgeLogic.php

@@ -151,7 +151,7 @@ class PledgeLogic
 
     
     //收取质抵押订单列表:(60*60*24)*(当前时间-最后一次收取时间)
-    public static function getPledgeCollect(int $user_id, int $team_level_id)
+    public static function getPledgeCollect(int $user_id)
 
     {   
         $model  = Loader::model('UserPledge');
@@ -185,7 +185,7 @@ class PledgeLogic
         }
 
         //等级分佣
-        if($team_level_id > 0) CommonLogic::setTeamLevelIncome($user_id, $total, $team_level_id, Asset::TEAC, LedgerTeacChangeModel::TeamLevel);
+        CommonLogic::setTeamLevelIncome($user_id, $total, Asset::TEAC, LedgerTeacChangeModel::TeamLevel);
 
         //更新用户资产
         return Loader::model('LedgerWalletModel')->changeWalletAccount($user_id, Asset::TEAC, $total, LedgerTeacChangeModel::Pledge, 0);  

+ 2 - 2
application/api/logic/TeacLogin.php

@@ -76,7 +76,7 @@ class TeacLogin
      * @$uid  用户人id
      * @$fromUid  来源订单id
      */
-    public static function setCreateBuyingOrder(int $uid, int $team_level_id, int $fromUid, float $chabao, int $num, float $fee)
+    public static function setCreateBuyingOrder(int $uid,  int $fromUid, float $chabao, int $num, float $fee)
     {
 
         $ledgerWalletModel = Loader::model('LedgerWalletModel');
@@ -94,7 +94,7 @@ class TeacLogin
         $ledgerWalletModel->changeWalletAccount($fromUid, Asset::TEAC, $num, LedgerTeacChangeModel::Buying, $uid);
 
         //添加分润等级    
-        if($team_level_id > 0) CommonLogic::setTeamLevelIncome($uid, $fee, $team_level_id, Asset::TOKEN, LedgerTokenChangeModel::TeamLevel);
+        CommonLogic::setTeamLevelIncome($uid, $fee, Asset::TOKEN, LedgerTokenChangeModel::TeamLevel);
 
         return true;
     }