From 646b39dec8eb2fa54a7de10703cf90a100ef21fc Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Thu, 14 Aug 2025 20:59:20 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=AE=A1=E6=A0=B8=E5=8E=9F=E5=9B=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/model/CustomerAudit.php | 49 +++++++++++++++++++ app/crm/controller/CustomerController.php | 3 ++ app/crm/service/CustomerService.php | 8 +++ .../controller/CustomerController.php | 2 +- app/crmAdmin/service/CustomerService.php | 2 + 5 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 app/common/model/CustomerAudit.php diff --git a/app/common/model/CustomerAudit.php b/app/common/model/CustomerAudit.php new file mode 100644 index 0000000..4e52267 --- /dev/null +++ b/app/common/model/CustomerAudit.php @@ -0,0 +1,49 @@ +error(trans('id_empty')); } + if (Util::isEmpty($param['remark'])) { + return $this->error('举报理由不能为空'); + } $param['user_id'] = $request->user->uid; $param['corp_abbr'] = $request->basic_data['corp_abbr']; diff --git a/app/crm/service/CustomerService.php b/app/crm/service/CustomerService.php index 0573972..3baa4ae 100644 --- a/app/crm/service/CustomerService.php +++ b/app/crm/service/CustomerService.php @@ -3,6 +3,7 @@ namespace app\crm\service; use app\common\model\Corp; +use app\common\model\CustomerAudit; use app\common\model\User; use app\common\traits\crud\CrudServiceTrait; use app\crm\logic\CustomerLogic; @@ -195,6 +196,13 @@ class CustomerService return false; } + CustomerAudit::create([ + 'customer_id' => $id, + 'report_user_id' => $userId, + 'remark' => $params['remark'], + 'img' => implode(',', $params['img']), + ]); + CustomerHis::create([ 'customer_id' => $id, 'user_his' => $userId, diff --git a/app/crmAdmin/controller/CustomerController.php b/app/crmAdmin/controller/CustomerController.php index a3dc0e2..a214a2c 100644 --- a/app/crmAdmin/controller/CustomerController.php +++ b/app/crmAdmin/controller/CustomerController.php @@ -85,7 +85,7 @@ class CustomerController extends BaseController } /** - * 客户列表 + * 审核客户 * @param Request $request * @return \support\Response */ diff --git a/app/crmAdmin/service/CustomerService.php b/app/crmAdmin/service/CustomerService.php index 074f341..09faa5a 100644 --- a/app/crmAdmin/service/CustomerService.php +++ b/app/crmAdmin/service/CustomerService.php @@ -2,6 +2,7 @@ namespace app\crmAdmin\service; +use app\common\model\CustomerAudit; use app\common\model\InquiryLog; use app\common\model\User; use app\common\service\OssService; @@ -139,6 +140,7 @@ class CustomerService if ($scene == 'audit') { //审核时查询举报人姓名 $customerHis = CustomerHis::where('customer_id', $item->id)->orderBy('id', 'desc')->first(['user_his']); $item['user_name'] = empty($customerHis['user_his']) ? '' : User::where('id',$customerHis['user_his'])->value('name'); + $item['audit'] = CustomerAudit::where('customer_id', $item->id)->orderBy('id', 'desc')->first(['user_his']); } } } From 1fa2342007fdb7f009d5041b408dff3bee97a645 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Sat, 16 Aug 2025 16:12:06 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=88=86=E9=85=8D=E7=A6=BB=E8=81=8C?= =?UTF-8?q?=E5=91=98=E5=B7=A5=E5=AE=A2=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/CustomerController.php | 27 ++++++++++ app/crmAdmin/service/CustomerService.php | 51 +++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/app/crmAdmin/controller/CustomerController.php b/app/crmAdmin/controller/CustomerController.php index a214a2c..c6279e7 100644 --- a/app/crmAdmin/controller/CustomerController.php +++ b/app/crmAdmin/controller/CustomerController.php @@ -207,4 +207,31 @@ class CustomerController extends BaseController } } + /** + * 离职员工客户分配 + * @param Request $request + * @return \support\Response + */ + public function allocation(Request $request) + { + 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')); + } + if (empty($param['user_id'])) { + return $this->error('user_id'.trans('not_null')); + } + + $result = (new CustomerService())->allocation($param); + + return $this->success($result); + } catch (\Throwable $th) { + return $this->error($th->getMessage()); + } + } + } \ No newline at end of file diff --git a/app/crmAdmin/service/CustomerService.php b/app/crmAdmin/service/CustomerService.php index 09faa5a..256451b 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\Log; class CustomerService { @@ -454,4 +455,54 @@ class CustomerService return $follow; } + + /** + * 离职员工客户分配 + * @param $params + * @return Follow[]|\Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Collection[] + */ + public function allocation($params) + { + $id = $params['id']; + $corpId = $params['corp_id']; + $userId = $params['user_id']; + + log::info('开始分配离职员工客户,corp_id:'.$corpId.' 被分配员工'. implode(',', $userId)); + + //查询离职客户 + $userResign = User::where('status', 2) + ->where('corp_id', $corpId) + ->get(['id','name']); + + $resignUerIds = []; + $userNames = []; + foreach ($userResign as $row) { + $resignUerIds[] = (int)$row->id; + $userNames[] = $row->name; + } + if (empty($userIds)) { + log::info('匹配到离职用户数:' . count($resignUerIds) .' '. implode(',',$userNames)); + } + + $customers = Customer::whereIn('user_id', $resignUerIds) + ->orderBy('id', 'asc') + ->get(['id','user_id']); + + if (!$customers || count($customers) === 0) { + $output->writeln('未找到相关的 crm_customer 记录。'); + log::info('未找到相关的离职员工客户记录。' ; + return []; + } + + $follow = Follow:: + where('customer_id', $id) + ->get(); + + $ossservice = new OssService(); + foreach ($follow as $item) { + $item['picture_full'] = empty($item->picture)?'':$ossservice->generatePrivateUrl($item->picture); + } + + return $follow; + } } \ No newline at end of file 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 3/4] =?UTF-8?q?=E7=A6=BB=E8=81=8C=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E5=88=86=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']); }); }); }); 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 4/4] =?UTF-8?q?=E5=88=86=E9=85=8D=E7=A6=BB=E8=81=8C?= =?UTF-8?q?=E5=AE=A2=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