|
|
|
@ -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']; |
|
|
|
|