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] =?UTF-8?q?=E5=88=86=E9=85=8D=E7=A6=BB=E8=81=8C=E5=91=98?= =?UTF-8?q?=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