diff --git a/app/Services/DistributeService.php b/app/Services/DistributeService.php index a0fe4228..007a5073 100644 --- a/app/Services/DistributeService.php +++ b/app/Services/DistributeService.php @@ -41,20 +41,23 @@ class DistributeService 'change_sales_value' => $sales_value ]); $user->userInfo()->increment('growth_value', $sales_value); - // 自动升级代理 - $levels = Agent::where('slug', Agent::TYPE_FAVOITE)->orderBy('sort')->get(); - $level_up = ''; - foreach($levels->reverse() as $item) { - if ($user->userInfo->growth_value >= $item->growth_value) { - $level_up = $item; + + if ($user_agent->type === Agent::TYPE_FAVOITE) { + // 自动升级代理 + $levels = Agent::where('slug', Agent::TYPE_FAVOITE)->orderBy('sort')->get(); + $level_up = ''; + foreach($levels->reverse() as $item) { + if ($user->userInfo->growth_value >= $item->growth_value) { + $level_up = $item; + } + } + // 如果当前等级, 比升级之后的要高, 则不升级 + if ($level_up && (!$user_agent || $level_up->sort < $user_agent->sort)) { + $user->update([ + 'agent_id' => $level_up->id, + ]); + $user_agent = $level_up; } - } - // 如果当前等级, 比升级之后的要高, 则不升级 - if ($level_up && (!$user_agent || $level_up->sort < $user_agent->sort)) { - $user->update([ - 'agent_id' => $level_up->id, - ]); - $user_agent = $level_up; } // 上级返利