|
|
@ -13,6 +13,7 @@ namespace app\service\api\apiService; |
|
|
|
|
|
|
|
|
use app\model\campus\Campus; |
|
|
use app\model\campus\Campus; |
|
|
use app\model\campus_person_role\CampusPersonRole; |
|
|
use app\model\campus_person_role\CampusPersonRole; |
|
|
|
|
|
use app\model\communication_records\CommunicationRecords; |
|
|
use app\model\customer_resources\CustomerResources; |
|
|
use app\model\customer_resources\CustomerResources; |
|
|
use app\model\order_table\OrderTable; |
|
|
use app\model\order_table\OrderTable; |
|
|
use app\model\resource_sharing\ResourceSharing; |
|
|
use app\model\resource_sharing\ResourceSharing; |
|
|
@ -90,23 +91,36 @@ class ResourceSharingService extends BaseApiService |
|
|
$model = $model->whereOr('shared_by', $where['shared_by']); |
|
|
$model = $model->whereOr('shared_by', $where['shared_by']); |
|
|
} |
|
|
} |
|
|
//分页查询 |
|
|
//分页查询 |
|
|
$res = $model->with([ |
|
|
$res = $model->with(['customerResource','sixSpeed']) |
|
|
'customerResource' => function ($query) { |
|
|
->withJoin(['customerResource','sixSpeed']) |
|
|
$query->append(['initial_intent_name']); |
|
|
|
|
|
} |
|
|
|
|
|
]) |
|
|
|
|
|
->withJoin(['customerResource']) |
|
|
|
|
|
->order('customerResource.updated_at', 'desc') |
|
|
->order('customerResource.updated_at', 'desc') |
|
|
->paginate([ |
|
|
->paginate([ |
|
|
'list_rows' => $limit, |
|
|
'list_rows' => $limit, |
|
|
'page' => $page, |
|
|
'page' => $page, |
|
|
])->toArray(); |
|
|
])->toArray(); |
|
|
|
|
|
// 获取列表中的campus_ids |
|
|
|
|
|
$campus_ids = array_unique(array_column(array_column($res['data'],'customerResource'), 'campus')); |
|
|
$campus = new 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(); |
|
|
|
|
|
|
|
|
|
|
|
dd($campus_name,$campus_ids); |
|
|
|
|
|
$resultdata = []; |
|
|
|
|
|
foreach ($subQuery as $item) { |
|
|
|
|
|
$resultdata[$item['resource_id']] = $item['max_time']; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
foreach ($res['data'] as &$item){ |
|
|
foreach ($res['data'] as &$item){ |
|
|
$item['customerResource']['source_channel'] = get_dict_value('source',$item['customerResource']['source_channel']); |
|
|
$item['customerResource']['source_channel'] = get_dict_value('source',$item['customerResource']['source_channel']); |
|
|
$item['customerResource']['campus_name'] = $campus->where(['id' =>$item['customerResource']['campus']])->value("campus_name"); |
|
|
$item['customerResource']['campus_name'] = $campus_name[$item['customerResource']['campus']] ?? ''; |
|
|
|
|
|
$item['customerResource']['communication_time'] = $resultdata[$item['resource_id']] ?? ''; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return $res; |
|
|
return $res; |
|
|
|