From 9e7c8e7d5efba4003ed08050f21bd4513cc81e14 Mon Sep 17 00:00:00 2001 From: wangzeyan <258785420@qq.com> Date: Wed, 25 Jun 2025 11:10:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=8E=B7=E5=8F=96=E8=B5=84?= =?UTF-8?q?=E6=BA=90=E5=88=97=E8=A1=A8=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apiController/ResourceSharing.php | 26 ----- niucloud/app/api/route/route.php | 2 +- .../api/apiService/ResourceSharingService.php | 97 +------------------ 3 files changed, 2 insertions(+), 123 deletions(-) diff --git a/niucloud/app/api/controller/apiController/ResourceSharing.php b/niucloud/app/api/controller/apiController/ResourceSharing.php index a35f400a..4fcdc809 100644 --- a/niucloud/app/api/controller/apiController/ResourceSharing.php +++ b/niucloud/app/api/controller/apiController/ResourceSharing.php @@ -51,32 +51,6 @@ class ResourceSharing extends BaseApiService $res= (new ResourceSharingService())->getList($where); return success($res); } - public function index1(Request $request) - { - $shared_by = $request->param('shared_by','');//共享人ID - $name = $request->param('name','');////客户资源表-姓名 - $phone_number = $request->param('phone_number','');//客户资源表-手机号 - $campus_name = $request->param('campus_name','');//客户资源表-校区 - - $shared_at_str = $request->param('shared_at_str','');//共享时间|[开始时间(Y-m-d),结束时间(Y-m-d)] - $shared_at_arr = []; - if(!empty($shared_at_str)){ - $shared_at_arr = explode(' ~ ',$shared_at_str); - $shared_at_arr[0] = "{$shared_at_arr[0]} 00:00:00"; - $shared_at_arr[1] = "{$shared_at_arr[1]} 23:59:59"; - } - - $where = [ - 'shared_by'=>$shared_by, - 'shared_at_arr'=>$shared_at_arr, - 'name'=>$name, - 'phone_number'=>$phone_number, - 'campus_name' => $campus_name - ]; - - $res= (new ResourceSharingService())->getList1($where); - return success($res); - } //资源共享-详情 public function info(Request $request) { diff --git a/niucloud/app/api/route/route.php b/niucloud/app/api/route/route.php index afa939e8..3714133a 100644 --- a/niucloud/app/api/route/route.php +++ b/niucloud/app/api/route/route.php @@ -242,7 +242,7 @@ Route::group(function () { //资源共享-列表 Route::get('resourceSharing/index', 'apiController.ResourceSharing/index'); - Route::get('resourceSharing/index1', 'apiController.ResourceSharing/index1'); + //资源共享-详情(客户详情) Route::get('resourceSharing/info', 'apiController.ResourceSharing/info'); //资源共享-分配员工 diff --git a/niucloud/app/service/api/apiService/ResourceSharingService.php b/niucloud/app/service/api/apiService/ResourceSharingService.php index 1ae53d80..c04df5ce 100644 --- a/niucloud/app/service/api/apiService/ResourceSharingService.php +++ b/niucloud/app/service/api/apiService/ResourceSharingService.php @@ -32,101 +32,6 @@ class ResourceSharingService extends BaseApiService $this->model = (new ResourceSharing()); } - //获取列表 - public function getList(array $where) - { - $page_params = $this->getPageParam();//获取请求参数中的页码+分页数 - $page = $page_params['page']; - $limit = $page_params['limit']; - - $person_id = $this->member_id;//当前登录的员工id - $campus_where = []; - $campus_where[] = ['person_id', '=', $person_id]; - - if (!empty($where['campus_name'])) { - $campus_where[] = ['campus_name', 'like', '%' . $where['campus_name'] . '%']; - } - - - //查当前用户的归属校区 - $campus_id = CampusPersonRole::where($campus_where) - ->distinct(true) - ->column('campus_id'); - if ($campus_id) { - //查当前用户校区下的全部员工id - $person_id_arr = CampusPersonRole::whereIn('campus_id', $campus_id) - ->distinct(true) - ->column('person_id'); - } - - $resource_id_arr = [];//客户资源表id - //客户资源表名字 - if (!empty($where['name'])) { - $resource_id = (new CustomerResources())->where('name', 'like', "%{$where['name']}%")->column('id'); - $resource_id_arr = array_merge($resource_id_arr, $resource_id); - } - //客户资源表手机号 - if (!empty($where['phone_number'])) { - $resource_id = (new CustomerResources())->where('phone_number', 'like', "%{$where['phone_number']}%")->column('id'); - $resource_id_arr = array_merge($resource_id_arr, $resource_id); - } - //去重 - $resource_id_arr = array_unique($resource_id_arr); - - $model = $this->model; - - if ($resource_id_arr) { - $model = $model->whereIn('resource_id', $resource_id_arr); - } - - if (!empty($where['shared_at_arr'])) { - $model = $model->where('shared_at', '>=', $where['shared_at_arr'][0])->where('shared_at', '<=', $where['shared_at_arr'][1]); - } - - $model = $model->when(!empty($person_id_arr), function ($query) use ($person_id_arr) { - $query->whereIn('user_id', $person_id_arr); - }); - - if ((!empty($where['shared_by']) || isset($where['shared_by'])) && $where['shared_by'] !== '') { - $model = $model->whereOr('shared_by', $where['shared_by']); - } - //分页查询 - $res = $model->with(['customerResource', 'sixSpeed']) - ->withJoin(['customerResource', 'sixSpeed']) - ->order('customerResource.updated_at', 'desc') - ->paginate([ - 'list_rows' => $limit, - 'page' => $page, - ])->toArray(); -// 获取列表中的campus_ids - $campus_ids = array_unique(array_column(array_column($res['data'], 'customerResource'), 'campus')); - $campus = new Campus(); - $campus_name = $campus->whereIn('id', $campus_ids)->column('campus_name', 'id'); -// 获取客户资源沟通记录 - $customer_resource_ids = array_unique(array_column($res['data'], 'resource_id')); -// 2. 构建子查询:获取每个 resource_id 的最大 communication_time - $subQuery = CommunicationRecords::field('resource_id, max(communication_time) as max_time') - ->whereIn('resource_id', $customer_resource_ids) // 只查询指定的 resource_id - ->group('resource_id') - ->select() - ->toArray(); - - $resultdata = []; - foreach ($subQuery as $item) { - $resultdata[$item['resource_id']] = $item['max_time']; - } - - foreach ($res['data'] as &$item) { - $item['customerResource']['source'] = get_dict_value('source', $item['customerResource']['source']); - $item['customerResource']['source_channel'] = get_dict_value('source', $item['customerResource']['source_channel']); - $item['customerResource']['campus_name'] = $campus_name[$item['customerResource']['campus']] ?? ''; - $item['customerResource']['communication_time'] = $resultdata[$item['resource_id']] ?? ''; - } - - return $res; - - } - //查询资源共享详情 public function info(array $where, string $field = '*') { @@ -219,7 +124,7 @@ class ResourceSharingService extends BaseApiService return $res; } - public function getList1($where) + public function getList($where) { $page_params = $this->getPageParam();//获取请求参数中的页码+分页数 $page = $page_params['page'];