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. 16
      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'); $date = date('Y-m-d');
$param = $request->param();
$promised_visit_time = $request->param('promised_visit_time', ''); $promised_visit_time = $request->param('promised_visit_time', '');
if ($promised_visit_time) { if ($promised_visit_time) {
$promised_visit_time = date('Y-m-d H:i:s', strtotime($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') ->join(['school_campus_person_role' => 'b'], 'a.id = b.person_id', 'left')
->where(['a.id' => $request->param('consultant', '')]) ->where(['a.id' => $request->param('consultant', '')])
->value('b.role_id'); ->value('b.role_id');
$customer_resources_data = [ $customer_resources_data = [
"create_year_month" => date('Y-m'), "create_year_month" => date('Y-m'),
"create_date" => $date, "create_date" => $date,
"source_channel" => $request->param('source_channel', ''), "source_channel" => $param['source_channel'] ?? '',
"source" => $request->param('source', ''), "source" => $param['source'] ?? '',
"consultant" => $request->param('consultant', ''), "consultant" => $param['consultant'] ?? 0,
"name" => $request->param('name', ''), "name" => $param['name'] ?? '',
"age" => $request->param('age', ''), "gender" => $param['gender'] ?? 'other',//性别
"gender" => $request->param('gender', ''), "phone_number" => $param['phone_number'] ?? '',
"phone_number" => $request->param('phone_number', ''), "demand" => $param['demand'] ?? '',
"demand" => $request->param('demand', ''), "decision_maker" => $param['decision_maker'] ?? 0,
"decision_maker" => $request->param('decision_maker', ''), "initial_intent" => $param['initial_intent'] ?? 'low',//客户初步意向度
"initial_intent" => $request->param('initial_intent', ''), "status" => $param['status'] ?? 'pending',//客户状态
"status" => $request->param('status', ''), "purchasing_power" => $param['purchasing_power'],
"purchasing_power" => $request->param('purchasing_power', ''), "cognitive_idea" => $param['cognitive_idea'],
"cognitive_idea" => $request->param('cognitive_idea', ''),
"optional_class_time" => $optional_class_time, "optional_class_time" => $optional_class_time,
"distance" => $request->param('distance', ''), "distance" => $param['distance'],
// 新资源有2节体验课 // 新资源有2节体验课
"trial_class_count" => 2, "trial_class_count" => 2,
"rf_type" => get_role_type($role_id), "rf_type" => get_role_type($role_id),
@ -104,19 +104,12 @@ class CustomerResources extends BaseApiService
return fail("联系电话不能超过12位"); 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']]); $info = (new CustomerResourcesService())->getInfo(['phone_number' => $customer_resources_data['phone_number']]);
if (!empty($info['data']['id'])) { if (!empty($info['data']['id'])) {
return fail("手机号已存在"); return fail("手机号已存在");
} }
$res = (new CustomerResourcesService())->addData($customer_resources_data, $six_speed_data); $res = (new CustomerResourcesService())->addData($customer_resources_data, $six_speed_data);
if (!$res['code']) { if (!$res['code']) {
return fail($res['msg']); return fail($res['msg']);
@ -158,12 +151,12 @@ class CustomerResources extends BaseApiService
"source" => $request->param('source', ''),//来源 "source" => $request->param('source', ''),//来源
"name" => $request->param('name', ''),//姓名 "name" => $request->param('name', ''),//姓名
"age" => $request->param('age', ''),//年龄 "age" => $request->param('age', ''),//年龄
"gender" => $request->param('gender', ''),//性别 "gender" => $request->param('gender', 'other'),//性别
"phone_number" => $request->param('phone_number', ''),//联系电话 "phone_number" => $request->param('phone_number', ''),//联系电话
"demand" => $request->param('demand', ''),//需求 "demand" => $request->param('demand', ''),//需求
"decision_maker" => $request->param('decision_maker', ''),//决策人 "decision_maker" => $request->param('decision_maker', ''),//决策人
"initial_intent" => $request->param('initial_intent', ''),//客户初步意向度 "initial_intent" => $request->param('initial_intent', 'low'),//客户初步意向度
"status" => $request->param('status', ''),//客户状态 "status" => $request->param('status', 'pending'),//客户状态
"purchasing_power" => $request->param('purchasing_power', ''),//购买力 "purchasing_power" => $request->param('purchasing_power', ''),//购买力
"cognitive_idea" => $request->param('cognitive_idea', ''),//认知理念 "cognitive_idea" => $request->param('cognitive_idea', ''),//认知理念
"optional_class_time" => $optional_class_time,//可选上课时间 "optional_class_time" => $optional_class_time,//可选上课时间
@ -184,11 +177,6 @@ class CustomerResources extends BaseApiService
"second_visit_status" => $request->param('second_visit_status', null),//二访情况 "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) { if (strlen($customer_resources_data['phone_number']) > 12) {
return fail("联系电话不能超过12位"); return fail("联系电话不能超过12位");
@ -204,9 +192,6 @@ class CustomerResources extends BaseApiService
if (in_array($k, ['first_visit_status', 'second_visit_status'])) { if (in_array($k, ['first_visit_status', 'second_visit_status'])) {
continue; 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)){ 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'); $alltotal = CustomerResources::where('consultant',$personnel_id)->count('id');
//已分配的数量 //已分配的数量
$yfpsl = Db::table('school_resource_sharing') $yfpsl = Db::table('school_resource_sharing')
@ -54,7 +55,7 @@ class Statistics extends BaseApiService
->where('consultant', 1) ->where('consultant', 1)
->field('id'); ->field('id');
}) })
->where('user_id', '!=', 1) ->where('user_id', '<>', 1)
->group('resource_id') ->group('resource_id')
->count(); ->count();
$data = [ $data = [
@ -68,9 +69,9 @@ class Statistics extends BaseApiService
'assigned_sales' => $yfpsl, 'assigned_sales' => $yfpsl,
'assigned_sales_rate' => $alltotal ? round($yfpsl/$alltotal*100,2) : 0,//已分配给销售的人数比例(不超过100%) 'assigned_sales_rate' => $alltotal ? round($yfpsl/$alltotal*100,2) : 0,//已分配给销售的人数比例(不超过100%)
'yesterday_new' => ($yesterdayNew = rand(5, 50)),//昨日拉新 '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' => ($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' => [ 'last_month' => [

4
niucloud/app/common.php

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

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

@ -43,10 +43,12 @@ class ResourceSharingService extends BaseApiService
$campus_id = CampusPersonRole::where('person_id', $person_id) $campus_id = CampusPersonRole::where('person_id', $person_id)
->distinct(true) ->distinct(true)
->column('campus_id'); ->column('campus_id');
if ($campus_id) {
//查当前用户校区下的全部员工id //查当前用户校区下的全部员工id
$person_id_arr = CampusPersonRole::whereIn('campus_id', $campus_id) $person_id_arr = CampusPersonRole::whereIn('campus_id', $campus_id)
->distinct(true) ->distinct(true)
->column('person_id'); ->column('person_id');
}
$resource_id_arr = [];//客户资源表id $resource_id_arr = [];//客户资源表id
//客户资源表名字 //客户资源表名字
@ -68,16 +70,17 @@ class ResourceSharingService extends BaseApiService
$model = $model->whereIn('resource_id', $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 (!empty($where['shared_at_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->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([ $res = $model->with([
'customerResource' => function ($query) { 'customerResource' => function ($query) {
@ -121,7 +124,8 @@ class ResourceSharingService extends BaseApiService
'concept_awareness_name',//认知理念 'concept_awareness_name',//认知理念
]); ]);
}, },
'personnel'=>function($query_2){} 'personnel' => function ($query_2) {
}
])->append([ ])->append([
'source_channel_name',//来源渠道 'source_channel_name',//来源渠道
'source_name',//来源 'source_name',//来源

Loading…
Cancel
Save