瀏覽代碼

质抵押订单

afa 5 月之前
父節點
當前提交
36a726d0a7
共有 3 個文件被更改,包括 65 次插入19 次删除
  1. 2 2
      application/api/controller/Pledge.php
  2. 61 15
      application/api/logic/CommonLogic.php
  3. 2 2
      application/api/logic/PledgeLogic.php

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

@@ -103,7 +103,7 @@ class Pledge extends Api
             $res = $pledgeLogic::setPledgeOrder($pledge, $order_id, $this->auth->id, $count, $this->pay[$pay_type], $pledge[$this->pay[$pay_type]]);
 
             //组合质押
-            if($pledge->type_id == 2) CommonLogic::setIsLevelSave($this->auth->id, $this->auth->team_level_id, $this->auth->address_level, 1);
+            if($pledge->type_id == 2) CommonLogic::setIsUpLevel($this->auth->id, $this->auth->team_level_id, $this->auth->address_level, $this->auth->parent_id);
             // 提交事务
             Db::commit();
         } catch (Exception $e) {
@@ -168,7 +168,7 @@ class Pledge extends Api
             Db::startTrans();
             try {
                   // 质抵押订单 
-                  $res = $pledgeLogic::setPledgeRemove($pledge_id, $order_id, $this->auth->id, $this->auth->team_level_id, $this->auth->address_level);
+                  $res = $pledgeLogic::setPledgeRemove($pledge_id, $order_id, $this->auth->id, $this->auth->team_level_id, $this->auth->address_level, $this->auth->parent_id);
 
                   // 提交事务
                   Db::commit();

+ 61 - 15
application/api/logic/CommonLogic.php

@@ -16,8 +16,8 @@ use app\common\model\LedgerFrozenChangeModel;
 class CommonLogic
 {
 
-      // 升级降级
-      public static function setIsLevelSave(int $user_id, int $team_level_id, int $address_level, int $num): bool
+      // 升级
+      public static function setIsUpLevel(int $user_id, int $team_level_id, int $address_level, int $parent_id): bool
       {
             $config = config('team_level_where');
             if($team_level_id == count($config)) return false;
@@ -26,35 +26,81 @@ class CommonLogic
                   if($address_level >= $config[$team_level_id]['direct']) {
                         $result = true;
                         $team_level_id += 1;
+                        self::setIsUpLevelParent($parent_id, $config);
+                  }
+            }else{
+                  //组合套数
+                  $groupCount = UserPledge::getPledgeCount($user_id) + 1;
+                  //直推
+                  $teamCount = UserModel::where('parent_id', $user_id)->where('team_level_id', $team_level_id)->count();
+                  if($teamCount >= $config[$team_level_id]['direct'] && $groupCount >= $config[$team_level_id]['num']){
+                        $result = true;
+                        $team_level_id += 1; //+1
+                        self::setIsUpLevelParent($parent_id, $config);
                   }
             }
+            return $result? UserModel::where('id', $user_id)->update(['team_level_id'=> $team_level_id]): false;
+      }
 
+      //上级升级
+      public static function setIsUpLevelParent(int $parent_id, array $config){
+            $parent = UserModel::where('id', $parent_id)->find();
+            if($parent->team_level_id > 0){
+                  //推广人数
+                  $teamCount = UserModel::where('parent_id', $parent_id)->where('team_level_id', $parent->team_level_id)->count() +1;
+                  //组合套数
+                  $groupCount = UserPledge::getPledgeCount($parent_id);
+                  if($teamCount >= $config[$parent->team_level_id]['direct'] && $groupCount >= $config[$parent->team_level_id]['num']){
+                        $parent->team_level_id +=1;
+                        $parent->save();
+                  }
+            }
+      }
+
+
+      //降级
+      public static  function setIsOuLevelSave($user_id,  $team_level_id, $address_level, $parent_id)
+      {
+            $config = config('team_level_where');
+            $result = false;
             //组合套数
-            $groupCount = UserPledge::getPledgeCount($user_id) + $num;
+            $groupCount = UserPledge::getPledgeCount($user_id) -1 ;
             if($team_level_id == 1 && ($groupCount == 0 || $address_level < $config[0]['direct'])){
                   $result = true;
                   $team_level_id = 0;
+                  self::setIsUpLevelParent($parent_id, $config);
             }
-            //大于1
+
             if($team_level_id > 1){
                   //直推
                   $teamCount = UserModel::where('parent_id', $user_id)->where('team_level_id', $team_level_id)->count();
-                  if($teamCount >= $config[$team_level_id]['direct'] && $groupCount >= $config[$team_level_id]['num']){
+                  if($teamCount < $config[$team_level_id]['direct'] && $groupCount < $config[$team_level_id]['num']){
                         $result = true;
-                        $team_level_id += 1; //+1
-                  }else{
-                        $result = true;
-                        $team_level_id -=1; //-1
+                        $team_level_id -= 1;
+                        self::setIsUpLevelParent($parent_id, $config);
                   }
             }
-                  
-            
             return $result? UserModel::where('id', $user_id)->update(['team_level_id'=> $team_level_id]): false;
       }
 
+      //上级降低级
+      public static function setIsOuLevelParent(int $parent_id, array $config){
+            $parent = UserModel::where('id', $parent_id)->find();
+            if($parent->team_level_id > 0){
+                  //推广人数
+                  $teamCount = UserModel::where('parent_id', $parent_id)->where('team_level_id', $parent->team_level_id)->count() +1;
+                  //组合套数
+                  $groupCount = UserPledge::getPledgeCount($parent_id);
+                  if($teamCount < $config[$parent->team_level_id]['direct'] && $groupCount >= $config[$parent->team_level_id]['num']){
+                        $parent->team_level_id -=1;
+                        $parent->save();
+                  }
+            }
+      }
+
+
 
 
-   
       //发放层级收益
       public static function setTeamLevelIncome(int $user_id, float $num, int $team_level_id, string $asset, string $action)
       {     
@@ -73,10 +119,8 @@ class CommonLogic
             return true;
       }
 
-
       //判断发放茶宝数量
-      public static function getFrozenIsChabao($token, $frozen)
-      {     
+      public static function getFrozenIsChabao($token, $frozen){     
             //标记茶宝
             if(bccomp(bcmul($frozen, config('team_level_inc'), 6) , 0.0001, 6) == -1)
             {
@@ -87,4 +131,6 @@ class CommonLogic
             }
       }
 
+      
+
 }

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

@@ -102,7 +102,7 @@ class PledgeLogic
     }
 
     //解除质抵押订单
-    public static function setPledgeRemove(int $pledge_id, string $order_id, int $user_id, $team_level_id, $address_level)
+    public static function setPledgeRemove(int $pledge_id, string $order_id, int $user_id, $team_level_id, $address_level, $parent_id)
     {
         $model  = Loader::model('UserPledge');
         $time  = time();
@@ -142,7 +142,7 @@ class PledgeLogic
         Loader::model('ProductOrder')::where('user_id', $user_id)->whereIn('id', $orderId)->setField('status', ProductOrder::Paid);
 
         //
-        if($rows->type_id == 2) CommonLogic::setIsLevelSave($user_id, $team_level_id, $address_level, -1);
+        if($rows->type_id == 2) CommonLogic::setIsOuLevelSave($user_id, $team_level_id, $address_level, $parent_id);
         //更新领取状态
         $rows->last_time = $time;
         return  $rows->save();