From 373c0bc06823219b48c05b917f3a91bc88c762c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Wed, 26 Jan 2022 16:19:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BB=8F=E9=94=80=E5=95=86?= =?UTF-8?q?=E5=8D=87=E7=BA=A7=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/Dealer.php | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/app/Models/Dealer.php b/app/Models/Dealer.php index 32ed186a..a20f67f7 100644 --- a/app/Models/Dealer.php +++ b/app/Models/Dealer.php @@ -215,7 +215,7 @@ class Dealer extends Model } /** - * 获取不同线上的非直属签约经销商人数(每条线上最多算一个) + * 获取非直属的签约经销商数量 * * @return int */ @@ -223,9 +223,23 @@ class Dealer extends Model { $path = $this->userInfo->full_path; - $dealers = static::whereHas('userInfo', function ($query) use ($path) { + return static::whereHas('userInfo', function ($query) use ($path) { $query->where('inviter_id', '!=', $this->user_id)->where('path', 'like', "{$path}%"); - })->where('lvl', '>=', DealerLvl::Contracted)->get(); + })->where('lvl', '>=', DealerLvl::Contracted)->count(); + } + + /** + * 获取直属的二级经销商数量 + * + * @return int + */ + public function getSecondaryDealersCountOnDifferentLines(): int + { + $path = $this->userInfo->full_path; + + $dealers = static::whereHas('userInfo', function ($query) use ($path) { + $query->where('path', 'like', "{$path}%"); + })->where('lvl', '>=', DealerLvl::Secondary)->get(); $dealers->load('userInfo:user_id,path'); @@ -244,18 +258,6 @@ class Dealer extends Model return count($lines); } - /** - * 获取直属的二级经销商数量 - * - * @return int - */ - public function getDirectSecondaryDealersCount(): int - { - return static::whereHas('userInfo', function ($query) { - $query->where('inviter_id', $this->user_id); - })->where('lvl', '>=', DealerLvl::Secondary)->count(); - } - /** * 尝试升级 * @@ -319,14 +321,14 @@ class Dealer extends Model } } - if ($lvl === DealerLvl::Secondary && $this->getDirectSecondaryDealersCount() >= 4) { + if ($lvl === DealerLvl::Secondary && $this->getSecondaryDealersCountOnDifferentLines() >= 4) { $lvl = DealerLvl::Top; if ($remark !== '') { $remark .= ';'; } - $remark .= '有4个直推二级'; + $remark .= '有4个二级经销商'; } $this->upgrade($lvl, $remark);