修改经销商升级规则
parent
897683dc22
commit
373c0bc068
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue