From a8d7e98eb87719a32752d6b7dadc915926901a3c Mon Sep 17 00:00:00 2001 From: panliang <1163816051@qq.com> Date: Thu, 2 Jun 2022 17:31:12 +0800 Subject: [PATCH] w --- app/Services/DistributeService.php | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) 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; } // 上级返利