分配离职客户
This commit is contained in:
@@ -460,13 +460,12 @@ class CustomerService
|
||||
/**
|
||||
* 离职员工客户分配
|
||||
* @param $params
|
||||
* @return Follow[]|\Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Collection[]
|
||||
* @return string[]
|
||||
*/
|
||||
public function allocation($params)
|
||||
{
|
||||
$id = $params['id'];
|
||||
$corpId = $params['corp_id'];
|
||||
$userId = $params['user_id'];
|
||||
$userId = explode(',', $params['user_id']);
|
||||
|
||||
log::info('开始分配离职员工客户,corp_id:'.$corpId.' 被分配员工'. implode(',', $userId));
|
||||
|
||||
@@ -481,9 +480,9 @@ class CustomerService
|
||||
$resignUerIds[] = (int)$row->id;
|
||||
$userNames[] = $row->name;
|
||||
}
|
||||
if (empty($userIds)) {
|
||||
if (empty($userResign)) {
|
||||
log::info('未匹配到离职用户');
|
||||
throw new BusinessException('未找到离职员工相关的客户记录', 500);
|
||||
throw new BusinessException('未匹配到离职用户', 500);
|
||||
}
|
||||
log::info('匹配到离职用户数:' . count($resignUerIds) .' '. implode(',',$userNames));
|
||||
|
||||
@@ -498,17 +497,21 @@ class CustomerService
|
||||
|
||||
// 初始化 UID 轮询器
|
||||
$uidRotator = new \app\common\utils\RedisUidRotator('allocation_customer_user');
|
||||
$uidRotator->setUids($params, false);
|
||||
$uidRotator->setUids($userId, false);
|
||||
|
||||
Customer::chunk(200, function ($customers, $uidRotator) {
|
||||
Customer::whereIn('user_id',$resignUerIds)->chunk(500, function ($customers) use ($uidRotator){
|
||||
foreach ($customers as $customer) {
|
||||
// 获取下一个分配的UID
|
||||
$newUserId = $uidRotator->next();
|
||||
$customer->user_id = $newUserId;
|
||||
$customer->save();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return true;
|
||||
return [
|
||||
'userCount' => count($resignUerIds),
|
||||
'customerCount' => $customerCount,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user