From 7aa717b93e8697a1645bbe4ac373551d7cb4811a Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Mon, 18 Aug 2025 15:14:30 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A6=BB=E8=81=8C=E5=AE=A2=E6=88=B7=E5=88=86?= =?UTF-8?q?=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/CustomerController.php | 2 +- app/crmAdmin/service/CustomerService.php | 36 +++++++++++-------- config/route.php | 1 + 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/app/crmAdmin/controller/CustomerController.php b/app/crmAdmin/controller/CustomerController.php index c6279e7..2584003 100644 --- a/app/crmAdmin/controller/CustomerController.php +++ b/app/crmAdmin/controller/CustomerController.php @@ -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()); } diff --git a/app/crmAdmin/service/CustomerService.php b/app/crmAdmin/service/CustomerService.php index 256451b..757a2a2 100644 --- a/app/crmAdmin/service/CustomerService.php +++ b/app/crmAdmin/service/CustomerService.php @@ -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('未找到相关的 crm_customer 记录。'); - 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; } } \ No newline at end of file diff --git a/config/route.php b/config/route.php index 9c33c32..e4702a3 100644 --- a/config/route.php +++ b/config/route.php @@ -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']); }); }); });