|
|
|
@ -37,17 +37,18 @@ class CustomerResourcesService extends BaseApiService |
|
|
|
} |
|
|
|
|
|
|
|
//获取客户资源详情 |
|
|
|
public function getInfo(array $where,string $field = '*'){ |
|
|
|
public function getInfo(array $where, string $field = '*') |
|
|
|
{ |
|
|
|
$res = [ |
|
|
|
'code' => 0, |
|
|
|
'msg' => '操作失败', |
|
|
|
'data' => [] |
|
|
|
]; |
|
|
|
$model = new CustomerResources(); |
|
|
|
if(!empty($where['member_id'])){ |
|
|
|
if (!empty($where['member_id'])) { |
|
|
|
$model = $model->where('member_id', $where['member_id']); |
|
|
|
} |
|
|
|
if(!empty($where['phone_number'])){ |
|
|
|
if (!empty($where['phone_number'])) { |
|
|
|
$model = $model->where('phone_number', $where['phone_number']); |
|
|
|
} |
|
|
|
$data = $model->field($field) |
|
|
|
@ -60,30 +61,30 @@ class CustomerResourcesService extends BaseApiService |
|
|
|
'initial_intent_name' |
|
|
|
]) |
|
|
|
->find(); |
|
|
|
if ($data){ |
|
|
|
if ($data) { |
|
|
|
$data = $data->toArray(); |
|
|
|
$res['code'] = 1; |
|
|
|
$res['data'] = $data; |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
$res['msg'] = '暂无数据'; |
|
|
|
} |
|
|
|
return $res; |
|
|
|
} |
|
|
|
|
|
|
|
//获取全部客户资源数据 |
|
|
|
public function getAll(array $where,string $field = '*') |
|
|
|
public function getAll(array $where, string $field = '*') |
|
|
|
{ |
|
|
|
$res = [ |
|
|
|
'code' => 0, |
|
|
|
'msg' => '操作失败', |
|
|
|
'data' => [] |
|
|
|
]; |
|
|
|
if(!$where){ |
|
|
|
if (!$where) { |
|
|
|
$res['msg'] = '查询条件不能为空'; |
|
|
|
return $res; |
|
|
|
} |
|
|
|
$model = new CustomerResources(); |
|
|
|
if(!empty($where['name'])){ |
|
|
|
if (!empty($where['name'])) { |
|
|
|
$model = $model->where('name', 'like', "%{$where['name']}%"); |
|
|
|
} |
|
|
|
$data = $model->field($field) |
|
|
|
@ -153,10 +154,11 @@ class CustomerResourcesService extends BaseApiService |
|
|
|
'event_type' => 'add'//事件类型"add=添加,edit=修改 |
|
|
|
];//事件类型"add=添加,edit=修改 |
|
|
|
|
|
|
|
Event::trigger('CalculatePerformance', $event_data)->queue(); |
|
|
|
Event::trigger('CalculatePerformance', $event_data, true); |
|
|
|
return $res; |
|
|
|
} catch (\Exception $exception) { |
|
|
|
Db::rollback(); |
|
|
|
$res['msg'] = $exception->getMessage(); |
|
|
|
return $res; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -199,9 +201,9 @@ class CustomerResourcesService extends BaseApiService |
|
|
|
if ($customer_resources) { |
|
|
|
$customer_resources = $customer_resources->toArray(); |
|
|
|
|
|
|
|
if(!$customer_resources['member_id'] && $six_speed){ |
|
|
|
if (!$customer_resources['member_id'] && $six_speed) { |
|
|
|
//新数据存在一访问 或者旧数据存在一访的情况 && 这用户没注册过member账号的情况下才给他创建member账号 |
|
|
|
if(!empty($six_speed_data['first_visit_status']) || $six_speed['first_visit_status']){ |
|
|
|
if (!empty($six_speed_data['first_visit_status']) || $six_speed['first_visit_status']) { |
|
|
|
$sex = 0; |
|
|
|
switch ($customer_resources_data['gender']) { |
|
|
|
case 'male'://男 |
|
|
|
@ -217,16 +219,16 @@ class CustomerResourcesService extends BaseApiService |
|
|
|
$password = create_password($customer_resources_data['phone_number']);//创建密码 |
|
|
|
//给用户创建member账号 |
|
|
|
$member_id = Member::insertGetId([ |
|
|
|
'username'=>$customer_resources_data['phone_number'],//会员用户名 |
|
|
|
'mobile'=>$customer_resources_data['phone_number'],//手机号 |
|
|
|
'password'=>$password,//会员密码 |
|
|
|
'nickname'=>$customer_resources_data['name'],//会员昵称 |
|
|
|
'sex'=>$sex,//性别 0保密 1男 2女 |
|
|
|
'member_time'=>time(),//成为会员时间 |
|
|
|
'username' => $customer_resources_data['phone_number'],//会员用户名 |
|
|
|
'mobile' => $customer_resources_data['phone_number'],//手机号 |
|
|
|
'password' => $password,//会员密码 |
|
|
|
'nickname' => $customer_resources_data['name'],//会员昵称 |
|
|
|
'sex' => $sex,//性别 0保密 1男 2女 |
|
|
|
'member_time' => time(),//成为会员时间 |
|
|
|
]); |
|
|
|
if($member_id){ |
|
|
|
if ($member_id) { |
|
|
|
$customer_resources_data['member_id'] = $member_id; |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
Db::rollback(); |
|
|
|
$res['msg'] = '创建用户账号失败'; |
|
|
|
return $res; |
|
|
|
@ -424,13 +426,13 @@ class CustomerResourcesService extends BaseApiService |
|
|
|
$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(客户状态) |
|
|
|
'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);//字段与字典值列表的映射关系 |
|
|
|
|
|
|
|
@ -441,16 +443,16 @@ class CustomerResourcesService extends BaseApiService |
|
|
|
$new_values_arr = json_decode($v['new_values'], true); |
|
|
|
|
|
|
|
//判断有没有修改过"顾问"字段 |
|
|
|
if(in_array('consultant',$modified_fields_arr)){ |
|
|
|
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){ |
|
|
|
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'], |
|
|
|
@ -474,13 +476,13 @@ class CustomerResourcesService extends BaseApiService |
|
|
|
$old_value = $old_values_arr[$m_v] ?? ''; |
|
|
|
$new_value = $new_values_arr[$m_v] ?? ''; |
|
|
|
|
|
|
|
if(in_array($m_v,$fieldDictKeyArr)){ |
|
|
|
if (in_array($m_v, $fieldDictKeyArr)) { |
|
|
|
$dict = $dict_arr[$m_v]; |
|
|
|
foreach($dict as $d_v){ |
|
|
|
if($d_v['value'] == $old_value){ |
|
|
|
foreach ($dict as $d_v) { |
|
|
|
if ($d_v['value'] == $old_value) { |
|
|
|
$old_value = $d_v['name']; |
|
|
|
} |
|
|
|
if($d_v['value'] == $new_value){ |
|
|
|
if ($d_v['value'] == $new_value) { |
|
|
|
$new_value = $d_v['name']; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -533,10 +535,10 @@ class CustomerResourcesService extends BaseApiService |
|
|
|
$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-否) |
|
|
|
'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);//字段与字典值列表的映射关系 |
|
|
|
|
|
|
|
@ -547,16 +549,16 @@ class CustomerResourcesService extends BaseApiService |
|
|
|
$new_values_arr = json_decode($v['new_value'], true); |
|
|
|
|
|
|
|
//判断有没有修改过"顾问(人员)"字段 |
|
|
|
if(in_array('staff_id',$modified_fields_arr)){ |
|
|
|
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){ |
|
|
|
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'], |
|
|
|
@ -580,13 +582,13 @@ class CustomerResourcesService extends BaseApiService |
|
|
|
$old_value = $old_values_arr[$m_v] ?? ''; |
|
|
|
$new_value = $new_values_arr[$m_v] ?? ''; |
|
|
|
|
|
|
|
if(in_array($m_v,$fieldDictKeyArr)){ |
|
|
|
if (in_array($m_v, $fieldDictKeyArr)) { |
|
|
|
$dict = $dict_arr[$m_v]; |
|
|
|
foreach($dict as $d_v){ |
|
|
|
if($d_v['value'] == $old_value){ |
|
|
|
foreach ($dict as $d_v) { |
|
|
|
if ($d_v['value'] == $old_value) { |
|
|
|
$old_value = $d_v['name']; |
|
|
|
} |
|
|
|
if($d_v['value'] == $new_value){ |
|
|
|
if ($d_v['value'] == $new_value) { |
|
|
|
$new_value = $d_v['name']; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -643,7 +645,7 @@ class CustomerResourcesService extends BaseApiService |
|
|
|
foreach ($fieldDictMapping as $field => $key) { |
|
|
|
$result[$field] = $dictMap[$key]['dictionary'] ?? []; |
|
|
|
//判断是不是获取的"来源渠道"的字典 |
|
|
|
if($field == 'source_channel'){ |
|
|
|
if ($field == 'source_channel') { |
|
|
|
$append_arr = [ |
|
|
|
"name" => "线下", |
|
|
|
"value" => "0", |
|
|
|
@ -651,7 +653,7 @@ class CustomerResourcesService extends BaseApiService |
|
|
|
"memo" => "", |
|
|
|
]; |
|
|
|
//插入到数组头部 |
|
|
|
array_unshift($result[$field],$append_arr); |
|
|
|
array_unshift($result[$field], $append_arr); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|