离职客户分配
This commit is contained in:
@@ -228,7 +228,7 @@ class CustomerController extends BaseController
|
||||
|
||||
$result = (new CustomerService())->allocation($param);
|
||||
|
||||
return $this->success($result);
|
||||
return $this->success();
|
||||
} catch (\Throwable $th) {
|
||||
return $this->error($th->getMessage());
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Border;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Fill;
|
||||
use support\Db;
|
||||
use support\exception\BusinessException;
|
||||
use support\Log;
|
||||
|
||||
class CustomerService
|
||||
@@ -481,28 +482,33 @@ class CustomerService
|
||||
$userNames[] = $row->name;
|
||||
}
|
||||
if (empty($userIds)) {
|
||||
log::info('匹配到离职用户数:' . count($resignUerIds) .' '. implode(',',$userNames));
|
||||
log::info('未匹配到离职用户');
|
||||
throw new BusinessException('未找到离职员工相关的客户记录', 500);
|
||||
}
|
||||
log::info('匹配到离职用户数:' . count($resignUerIds) .' '. implode(',',$userNames));
|
||||
|
||||
$customers = Customer::whereIn('user_id', $resignUerIds)
|
||||
$customerCount = Customer::whereIn('user_id', $resignUerIds)
|
||||
->orderBy('id', 'asc')
|
||||
->get(['id','user_id']);
|
||||
->count();
|
||||
|
||||
if (!$customers || count($customers) === 0) {
|
||||
$output->writeln('<comment>未找到相关的 crm_customer 记录。</comment>');
|
||||
log::info('未找到相关的离职员工客户记录。' ;
|
||||
return [];
|
||||
if ($customerCount === 0) {
|
||||
log::info('未找到离职员工相关的客户记录。');
|
||||
throw new BusinessException('未找到离职员工相关的客户记录', 500);
|
||||
}
|
||||
|
||||
$follow = Follow::
|
||||
where('customer_id', $id)
|
||||
->get();
|
||||
// 初始化 UID 轮询器
|
||||
$uidRotator = new \app\common\utils\RedisUidRotator('allocation_customer_user');
|
||||
$uidRotator->setUids($params, false);
|
||||
|
||||
$ossservice = new OssService();
|
||||
foreach ($follow as $item) {
|
||||
$item['picture_full'] = empty($item->picture)?'':$ossservice->generatePrivateUrl($item->picture);
|
||||
}
|
||||
Customer::chunk(200, function ($customers, $uidRotator) {
|
||||
foreach ($customers as $customer) {
|
||||
// 获取下一个分配的UID
|
||||
$newUserId = $uidRotator->next();
|
||||
$customer->user_id = $newUserId;
|
||||
}
|
||||
});
|
||||
|
||||
return $follow;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -159,6 +159,7 @@ Route::group('/admin', function () {
|
||||
Route::any('/delete', [app\crmAdmin\controller\CustomerController::class, 'delete']);
|
||||
Route::any('/cede', [app\crm\controller\CustomerController::class, 'cede']);
|
||||
Route::any('/follow', [app\crmAdmin\controller\CustomerController::class, 'follow']);
|
||||
Route::any('/allocation', [app\crmAdmin\controller\CustomerController::class, 'allocation']);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user