|
|
@ -14,6 +14,7 @@ namespace app\service\api\apiService; |
|
|
use app\model\campus_person_role\CampusPersonRole; |
|
|
use app\model\campus_person_role\CampusPersonRole; |
|
|
use app\model\customer_resource_changes\CustomerResourceChanges; |
|
|
use app\model\customer_resource_changes\CustomerResourceChanges; |
|
|
use app\model\customer_resources\CustomerResources; |
|
|
use app\model\customer_resources\CustomerResources; |
|
|
|
|
|
use app\model\dict\Dict; |
|
|
use app\model\personnel\Personnel; |
|
|
use app\model\personnel\Personnel; |
|
|
use app\model\resource_sharing\ResourceSharing; |
|
|
use app\model\resource_sharing\ResourceSharing; |
|
|
use app\model\six_speed\SixSpeed; |
|
|
use app\model\six_speed\SixSpeed; |
|
|
@ -205,6 +206,263 @@ class CustomerResourcesService extends BaseApiService |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//客户资源-获取客户资源修改记录列表 |
|
|
|
|
|
public function getCustomerResourceChangesEditLog(array $where) |
|
|
|
|
|
{ |
|
|
|
|
|
$page_params = $this->getPageParam();//获取请求参数中的页码+分页数 |
|
|
|
|
|
$page = $page_params['page']; |
|
|
|
|
|
$limit = $page_params['limit']; |
|
|
|
|
|
|
|
|
|
|
|
//客户资源修改记录表 |
|
|
|
|
|
$data = CustomerResourceChanges::where('customer_resource_id', $where['customer_resource_id']) |
|
|
|
|
|
->order('created_at', 'desc') |
|
|
|
|
|
->with([ |
|
|
|
|
|
'personnel' => function ($query) { |
|
|
|
|
|
} |
|
|
|
|
|
]) |
|
|
|
|
|
->paginate([ |
|
|
|
|
|
'list_rows' => $limit, |
|
|
|
|
|
'page' => $page, |
|
|
|
|
|
]) |
|
|
|
|
|
->toArray(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$fieldZhArr = CustomerResources::FieldZh;//字段中文映射常量 |
|
|
|
|
|
//需要获取字段与字典key的映射关系数组 |
|
|
|
|
|
$fieldDictArr = [ |
|
|
|
|
|
'source_channel'=>'SourceChannel',//field=>dict_key(来源渠道) |
|
|
|
|
|
'source'=>'source',//field=>dict_key(来源) |
|
|
|
|
|
'gender'=>'zy_sex',//field=>dict_key(性别) |
|
|
|
|
|
'purchasing_power'=>'customer_purchasing_power',//field=>dict_key(购买力) |
|
|
|
|
|
'cognitive_idea'=>'cognitive_concept',//field=>dict_key(认知理念) |
|
|
|
|
|
'initial_intent'=>'preliminarycustomerintention',//field=>dict_key(客户初步意向度) |
|
|
|
|
|
'status'=>'kh_status',//field=>dict_key(客户状态) |
|
|
|
|
|
]; |
|
|
|
|
|
$dict_arr = $this->getFieldDictionary($fieldDictArr);//字段与字典值列表的映射关系 |
|
|
|
|
|
|
|
|
|
|
|
$consultant_id_arr = []; |
|
|
|
|
|
foreach ($data['data'] as $v) { |
|
|
|
|
|
$modified_fields_arr = json_decode($v['modified_fields'], true); |
|
|
|
|
|
$old_values_arr = json_decode($v['old_values'], true); |
|
|
|
|
|
$new_values_arr = json_decode($v['new_values'], true); |
|
|
|
|
|
|
|
|
|
|
|
//判断有没有修改过"顾问"字段 |
|
|
|
|
|
if(in_array('consultant',$modified_fields_arr)){ |
|
|
|
|
|
$consultant_id_arr[] = $old_values_arr['consultant']; |
|
|
|
|
|
$consultant_id_arr[] = $new_values_arr['consultant']; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
$consultant_id_arr = array_unique($consultant_id_arr);//去重 |
|
|
|
|
|
$dict_arr['consultant'] = [];//获取员工信息列表 |
|
|
|
|
|
if($consultant_id_arr){ |
|
|
|
|
|
$personnel = Personnel::whereIn('id',$consultant_id_arr)->field('id,name')->select()->toArray(); |
|
|
|
|
|
foreach($personnel as $v){ |
|
|
|
|
|
$dict_arr['consultant'][] = [ |
|
|
|
|
|
"name" => $v['name'], |
|
|
|
|
|
"value" => $v['id'], |
|
|
|
|
|
"sort" => 0, |
|
|
|
|
|
"memo" => "", |
|
|
|
|
|
]; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$fieldDictKeyArr = array_keys($fieldDictArr); |
|
|
|
|
|
$list = []; |
|
|
|
|
|
foreach ($data['data'] as $v) { |
|
|
|
|
|
$modified_fields_arr = json_decode($v['modified_fields'], true); |
|
|
|
|
|
$old_values_arr = json_decode($v['old_values'], true); |
|
|
|
|
|
$new_values_arr = json_decode($v['new_values'], true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$update_arr = []; |
|
|
|
|
|
foreach ($modified_fields_arr as $m_v) { |
|
|
|
|
|
$old_value = $old_values_arr[$m_v] ?? ''; |
|
|
|
|
|
$new_value = $new_values_arr[$m_v] ?? ''; |
|
|
|
|
|
|
|
|
|
|
|
if(in_array($m_v,$fieldDictKeyArr)){ |
|
|
|
|
|
$dict = $dict_arr[$m_v]; |
|
|
|
|
|
foreach($dict as $d_v){ |
|
|
|
|
|
if($d_v['value'] == $old_value){ |
|
|
|
|
|
$old_value = $d_v['name']; |
|
|
|
|
|
} |
|
|
|
|
|
if($d_v['value'] == $new_value){ |
|
|
|
|
|
$new_value = $d_v['name']; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//一些字典和外键相关的字段值处理 |
|
|
|
|
|
$update_arr[] = [ |
|
|
|
|
|
'field_name_en' => $m_v, |
|
|
|
|
|
'field_name_zh' => $fieldZhArr[$m_v] ?? $m_v, |
|
|
|
|
|
'old_value' => $old_value, |
|
|
|
|
|
'new_value' => $new_value, |
|
|
|
|
|
]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$list[] = [ |
|
|
|
|
|
'id' => $v['id'],//日志id |
|
|
|
|
|
'modification_time' => $v['modification_time'],//修改时间 |
|
|
|
|
|
'staff_id_name' => $v['staff_id_name'],//修改人的名字 |
|
|
|
|
|
'update_arr' => $update_arr,//数据变更数组 |
|
|
|
|
|
]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$data['data'] = $list; |
|
|
|
|
|
return $data; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//客户资源-获取六要素修改记录列表 |
|
|
|
|
|
public function getSixSpeedModificationEditLog(array $where) |
|
|
|
|
|
{ |
|
|
|
|
|
$page_params = $this->getPageParam();//获取请求参数中的页码+分页数 |
|
|
|
|
|
$page = $page_params['page']; |
|
|
|
|
|
$limit = $page_params['limit']; |
|
|
|
|
|
|
|
|
|
|
|
//六要素修改记录表 |
|
|
|
|
|
$data = SixSpeedModificationLog::where('operator_id', $where['customer_resource_id']) |
|
|
|
|
|
->order('created_at', 'desc') |
|
|
|
|
|
->with([ |
|
|
|
|
|
'personnel' => function ($query) { |
|
|
|
|
|
} |
|
|
|
|
|
]) |
|
|
|
|
|
->paginate([ |
|
|
|
|
|
'list_rows' => $limit, |
|
|
|
|
|
'page' => $page, |
|
|
|
|
|
]) |
|
|
|
|
|
->toArray(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$fieldZhArr = SixSpeed::FieldZh;//字段中文映射常量 |
|
|
|
|
|
//需要获取字段与字典key的映射关系数组 |
|
|
|
|
|
$fieldDictArr = [ |
|
|
|
|
|
'purchase_power'=>'customer_purchasing_power',//field=>dict_key(需求购买力) |
|
|
|
|
|
'concept_awareness'=>'cognitive_concept',//field=>dict_key(认知理念) |
|
|
|
|
|
'call_intent'=>'preliminarycustomerintention',//field=>dict_key(电话后的意向程度) |
|
|
|
|
|
'is_closed'=>'global_true_or_false',//field=>dict_key(是否关单: 1-是, 0-否) |
|
|
|
|
|
]; |
|
|
|
|
|
$dict_arr = $this->getFieldDictionary($fieldDictArr);//字段与字典值列表的映射关系 |
|
|
|
|
|
|
|
|
|
|
|
$consultant_id_arr = [];//顾问(人员)id数组 |
|
|
|
|
|
foreach ($data['data'] as $v) { |
|
|
|
|
|
$modified_fields_arr = json_decode($v['modified_field'], true); |
|
|
|
|
|
$old_values_arr = json_decode($v['old_value'], true); |
|
|
|
|
|
$new_values_arr = json_decode($v['new_value'], true); |
|
|
|
|
|
|
|
|
|
|
|
//判断有没有修改过"顾问(人员)"字段 |
|
|
|
|
|
if(in_array('staff_id',$modified_fields_arr)){ |
|
|
|
|
|
$consultant_id_arr[] = $old_values_arr['staff_id']; |
|
|
|
|
|
$consultant_id_arr[] = $new_values_arr['staff_id']; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
$consultant_id_arr = array_unique($consultant_id_arr);//去重 |
|
|
|
|
|
$dict_arr['consultant'] = [];//获取员工信息列表 |
|
|
|
|
|
if($consultant_id_arr){ |
|
|
|
|
|
$personnel = Personnel::whereIn('id',$consultant_id_arr)->field('id,name')->select()->toArray(); |
|
|
|
|
|
foreach($personnel as $v){ |
|
|
|
|
|
$dict_arr['consultant'][] = [ |
|
|
|
|
|
"name" => $v['name'], |
|
|
|
|
|
"value" => $v['id'], |
|
|
|
|
|
"sort" => 0, |
|
|
|
|
|
"memo" => "", |
|
|
|
|
|
]; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$fieldDictKeyArr = array_keys($fieldDictArr); |
|
|
|
|
|
$list = []; |
|
|
|
|
|
foreach ($data['data'] as $v) { |
|
|
|
|
|
$modified_fields_arr = json_decode($v['modified_field'], true); |
|
|
|
|
|
$old_values_arr = json_decode($v['old_value'], true); |
|
|
|
|
|
$new_values_arr = json_decode($v['new_value'], true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$update_arr = []; |
|
|
|
|
|
foreach ($modified_fields_arr as $m_v) { |
|
|
|
|
|
$old_value = $old_values_arr[$m_v] ?? ''; |
|
|
|
|
|
$new_value = $new_values_arr[$m_v] ?? ''; |
|
|
|
|
|
|
|
|
|
|
|
if(in_array($m_v,$fieldDictKeyArr)){ |
|
|
|
|
|
$dict = $dict_arr[$m_v]; |
|
|
|
|
|
foreach($dict as $d_v){ |
|
|
|
|
|
if($d_v['value'] == $old_value){ |
|
|
|
|
|
$old_value = $d_v['name']; |
|
|
|
|
|
} |
|
|
|
|
|
if($d_v['value'] == $new_value){ |
|
|
|
|
|
$new_value = $d_v['name']; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//一些字典和外键相关的字段值处理 |
|
|
|
|
|
$update_arr[] = [ |
|
|
|
|
|
'field_name_en' => $m_v, |
|
|
|
|
|
'field_name_zh' => $fieldZhArr[$m_v] ?? $m_v, |
|
|
|
|
|
'old_value' => $old_value, |
|
|
|
|
|
'new_value' => $new_value, |
|
|
|
|
|
]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$list[] = [ |
|
|
|
|
|
'id' => $v['id'],//日志id |
|
|
|
|
|
'modification_time' => $v['updated_at'],//修改时间 |
|
|
|
|
|
'staff_id_name' => $v['staff_id_name'],//修改人的名字 |
|
|
|
|
|
'update_arr' => $update_arr,//数据变更数组 |
|
|
|
|
|
]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$data['data'] = $list; |
|
|
|
|
|
return $data; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 根据字段和字典键映射关系,获取字段对应字典项 |
|
|
|
|
|
* |
|
|
|
|
|
* @param array $fieldDictMapping 字段 => 字典 key 映射数组 |
|
|
|
|
|
* @return array 字段 => 字典列表 |
|
|
|
|
|
*/ |
|
|
|
|
|
public function getFieldDictionary(array $fieldDictMapping): array |
|
|
|
|
|
{ |
|
|
|
|
|
// 获取所有需要的字典 key 列表 |
|
|
|
|
|
$dictKeys = array_values($fieldDictMapping); |
|
|
|
|
|
|
|
|
|
|
|
if (empty($dictKeys)) { |
|
|
|
|
|
return []; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 查询字典数据 |
|
|
|
|
|
$dictData = Dict::whereIn('key', $dictKeys)->select()->toArray(); |
|
|
|
|
|
|
|
|
|
|
|
//使用 array_column 构建 key => dict 的映射 |
|
|
|
|
|
$dictMap = array_column($dictData, null, 'key'); // 以 key 字段为索引 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 构建字段 => 字典项的映射 |
|
|
|
|
|
$result = []; |
|
|
|
|
|
foreach ($fieldDictMapping as $field => $key) { |
|
|
|
|
|
$result[$field] = $dictMap[$key]['dictionary'] ?? []; |
|
|
|
|
|
//判断是不是获取的"来源渠道"的字典 |
|
|
|
|
|
if($field == 'source_channel'){ |
|
|
|
|
|
$append_arr = [ |
|
|
|
|
|
"name" => "线下", |
|
|
|
|
|
"value" => "0", |
|
|
|
|
|
"sort" => 0, |
|
|
|
|
|
"memo" => "", |
|
|
|
|
|
]; |
|
|
|
|
|
//插入到数组头部 |
|
|
|
|
|
array_unshift($result[$field],$append_arr); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return $result; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|