Browse Source

修改 bug

master
王泽彦 6 months ago
parent
commit
5bb437473b
  1. 31
      niucloud/app/service/api/apiService/PersonnelService.php
  2. 128
      niucloud/app/service/api/apiService/ResourceSharingService.php
  3. 2
      uniapp/common/config.js
  4. 1339
      uniapp/pages-market/clue/index.vue

31
niucloud/app/service/api/apiService/PersonnelService.php

@ -925,22 +925,25 @@ class PersonnelService extends BaseApiService
try {
$where = [];
// 查询销售部门(dept_id=3)下的所有角色ID
$salesRoleIds = SysRole::where('dept_id', 3)
->where('status', 1)
// 排除的角色key列表
$excludeRoleKeys = ['teacher', 'market', 'market_manager', 'teacher_manager', 'superadmin', 'finance_role'];
// 查询除了排除角色外的所有角色ID
$roleIds = SysRole::where('status', 1)
->where('role_key', 'not in', $excludeRoleKeys)
->column('role_id');
if (empty($salesRoleIds)) {
if (empty($roleIds)) {
return [
'code' => 1,
'msg' => '暂无销售部门角色',
'msg' => '暂无符合条件的角色',
'data' => []
];
}
// 构建校区人员角色关系查询条件
$campusPersonWhere = [
['role_id', 'in', $salesRoleIds]
['role_id', 'in', $roleIds]
];
// 根据传入的校区进行筛选
@ -948,21 +951,21 @@ class PersonnelService extends BaseApiService
$campusPersonWhere[] = ['campus_id', '=', $campus];
}
// 查询符合条件的销售人员ID
$salesPersonIds = CampusPersonRole::where($campusPersonWhere)
// 查询符合条件的人员ID
$personIds = CampusPersonRole::where($campusPersonWhere)
->column('person_id');
if (empty($salesPersonIds)) {
if (empty($personIds)) {
return [
'code' => 1,
'msg' => '暂无销售人员数据',
'msg' => '暂无符合条件的人员数据',
'data' => []
];
}
// 从personnel表中获取人员信息,包含姓名和电话
$salesPersonnel = $this->model
->whereIn('id', $salesPersonIds)
$personnel = $this->model
->whereIn('id', $personIds)
->where('deleted_at', 0) // 只获取未删除的人员
->field('id, name, phone')
->order('create_time DESC')
@ -972,13 +975,13 @@ class PersonnelService extends BaseApiService
return [
'code' => 1,
'msg' => '获取成功',
'data' => $salesPersonnel
'data' => $personnel
];
} catch (\Exception $e) {
return [
'code' => 0,
'msg' => '获取销售人员列表失败:' . $e->getMessage(),
'msg' => '获取人员列表失败:' . $e->getMessage(),
'data' => []
];
}

128
niucloud/app/service/api/apiService/ResourceSharingService.php

@ -282,6 +282,19 @@ class ResourceSharingService extends BaseApiService
// 应用权限过滤
$model = $this->applyPermissionFilter($model, $permissions, $person_id, $shared_scope, $shared_by, $assignee_role_ids);
// 全部资源场景下,固定按最近一次分配记录去重
if ($shared_scope === 'all') {
$latestAssignmentSub = $this->assignmentModel
->alias('sub')
->field('MAX(id) as latest_id, resource_id')
->group('resource_id')
->buildSql();
$model = $model
->join([$latestAssignmentSub => 'latest'], 'ra.id = latest.latest_id')
->field('ra.*');
}
// 处理查询条件 - CustomerResources模型的字段
$resource_conditions = [];
@ -478,6 +491,28 @@ class ResourceSharingService extends BaseApiService
$resource_ids = array_column($list['data'], 'resource_id');
$resource_ids = array_unique(array_filter($resource_ids));
// 映射 legacy 表中的资源共享记录 ID,兼容旧接口依赖
$resource_sharing_map = [];
if (!empty($resource_ids)) {
$legacy_records = $this->model
->whereIn('resource_id', $resource_ids)
->order('id', 'desc')
->field('resource_id, id')
->select()
->toArray();
foreach ($legacy_records as $record) {
$resourceId = (int) ($record['resource_id'] ?? 0);
$recordId = (int) ($record['id'] ?? 0);
if ($resourceId === 0 || $recordId === 0) {
continue;
}
if (!isset($resource_sharing_map[$resourceId])) {
$resource_sharing_map[$resourceId] = $recordId;
}
}
}
// 获取分配人员ID列表
$shared_by_ids = array_column($list['data'], 'assigned_by');
$shared_by_ids = array_unique(array_filter($shared_by_ids));
@ -505,6 +540,45 @@ class ResourceSharingService extends BaseApiService
$consultant_names = $personnel->whereIn('id', $consultant_ids)->column('name', 'id');
}
// 查询销售老师信息(从资源分配表获取)
$sales_teachers = [];
if (!empty($resource_ids)) {
$assignment_model = new \app\model\resource_assignment\ResourceAssignment();
$assignments = $assignment_model
->whereIn('resource_id', $resource_ids)
->where('assignee_type', 'user')
->field('resource_id, assignee_id')
->select()
->toArray();
// 获取所有销售人员ID
$sales_teacher_ids = array_unique(array_column($assignments, 'assignee_id'));
$sales_teacher_names = [];
if (!empty($sales_teacher_ids)) {
$personnel = new \app\model\personnel\Personnel();
$sales_teacher_names = $personnel->whereIn('id', $sales_teacher_ids)->column('name', 'id');
}
// 按resource_id组织销售老师名称
foreach ($assignments as $assignment) {
$resource_id = $assignment['resource_id'];
$assignee_id = $assignment['assignee_id'];
$teacher_name = $sales_teacher_names[$assignee_id] ?? '';
if (!isset($sales_teachers[$resource_id])) {
$sales_teachers[$resource_id] = [];
}
if (!empty($teacher_name)) {
$sales_teachers[$resource_id][] = $teacher_name;
}
}
// 将数组转为字符串
foreach ($sales_teachers as $resource_id => &$teachers) {
$teachers = implode('、', array_unique($teachers));
}
}
// 查询最近沟通记录
$communication_times = [];
if (!empty($resource_ids)) {
@ -601,6 +675,10 @@ class ResourceSharingService extends BaseApiService
// 处理每条数据
foreach ($list['data'] as &$item) {
$resourceId = (int) ($item['resource_id'] ?? 0);
$legacyResourceSharingId = $resource_sharing_map[$resourceId] ?? null;
$item['resource_sharing_id'] = $legacyResourceSharingId;
if (!empty($item['customerResource'])) {
// 确保数据类型转换:数据库中的数值需要转换为字符串
$source_value = (string) $item['customerResource']['source'];
@ -611,12 +689,23 @@ class ResourceSharingService extends BaseApiService
$item['customerResource']['source_channel'] = get_dict_value('SourceChannel', $source_channel_value);
$item['customerResource']['campus_name'] = $campus_names[$item['customerResource']['campus']] ?? '';
if ($legacyResourceSharingId !== null) {
$item['customerResource']['resource_sharing_id'] = $legacyResourceSharingId;
}
if (!empty($item['customerResource']['consultant'])) {
$item['customerResource']['consultant_name'] = $consultant_names[$item['customerResource']['consultant']] ?? '';
} else {
$item['customerResource']['consultant_name'] = '';
}
// 添加市场老师字段(与consultant_name相同)
$item['customerResource']['market_teacher'] = $item['customerResource']['consultant_name'];
// 添加销售老师字段(从资源分配表获取的拼接字符串)
$resource_id = $item['resource_id'];
$item['customerResource']['sales_teacher'] = $sales_teachers[$resource_id] ?? '';
$item['customerResource']['communication_time'] = $communication_times[$item['resource_id']] ?? '';
$resource_id = $item['resource_id'];
@ -970,6 +1059,45 @@ class ResourceSharingService extends BaseApiService
$consultant_names = $personnel->whereIn('id', $consultant_ids)->column('name', 'id');
}
// 查询销售老师信息(从资源分配表获取)
$sales_teachers = [];
if (!empty($resource_ids)) {
$assignment_model = new \app\model\resource_assignment\ResourceAssignment();
$assignments = $assignment_model
->whereIn('resource_id', $resource_ids)
->where('assignee_type', 'user')
->field('resource_id, assignee_id')
->select()
->toArray();
// 获取所有销售人员ID
$sales_teacher_ids = array_unique(array_column($assignments, 'assignee_id'));
$sales_teacher_names = [];
if (!empty($sales_teacher_ids)) {
$personnel = new \app\model\personnel\Personnel();
$sales_teacher_names = $personnel->whereIn('id', $sales_teacher_ids)->column('name', 'id');
}
// 按resource_id组织销售老师名称
foreach ($assignments as $assignment) {
$resource_id = $assignment['resource_id'];
$assignee_id = $assignment['assignee_id'];
$teacher_name = $sales_teacher_names[$assignee_id] ?? '';
if (!isset($sales_teachers[$resource_id])) {
$sales_teachers[$resource_id] = [];
}
if (!empty($teacher_name)) {
$sales_teachers[$resource_id][] = $teacher_name;
}
}
// 将数组转为字符串
foreach ($sales_teachers as $resource_id => &$teachers) {
$teachers = implode('、', array_unique($teachers));
}
}
// 查询最近沟通记录
$communication_times = [];
if (!empty($resource_ids)) {

2
uniapp/common/config.js

@ -1,6 +1,6 @@
// 环境变量配置
// const env = 'development'
const env = 'development'
const env = 'prod'
const isMockEnabled = false // 默认禁用Mock优先模式,仅作为回退
const isDebug = false // 默认启用调试模式
const devurl = 'http://localhost:20080/api'

1339
uniapp/pages-market/clue/index.vue

File diff suppressed because it is too large
Loading…
Cancel
Save