From d74624d2be3d7f0b5aff6f6962112d12e48a4a33 Mon Sep 17 00:00:00 2001 From: zeyan <258785420@qq.com> Date: Sat, 9 Aug 2025 16:44:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apiController/CustomerResources.php | 3 +- .../apiController/ResourceSharing.php | 20 +- niucloud/app/common.php | 11 +- niucloud/app/model/dict/Dict.php | 13 +- .../api/apiService/ResourceSharingService.php | 128 +- .../app/service/api/common/DictService.php | 47 +- uniapp/common/config.js | 4 +- uniapp/components/order-form-popup/index.vue | 137 ++- uniapp/pages-market/clue/edit_clues.vue | 1093 +++++------------ uniapp/pages-market/clue/index.vue | 79 +- 10 files changed, 671 insertions(+), 864 deletions(-) diff --git a/niucloud/app/api/controller/apiController/CustomerResources.php b/niucloud/app/api/controller/apiController/CustomerResources.php index 70ef80fb..18ef87c6 100644 --- a/niucloud/app/api/controller/apiController/CustomerResources.php +++ b/niucloud/app/api/controller/apiController/CustomerResources.php @@ -211,7 +211,8 @@ class CustomerResources extends BaseApiService "second_visit_status" => $request->param('second_visit_status', ''), "chasing_orders" => $request->param('chasing_orders', ''), "consultation_remark" => $request->param('consultation_remark', ''), - "call_intent" => $request->param('call_intent', '') + "call_intent" => $request->param('call_intent', ''), + "emotional_stickiness_score" => $request->param('emotional_stickiness_score', 1),//情感粘度 ]; diff --git a/niucloud/app/api/controller/apiController/ResourceSharing.php b/niucloud/app/api/controller/apiController/ResourceSharing.php index 4fcdc809..0f53a752 100644 --- a/niucloud/app/api/controller/apiController/ResourceSharing.php +++ b/niucloud/app/api/controller/apiController/ResourceSharing.php @@ -32,6 +32,15 @@ class ResourceSharing extends BaseApiService $name = $request->param('name','');////客户资源表-姓名 $phone_number = $request->param('phone_number','');//客户资源表-手机号 $campus_name = $request->param('campus_name','');//客户资源表-校区 + + // 新增搜索参数 + $source = $request->param('source','');//来源类型 + $source_channel = $request->param('source_channel','');//来源渠道 + $attendance_type = $request->param('attendance_type','');//到课类型 + $deal_type = $request->param('deal_type','');//成交类型 + $valid_type = $request->param('valid_type','');//资源有效类型 + $communication_status = $request->param('communication_status','');//沟通情况 + $course_search = $request->param('course_search','');//课程检索 $shared_at_str = $request->param('shared_at_str','');//共享时间|[开始时间(Y-m-d),结束时间(Y-m-d)] $shared_at_arr = []; @@ -46,9 +55,16 @@ class ResourceSharing extends BaseApiService 'shared_at_arr'=>$shared_at_arr, 'name'=>$name, 'phone_number'=>$phone_number, - 'campus_name' => $campus_name + 'campus_name' => $campus_name, + 'source' => $source, + 'source_channel' => $source_channel, + 'attendance_type' => $attendance_type, + 'deal_type' => $deal_type, + 'valid_type' => $valid_type, + 'communication_status' => $communication_status, + 'course_search' => $course_search ]; - $res= (new ResourceSharingService())->getList($where); + $res = (new ResourceSharingService())->getList($where); return success($res); } //资源共享-详情 diff --git a/niucloud/app/common.php b/niucloud/app/common.php index 85c38815..29e49157 100644 --- a/niucloud/app/common.php +++ b/niucloud/app/common.php @@ -1259,9 +1259,16 @@ function get_dict_value($key, $value) $info['dictionary'] = []; } + // 如果dictionary是字符串,尝试解析为数组 + if (is_string($info['dictionary'])) { + $info['dictionary'] = json_decode($info['dictionary'], true) ?: []; + } + $map = []; - foreach ($info['dictionary'] as $item) { - $map[$item['value']] = $item['name']; + if (is_array($info['dictionary'])) { + foreach ($info['dictionary'] as $item) { + $map[$item['value']] = $item['name']; + } } return $map[$value] ?? ''; diff --git a/niucloud/app/model/dict/Dict.php b/niucloud/app/model/dict/Dict.php index cf2a2822..43d28d5c 100644 --- a/niucloud/app/model/dict/Dict.php +++ b/niucloud/app/model/dict/Dict.php @@ -33,14 +33,13 @@ class Dict extends BaseModel */ protected $name = 'sys_dict'; - protected $type = [ - 'dictionary' => 'json' - ]; + // 移除JSON自动转换,手动处理以避免类型冲突 + // protected $type = [ + // 'dictionary' => 'json' + // ]; - // 设置json类型字段 - protected $json = ['dictionary']; - // 设置JSON数据返回数组 - protected $jsonAssoc = true; + // protected $json = ['dictionary']; + // protected $jsonAssoc = true; /** * 搜索器:数据字典字典名称 diff --git a/niucloud/app/service/api/apiService/ResourceSharingService.php b/niucloud/app/service/api/apiService/ResourceSharingService.php index bfb0b0f4..8866f547 100644 --- a/niucloud/app/service/api/apiService/ResourceSharingService.php +++ b/niucloud/app/service/api/apiService/ResourceSharingService.php @@ -200,7 +200,8 @@ class ResourceSharingService extends BaseApiService if (!empty($where['campus_name'])) { // 先查询匹配的校区ID $campus = new Campus(); - $matched_campus_ids = $campus->where('campus_name', 'like', '%' . $where['campus_name'] . '%')->column('id'); + $matched_campus_ids = $campus->where('campus_name', 'like', '%' . $where['campus_name'] . '%') + ->column('id'); if (!empty($matched_campus_ids)) { $resource_conditions[] = ['campus', 'in', $matched_campus_ids]; @@ -225,6 +226,16 @@ class ResourceSharingService extends BaseApiService if (!empty($where['phone_number'])) { $resource_conditions[] = ['phone_number', 'like', '%' . $where['phone_number'] . '%']; } + + // 来源查询 + if (!empty($where['source'])) { + $resource_conditions[] = ['source', 'like', '%' . $where['source'] . '%']; + } + + // 来源渠道查询 + if (!empty($where['source_channel'])) { + $resource_conditions[] = ['source_channel', 'like', '%' . $where['source_channel'] . '%']; + } // 查询符合条件的资源ID $resource_ids = []; @@ -248,6 +259,98 @@ class ResourceSharingService extends BaseApiService $model = $model->where('shared_at', '>=', $where['shared_at_arr'][0]) ->where('shared_at', '<=', $where['shared_at_arr'][1]); } + + // 处理有效性查询 - 需要通过six_speed表关联查询 + if (!empty($where['valid_type'])) { + $six_speed_model = new \app\model\six_speed\SixSpeed(); + if ($where['valid_type'] === '有效') { + $valid_resource_ids = $six_speed_model->where('efficacious', 1)->column('resource_id'); + } else if ($where['valid_type'] === '无效') { + $valid_resource_ids = $six_speed_model->where('efficacious', 0)->column('resource_id'); + } + + if (isset($valid_resource_ids)) { + if (empty($resource_ids)) { + $resource_ids = $valid_resource_ids; + } else { + $resource_ids = array_intersect($resource_ids, $valid_resource_ids); + } + + if (empty($resource_ids)) { + return [ + 'count' => 0, + 'total' => 0, + 'current_page' => $page, + 'last_page' => 0, + 'data' => [] + ]; + } + $model = $model->whereIn('resource_id', $resource_ids); + } + } + + // 处理成交类型查询 - 通过订单表关联查询 + if (!empty($where['deal_type'])) { + $order_model = new OrderTable(); + if ($where['deal_type'] === '已成交') { + $deal_resource_ids = $order_model->where('order_status', 'paid')->column('resource_id'); + } else if ($where['deal_type'] === '未成交') { + // 没有付费订单的资源 + $paid_resource_ids = $order_model->where('order_status', 'paid')->column('resource_id'); + $all_resource_ids = (new CustomerResources())->column('id'); + $deal_resource_ids = array_diff($all_resource_ids, $paid_resource_ids); + } + + if (isset($deal_resource_ids)) { + if (empty($resource_ids)) { + $resource_ids = $deal_resource_ids; + } else { + $resource_ids = array_intersect($resource_ids, $deal_resource_ids); + } + + if (empty($resource_ids)) { + return [ + 'count' => 0, + 'total' => 0, + 'current_page' => $page, + 'last_page' => 0, + 'data' => [] + ]; + } + $model = $model->whereIn('resource_id', $resource_ids); + } + } + + // 处理沟通情况查询 - 通过沟通记录表关联查询 + if (!empty($where['communication_status'])) { + if ($where['communication_status'] === '已沟通') { + $comm_resource_ids = CommunicationRecords::distinct(true)->column('resource_id'); + } else if ($where['communication_status'] === '未沟通') { + // 没有沟通记录的资源 + $comm_resource_ids_with_records = CommunicationRecords::distinct(true)->column('resource_id'); + $all_resource_ids = (new CustomerResources())->column('id'); + $comm_resource_ids = array_diff($all_resource_ids, $comm_resource_ids_with_records); + } + + if (isset($comm_resource_ids)) { + if (empty($resource_ids)) { + $resource_ids = $comm_resource_ids; + } else { + $resource_ids = array_intersect($resource_ids, $comm_resource_ids); + } + + if (empty($resource_ids)) { + return [ + 'count' => 0, + 'total' => 0, + 'current_page' => $page, + 'last_page' => 0, + 'data' => [] + ]; + } + $model = $model->whereIn('resource_id', $resource_ids); + } + } // 过滤已分配的资源(只显示可再分配的资源) // 注意:这里需要用子查询包装OR条件,避免与其他WHERE条件冲突 @@ -295,6 +398,15 @@ class ResourceSharingService extends BaseApiService $shared_by_ids = array_column($list['data'], 'shared_by'); $shared_by_ids = array_unique(array_filter($shared_by_ids)); + // 获取市场老师ID列表 + $consultant_ids = []; + foreach ($list['data'] as $item) { + if (!empty($item['customerResource']) && !empty($item['customerResource']['consultant'])) { + $consultant_ids[] = $item['customerResource']['consultant']; + } + } + $consultant_ids = array_unique(array_filter($consultant_ids)); + // 查询分配人员信息 $shared_by_names = []; if (!empty($shared_by_ids)) { @@ -302,6 +414,13 @@ class ResourceSharingService extends BaseApiService $shared_by_names = $personnel->whereIn('id', $shared_by_ids)->column('name', 'id'); } + // 查询市场老师信息 + $consultant_names = []; + if (!empty($consultant_ids)) { + $personnel = new \app\model\personnel\Personnel(); + $consultant_names = $personnel->whereIn('id', $consultant_ids)->column('name', 'id'); + } + // 查询最近沟通记录 $communication_times = []; if (!empty($resource_ids)) { @@ -404,6 +523,13 @@ class ResourceSharingService extends BaseApiService $item['customerResource']['source_channel'] = get_dict_value('SourceChannel', $item['customerResource']['source_channel']); $item['customerResource']['campus_name'] = $campus_names[$item['customerResource']['campus']] ?? ''; + // 设置市场老师名称 + if (!empty($item['customerResource']['consultant'])) { + $item['customerResource']['consultant_name'] = $consultant_names[$item['customerResource']['consultant']] ?? ''; + } else { + $item['customerResource']['consultant_name'] = ''; + } + // 修复沟通时间字段 $item['customerResource']['communication_time'] = $communication_times[$item['resource_id']] ?? ''; diff --git a/niucloud/app/service/api/common/DictService.php b/niucloud/app/service/api/common/DictService.php index c5fd9eb6..1c73f0c7 100644 --- a/niucloud/app/service/api/common/DictService.php +++ b/niucloud/app/service/api/common/DictService.php @@ -61,16 +61,45 @@ class DictService extends BaseApiService $key = $dict['key']; $dictionary = $dict['dictionary']; - // 解析字典值 - 模型已自动处理JSON转换 - if (!empty($dictionary) && is_array($dictionary)) { - $result[$key] = $dictionary; - } else if (!empty($dictionary) && is_string($dictionary)) { - // 如果是字符串,尝试解析 - $decodedValue = json_decode($dictionary, true); - if (json_last_error() === JSON_ERROR_NONE && is_array($decodedValue)) { - $result[$key] = $decodedValue; + // 解析字典值 - 手动处理JSON解析 + if (!empty($dictionary)) { + if (is_array($dictionary)) { + // 已经是数组格式,直接使用 + $result[$key] = $dictionary; + } else if (is_string($dictionary)) { + // 处理JSON字符串,可能包含转义字符 + + // 首先尝试直接解析 + $decodedValue = json_decode($dictionary, true); + if (json_last_error() === JSON_ERROR_NONE) { + if (is_array($decodedValue)) { + // 解析结果是数组,直接使用 + $result[$key] = $decodedValue; + } else if (is_string($decodedValue)) { + // 解析结果是字符串,可能是双重JSON编码,尝试再次解析 + $secondDecodedValue = json_decode($decodedValue, true); + if (json_last_error() === JSON_ERROR_NONE && is_array($secondDecodedValue)) { + $result[$key] = $secondDecodedValue; + } else { + // 字符串解析失败,使用字符串解析方法 + $result[$key] = $this->parseStringValue($decodedValue); + } + } else { + $result[$key] = []; + } + } else { + // JSON解析失败,尝试其他方法 + $cleanedDictionary = stripcslashes($dictionary); + $decodedValue = json_decode($cleanedDictionary, true); + if (json_last_error() === JSON_ERROR_NONE && is_array($decodedValue)) { + $result[$key] = $decodedValue; + } else { + // 使用字符串解析方法作为最后手段 + $result[$key] = $this->parseStringValue($dictionary); + } + } } else { - $result[$key] = $this->parseStringValue($dictionary); + $result[$key] = []; } } else { $result[$key] = []; diff --git a/uniapp/common/config.js b/uniapp/common/config.js index 2459f37b..c98a2253 100644 --- a/uniapp/common/config.js +++ b/uniapp/common/config.js @@ -1,6 +1,6 @@ // 环境变量配置 -// const env = 'development' -const env = 'prod' +const env = 'development' +// const env = 'prod' const isMockEnabled = false // 默认禁用Mock优先模式,仅作为回退 const isDebug = false // 默认启用调试模式 const devurl = 'http://localhost:20080/api' diff --git a/uniapp/components/order-form-popup/index.vue b/uniapp/components/order-form-popup/index.vue index 26b873c5..1efb781e 100644 --- a/uniapp/components/order-form-popup/index.vue +++ b/uniapp/components/order-form-popup/index.vue @@ -120,6 +120,7 @@ \ No newline at end of file diff --git a/uniapp/pages-market/clue/index.vue b/uniapp/pages-market/clue/index.vue index f48fe810..52c373c2 100644 --- a/uniapp/pages-market/clue/index.vue +++ b/uniapp/pages-market/clue/index.vue @@ -39,8 +39,8 @@ 到访备注:{{ v.sixSpeed.consultation_remark || '' }} - - 市场老师:{{ v.sixSpeed.consultation_remark || '' }} + + 市场老师:{{ v.customerResource.consultant_name || '测试显示' + v.customerResource.consultant }} @@ -383,7 +383,9 @@ // 选择器相关 sourceIndex: 0, - sourceOptions: ['全部', '线上', '线下'], + sourceOptions: ['全部', '线上', '线下'], // 默认值,会被动态替换 + sourceDict: {}, // 来源名称到ID的映射 + sourceChannelDict: {}, // 渠道名称到ID的映射 attendanceIndex: 0, attendanceOptions: ['全部', '一访未到', '一访已到', '二访未到', '二访已到', '未到访'], dealIndex: 0, @@ -510,6 +512,7 @@ //初始化 async init() { await this.getUserInfo(); + await this.initDictData(); // 初始化字典数据 if (this.segmented_type == 1) { await this.getList_1(); } else { @@ -517,6 +520,38 @@ } }, + // 初始化字典数据 + async initDictData() { + try { + // 获取来源字典 + const sourceRes = await apiRoute.common_Dictionary({key: 'source'}) + if (sourceRes.code === 1 && sourceRes.data) { + // 直接使用返回的数据数组 + const sourceData = sourceRes.data + this.sourceOptions = ['全部', ...sourceData.map(item => item.name)] + this.sourceDict = sourceData.reduce((acc, item) => { + acc[item.name] = item.value + return acc + }, {}) + console.log('来源字典加载成功:', this.sourceOptions) + } + + // 获取渠道字典 + const channelRes = await apiRoute.common_Dictionary({key: 'SourceChannel'}) + if (channelRes.code === 1 && channelRes.data) { + // 直接使用返回的数据数组 + const channelData = channelRes.data + this.sourceChannelDict = channelData.reduce((acc, item) => { + acc[item.name] = item.value + return acc + }, {}) + console.log('渠道字典加载成功:', this.sourceChannelDict) + } + } catch (error) { + console.error('字典数据加载失败:', error) + } + }, + //获取用户信息 async getUserInfo() { let res = await apiRoute.getPersonnelInfo({}) @@ -628,6 +663,11 @@ return } + console.log('getList_1 API响应:', res) + console.log('getList_1 第一条数据的customerResource:', res.data.data[0]?.customerResource) + console.log('getList_1 consultant字段:', res.data.data[0]?.customerResource?.consultant) + console.log('getList_1 consultant_name字段:', res.data.data[0]?.customerResource?.consultant_name) + this.tableList_1 = this.tableList_1.concat(res.data.data); // 使用 concat 方法 将新数据追加到数组中 console.log('列表1', this.tableList_1) @@ -681,7 +721,8 @@ return } - console.log(123123, res) + console.log('API响应数据:', res) + console.log('第一条数据的customerResource:', res.data.data[0]?.customerResource) this.tableList_2 = this.tableList_2.concat(res.data.data); // 使用 concat 方法 将新数据追加到数组中 @@ -987,21 +1028,49 @@ currentFilterData.shared_at_str = '' } - // 处理其他搜索条件(如果后端支持) + // 处理来源字段:将中文名称直接传给后端(后端已支持中文名称搜索) if (this.searchForm.source && this.searchForm.source !== '全部') { currentFilterData.source = this.searchForm.source + } else { + currentFilterData.source = '' } + + // 处理渠道字段 if (this.searchForm.source_channel) { currentFilterData.source_channel = this.searchForm.source_channel + } else { + currentFilterData.source_channel = '' } + + // 处理其他搜索条件 if (this.searchForm.attendance_type && this.searchForm.attendance_type !== '全部') { currentFilterData.attendance_type = this.searchForm.attendance_type + } else { + currentFilterData.attendance_type = '' } + if (this.searchForm.deal_type && this.searchForm.deal_type !== '全部') { currentFilterData.deal_type = this.searchForm.deal_type + } else { + currentFilterData.deal_type = '' } + if (this.searchForm.valid_type && this.searchForm.valid_type !== '全部') { currentFilterData.valid_type = this.searchForm.valid_type + } else { + currentFilterData.valid_type = '' + } + + if (this.searchForm.communication_status && this.searchForm.communication_status !== '全部') { + currentFilterData.communication_status = this.searchForm.communication_status + } else { + currentFilterData.communication_status = '' + } + + if (this.searchForm.course_search) { + currentFilterData.course_search = this.searchForm.course_search + } else { + currentFilterData.course_search = '' } console.log('映射后的筛选数据:', currentFilterData)