Browse Source

Merge branch 'master' of http://gitlab.frkj.cc/php/zhjwxt into yuhongzhe

yuhongzhe
于宏哲PHP 10 months ago
parent
commit
d6b8197495
  1. 28
      niucloud/app/api/controller/apiController/CustomerResources.php
  2. 3
      niucloud/app/api/route/route.php
  3. 27
      niucloud/app/model/customer_resources/CustomerResources.php
  4. 21
      niucloud/app/model/six_speed/SixSpeed.php
  5. 258
      niucloud/app/service/api/apiService/CustomerResourcesService.php

28
niucloud/app/api/controller/apiController/CustomerResources.php

@ -152,5 +152,33 @@ class CustomerResources extends BaseApiService
return success([]); return success([]);
} }
//客户资源-修改记录列表
public function getEditLogList(Request $request){
//前端要传递分页(page,limit)参数
$customer_resource_id = $request->param('customer_resource_id','');
$type = $request->param('type','resource');//查询类型|resource=客户资源,six_speed=六要素
if(empty($customer_resource_id) || empty($type)){
return fail('缺少必要参数');
}
if(!in_array($type,['resource','six_speed'])){
return fail('类型不正确');
}
$where = [
'customer_resource_id' =>$customer_resource_id
];
if($type == 'resource'){
//resource=客户资源
$res =(new CustomerResourcesService())->getCustomerResourceChangesEditLog($where);
}else{
$res =(new CustomerResourcesService())->getSixSpeedModificationEditLog($where);
}
return success($res);
}
} }

3
niucloud/app/api/route/route.php

@ -208,6 +208,9 @@ Route::group(function () {
Route::post('customerResources/add', 'apiController.CustomerResources/add'); Route::post('customerResources/add', 'apiController.CustomerResources/add');
//客户资源-编辑 //客户资源-编辑
Route::post('customerResources/edit', 'apiController.CustomerResources/edit'); Route::post('customerResources/edit', 'apiController.CustomerResources/edit');
//客户资源-修改记录列表
Route::get('customerResources/getEditLogList', 'apiController.CustomerResources/getEditLogList');
//资源共享-列表 //资源共享-列表
Route::get('resourceSharing/index', 'apiController.ResourceSharing/index'); Route::get('resourceSharing/index', 'apiController.ResourceSharing/index');

27
niucloud/app/model/customer_resources/CustomerResources.php

@ -57,6 +57,33 @@ class CustomerResources extends BaseModel
*/ */
protected $defaultSoftDelete = 0; protected $defaultSoftDelete = 0;
//定义一个常量数组-字段中文映射
const FieldZh = [
'id' => '编号',
'create_year_month' => '创建年月',
'create_date' => '创建日期',
'source_channel' => '来源渠道',
'source' => '来源',
'consultant' => '顾问',
'name' => '姓名',
'age' => '年龄',
'gender' => '性别',
'phone_number' => '联系电话',
'demand' => '需求',
'purchasing_power' => '购买力',
'cognitive_idea' => '认知理念',
'optional_class_time' => '可选上课时间',
'distance' => '距离',
'decision_maker' => '决策人',
'initial_intent' => '客户初步意向度',
'campus' => '所属校区',
'trial_class_count' => '体验课次数',
'created_at' => '创建时间',
'updated_at' => '更新时间',
'deleted_at' => '逻辑删除时间',
'status' => '客户状态',
];
/** /**
* 搜索器:客户资源姓名 * 搜索器:客户资源姓名
* @param $value * @param $value

21
niucloud/app/model/six_speed/SixSpeed.php

@ -57,7 +57,26 @@ class SixSpeed extends BaseModel
//定义一个常量数组-字段中文映射
const FieldZh = [
'id' => '编号',
'purchase_power' => '需求购买力',
'concept_awareness' => '认知理念',
'preferred_class_time' => '可选上课时间',
'distance' => '距离',
'communication' => '沟通备注',
'promised_visit_time' => '承诺到访时间',
'actual_visit_time' => '实际到访时间',
'call_intent' => '电话后的意向程度',
'first_visit_status' => '一访情况',
'second_visit_status' => '二访情况',
'is_closed' => '是否关单',
'staff_id' => '人员ID',
'resource_id' => '资源ID',
'created_at' => '创建时间',
'updated_at' => '更新时间',
'deleted_at' => '逻辑删除时间'
];
public function personnel(){ public function personnel(){

258
niucloud/app/service/api/apiService/CustomerResourcesService.php

@ -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;
}
} }

Loading…
Cancel
Save