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