调整分配订单
parent
36a44f9ef6
commit
5077e2969f
|
|
@ -327,18 +327,43 @@ class OrderService
|
||||||
if ($lvl->value >= DealerLvl::Contracted->value) {
|
if ($lvl->value >= DealerLvl::Contracted->value) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$query = UserInfo::with('dealer');
|
// //老逻辑;
|
||||||
if ($lastConsignor) {
|
// $query = UserInfo::with('dealer');
|
||||||
$query->whereIn('user_id', $lastConsignor->userInfo->real_parent_ids);//上个发货人的上级
|
// if ($lastConsignor) {
|
||||||
} else {
|
// $query->whereIn('user_id', $lastConsignor->userInfo->real_parent_ids);//上个发货人的上级
|
||||||
$query->whereIn('user_id', $user->userInfo->real_parent_ids);//自己的上级
|
// } else {
|
||||||
}
|
// $query->whereIn('user_id', $user->userInfo->real_parent_ids);//自己的上级
|
||||||
$consignor = $query->whereHas('dealer', function ($q) use ($lvl) {
|
// }
|
||||||
return $q->where('is_sale', true)->where('lvl', '>', $lvl);//可销售的经销商,且身份大于自己的
|
// $consignor = $query->whereHas('dealer', function ($q) use ($lvl) {
|
||||||
})->orderBy('depth', 'desc')->first();//深度逆序第一个
|
// return $q->where('is_sale', true)->where('lvl', '>', $lvl);//可销售的经销商,且身份大于自己的
|
||||||
if (!$consignor) {
|
// })->orderBy('depth', 'desc')->first();//深度逆序第一个
|
||||||
$consignor = $lastConsignor;
|
// if (!$consignor) {
|
||||||
}
|
// $consignor = $lastConsignor;
|
||||||
return $consignor;
|
// }
|
||||||
|
//新逻辑
|
||||||
|
$consignor = null;
|
||||||
|
$_lastConsignor = $lastConsignor;
|
||||||
|
do {
|
||||||
|
$query = User::with(['userInfo', 'dealer']);
|
||||||
|
if ($_lastConsignor) {
|
||||||
|
$query->where('id', $_lastConsignor->userInfo->real_inviter_id);
|
||||||
|
} else {
|
||||||
|
$query->where('id', $user->userInfo->real_inviter_id);
|
||||||
|
}
|
||||||
|
$consignor = $query->first();
|
||||||
|
if ($consignor) {//找到老上级
|
||||||
|
if ($consignor->dealer->is_sale == true && $consignor->dealer->lvl->value > $lvl->value) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
$_lastConsignor = $consignor;
|
||||||
|
$consignor = null;
|
||||||
|
}
|
||||||
|
} else {//如果找不到人了
|
||||||
|
$consignor = $lastConsignor;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while (empty($consignor));
|
||||||
|
|
||||||
|
return $consignor?->userInfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue