Browse Source

feat(app): 添加资源自动分配功能并优化客户资源模块

- 新增资源自动分配任务和相关配置
- 客户资源添加和编辑接口增加角色类型和体验课数量字段
- 统计接口增加已分配资源数量统计
- 优化客户资源查询和日志列表接口
master
王泽彦 10 months ago
parent
commit
cc1a20a705
  1. 51
      niucloud/app/api/controller/apiController/CustomerResources.php
  2. 9
      niucloud/app/api/controller/apiController/Statistics.php
  3. 4
      niucloud/app/common.php
  4. 40
      niucloud/app/service/api/apiService/ResourceSharingService.php

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

@ -51,7 +51,7 @@ class CustomerResources extends BaseApiService
{
$date = date('Y-m-d');
$param = $request->param();
$promised_visit_time = $request->param('promised_visit_time', '');
if ($promised_visit_time) {
$promised_visit_time = date('Y-m-d H:i:s', strtotime($promised_visit_time));
@ -67,24 +67,24 @@ class CustomerResources extends BaseApiService
->join(['school_campus_person_role' => 'b'], 'a.id = b.person_id', 'left')
->where(['a.id' => $request->param('consultant', '')])
->value('b.role_id');
$customer_resources_data = [
"create_year_month" => date('Y-m'),
"create_date" => $date,
"source_channel" => $request->param('source_channel', ''),
"source" => $request->param('source', ''),
"consultant" => $request->param('consultant', ''),
"name" => $request->param('name', ''),
"age" => $request->param('age', ''),
"gender" => $request->param('gender', ''),
"phone_number" => $request->param('phone_number', ''),
"demand" => $request->param('demand', ''),
"decision_maker" => $request->param('decision_maker', ''),
"initial_intent" => $request->param('initial_intent', ''),
"status" => $request->param('status', ''),
"purchasing_power" => $request->param('purchasing_power', ''),
"cognitive_idea" => $request->param('cognitive_idea', ''),
"source_channel" => $param['source_channel'] ?? '',
"source" => $param['source'] ?? '',
"consultant" => $param['consultant'] ?? 0,
"name" => $param['name'] ?? '',
"gender" => $param['gender'] ?? 'other',//性别
"phone_number" => $param['phone_number'] ?? '',
"demand" => $param['demand'] ?? '',
"decision_maker" => $param['decision_maker'] ?? 0,
"initial_intent" => $param['initial_intent'] ?? 'low',//客户初步意向度
"status" => $param['status'] ?? 'pending',//客户状态
"purchasing_power" => $param['purchasing_power'],
"cognitive_idea" => $param['cognitive_idea'],
"optional_class_time" => $optional_class_time,
"distance" => $request->param('distance', ''),
"distance" => $param['distance'],
// 新资源有2节体验课
"trial_class_count" => 2,
"rf_type" => get_role_type($role_id),
@ -104,19 +104,12 @@ class CustomerResources extends BaseApiService
return fail("联系电话不能超过12位");
}
foreach ($six_speed_data as $k => $v) {
if (!isset($v) || $v === '') {
return fail("缺少必填项{$k}");
}
}
//验证手机号是否存在
$info = (new CustomerResourcesService())->getInfo(['phone_number' => $customer_resources_data['phone_number']]);
if (!empty($info['data']['id'])) {
return fail("手机号已存在");
}
$res = (new CustomerResourcesService())->addData($customer_resources_data, $six_speed_data);
if (!$res['code']) {
return fail($res['msg']);
@ -158,12 +151,12 @@ class CustomerResources extends BaseApiService
"source" => $request->param('source', ''),//来源
"name" => $request->param('name', ''),//姓名
"age" => $request->param('age', ''),//年龄
"gender" => $request->param('gender', ''),//性别
"gender" => $request->param('gender', 'other'),//性别
"phone_number" => $request->param('phone_number', ''),//联系电话
"demand" => $request->param('demand', ''),//需求
"decision_maker" => $request->param('decision_maker', ''),//决策人
"initial_intent" => $request->param('initial_intent', ''),//客户初步意向度
"status" => $request->param('status', ''),//客户状态
"initial_intent" => $request->param('initial_intent', 'low'),//客户初步意向度
"status" => $request->param('status', 'pending'),//客户状态
"purchasing_power" => $request->param('purchasing_power', ''),//购买力
"cognitive_idea" => $request->param('cognitive_idea', ''),//认知理念
"optional_class_time" => $optional_class_time,//可选上课时间
@ -184,11 +177,6 @@ class CustomerResources extends BaseApiService
"second_visit_status" => $request->param('second_visit_status', null),//二访情况
];
foreach ($customer_resources_data as $k => $v) {
if (!isset($v) || $v === '') {
return fail("缺少必填项{$k}");
}
}
if (strlen($customer_resources_data['phone_number']) > 12) {
return fail("联系电话不能超过12位");
@ -204,9 +192,6 @@ class CustomerResources extends BaseApiService
if (in_array($k, ['first_visit_status', 'second_visit_status'])) {
continue;
}
if (!isset($v) || $v === '') {
return fail("缺少必填项{$k}");
}
}

9
niucloud/app/api/controller/apiController/Statistics.php

@ -45,7 +45,8 @@ class Statistics extends BaseApiService
if(in_array('market',$role_key_arr) || in_array('market_manager',$role_key_arr)){
//市场人员统计数据(地推拉人头的)
$monthtotal = CustomerResources::where('consultant',$personnel_id)->where('create_time','between',[$firstDayOfMonth,$lastDayOfMonth])->count('id');
$monthtotal = CustomerResources::where('consultant',$personnel_id)
->where('created_at','between',[$firstDayOfMonth,$lastDayOfMonth])->count('id');
$alltotal = CustomerResources::where('consultant',$personnel_id)->count('id');
//已分配的数量
$yfpsl = Db::table('school_resource_sharing')
@ -54,7 +55,7 @@ class Statistics extends BaseApiService
->where('consultant', 1)
->field('id');
})
->where('user_id', '!=', 1)
->where('user_id', '<>', 1)
->group('resource_id')
->count();
$data = [
@ -68,9 +69,9 @@ class Statistics extends BaseApiService
'assigned_sales' => $yfpsl,
'assigned_sales_rate' => $alltotal ? round($yfpsl/$alltotal*100,2) : 0,//已分配给销售的人数比例(不超过100%)
'yesterday_new' => ($yesterdayNew = rand(5, 50)),//昨日拉新
'yesterday_new_rate' => min(100, round($yesterdayNew / $newTotal * 100, 2)),//昨日拉新比例(不超过100%)
'yesterday_new_rate' => min(100, round($yesterdayNew / $alltotal * 100, 2)),//昨日拉新比例(不超过100%)
'today_new' => ($todayNew = rand(1, 20)),//今日拉新
'today_new_rate' => min(100, round($todayNew / $newTotal * 100, 2)),//今日拉新比例(不超过100%)
'today_new_rate' => min(100, round($todayNew / $alltotal * 100, 2)),//今日拉新比例(不超过100%)
],
//上月
'last_month' => [

4
niucloud/app/common.php

@ -1264,6 +1264,6 @@ function get_role_type($role_id)
2 => 'sale',
3 => 'teacher'
];
$dept_id = \app\model\sys\SysRole::find($role_id)->value('dept_id');
return $role_type[$dept_id] ?? 'other';
$dept = \app\model\sys\SysRole::find($role_id);
return $role_type[$dept->dept_id] ?? 'other';
}

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

@ -40,47 +40,50 @@ class ResourceSharingService extends BaseApiService
$person_id = $this->member_id;//当前登录的员工id
//查当前用户的归属校区
$campus_id = CampusPersonRole::where('person_id',$person_id)
$campus_id = CampusPersonRole::where('person_id', $person_id)
->distinct(true)
->column('campus_id');
if ($campus_id) {
//查当前用户校区下的全部员工id
$person_id_arr = CampusPersonRole::whereIn('campus_id',$campus_id)
$person_id_arr = CampusPersonRole::whereIn('campus_id', $campus_id)
->distinct(true)
->column('person_id');
}
$resource_id_arr = [];//客户资源表id
//客户资源表名字
if(!empty($where['name'])){
if (!empty($where['name'])) {
$resource_id = (new CustomerResources())->where('name', 'like', "%{$where['name']}%")->column('id');
$resource_id_arr = array_merge($resource_id_arr,$resource_id);
$resource_id_arr = array_merge($resource_id_arr, $resource_id);
}
//客户资源表手机号
if(!empty($where['phone_number'])){
if (!empty($where['phone_number'])) {
$resource_id = (new CustomerResources())->where('phone_number', 'like', "%{$where['phone_number']}%")->column('id');
$resource_id_arr = array_merge($resource_id_arr,$resource_id);
$resource_id_arr = array_merge($resource_id_arr, $resource_id);
}
//去重
$resource_id_arr = array_unique($resource_id_arr);
$model = $this->model;
if($resource_id_arr){
$model = $model->whereIn('resource_id',$resource_id_arr);
}
if ((!empty($where['shared_by']) || isset($where['shared_by'])) && $where['shared_by'] !== '') {
$model = $model->where('shared_by', $where['shared_by']);
if ($resource_id_arr) {
$model = $model->whereIn('resource_id', $resource_id_arr);
}
if (!empty($where['shared_at_arr'])) {
$model = $model->where('shared_at', '>=', $where['shared_at_arr'][0])->where('shared_at', '<=', $where['shared_at_arr'][1]);
}
$model = $model->when(!empty($person_id_arr), function ($query) use ($person_id_arr) {
$query->whereIn('user_id', $person_id_arr);
});
$model = $model->whereIn('user_id', $person_id_arr);
if ((!empty($where['shared_by']) || isset($where['shared_by'])) && $where['shared_by'] !== '') {
$model = $model->whereOr('shared_by', $where['shared_by']);
}
//分页查询
$res = $model->with([
'customerResource'=>function($query){
'customerResource' => function ($query) {
$query->append(['initial_intent_name']);
}
])->paginate([
@ -113,15 +116,16 @@ class ResourceSharingService extends BaseApiService
}
$data = $model->with([
'customerResource'=>function($query){
'customerResource' => function ($query) {
$query->with([
'sixSpeed'=>function($query_2){
'sixSpeed' => function ($query_2) {
$query_2->append([
'purchase_power_name',//购买力
'concept_awareness_name',//认知理念
]);
},
'personnel'=>function($query_2){}
'personnel' => function ($query_2) {
}
])->append([
'source_channel_name',//来源渠道
'source_name',//来源
@ -133,7 +137,7 @@ class ResourceSharingService extends BaseApiService
]);
}
])->field($field)->find();
if($data){
if ($data) {
$data = $data->toArray();
}
if (!empty($data['customerResource'])) {

Loading…
Cancel
Save