6
0
Fork 0

修改经销商升级规则

release
李静 2022-01-26 16:19:27 +08:00
parent 897683dc22
commit 373c0bc068
1 changed files with 19 additions and 17 deletions

View File

@ -215,7 +215,7 @@ class Dealer extends Model
} }
/** /**
* 获取不同线上的非直属签约经销商人数(每条线上最多算一个) * 获取非直属的签约经销商数量
* *
* @return int * @return int
*/ */
@ -223,9 +223,23 @@ class Dealer extends Model
{ {
$path = $this->userInfo->full_path; $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}%"); $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'); $dealers->load('userInfo:user_id,path');
@ -244,18 +258,6 @@ class Dealer extends Model
return count($lines); 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; $lvl = DealerLvl::Top;
if ($remark !== '') { if ($remark !== '') {
$remark .= ';'; $remark .= ';';
} }
$remark .= '有4个直推二级'; $remark .= '有4个二级经销商';
} }
$this->upgrade($lvl, $remark); $this->upgrade($lvl, $remark);