From 3ba830259a0b9312617a16e7829032a97df1f09c Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Mon, 18 Aug 2025 16:54:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E9=85=8D=E7=A6=BB=E8=81=8C=E5=AE=A2?= =?UTF-8?q?=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/CustomerController.php | 5 +---- app/crmAdmin/service/CustomerService.php | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/crmAdmin/controller/CustomerController.php b/app/crmAdmin/controller/CustomerController.php index 2584003..2f3ba2e 100644 --- a/app/crmAdmin/controller/CustomerController.php +++ b/app/crmAdmin/controller/CustomerController.php @@ -216,9 +216,6 @@ class CustomerController extends BaseController { try { $param = $request->all(); - if (empty($param['id'])) { - return $this->error('id'.trans('not_null')); - } if (empty($param['corp_id'])) { return $this->error('corp_id'.trans('not_null')); } @@ -228,7 +225,7 @@ class CustomerController extends BaseController $result = (new CustomerService())->allocation($param); - return $this->success(); + return $this->success($result,'成功分配'.$result['userCount'].'位离职用户的'.$result['customerCount'].'位客户'); } catch (\Throwable $th) { return $this->error($th->getMessage()); } diff --git a/app/crmAdmin/service/CustomerService.php b/app/crmAdmin/service/CustomerService.php index 757a2a2..7357efb 100644 --- a/app/crmAdmin/service/CustomerService.php +++ b/app/crmAdmin/service/CustomerService.php @@ -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, + ]; } } \ No newline at end of file