From cc1a20a70535cc28d471b73038fd6922887ce4d1 Mon Sep 17 00:00:00 2001 From: wangzeyan <258785420@qq.com> Date: Sat, 14 Jun 2025 08:47:12 +0800 Subject: [PATCH] =?UTF-8?q?feat(app):=20=E6=B7=BB=E5=8A=A0=E8=B5=84?= =?UTF-8?q?=E6=BA=90=E8=87=AA=E5=8A=A8=E5=88=86=E9=85=8D=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=B9=B6=E4=BC=98=E5=8C=96=E5=AE=A2=E6=88=B7=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增资源自动分配任务和相关配置 - 客户资源添加和编辑接口增加角色类型和体验课数量字段 - 统计接口增加已分配资源数量统计 - 优化客户资源查询和日志列表接口 --- .../apiController/CustomerResources.php | 51 +++++++------------ .../controller/apiController/Statistics.php | 9 ++-- niucloud/app/common.php | 4 +- .../api/apiService/ResourceSharingService.php | 48 +++++++++-------- 4 files changed, 51 insertions(+), 61 deletions(-) diff --git a/niucloud/app/api/controller/apiController/CustomerResources.php b/niucloud/app/api/controller/apiController/CustomerResources.php index ffcf7027..2f144fbe 100644 --- a/niucloud/app/api/controller/apiController/CustomerResources.php +++ b/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}"); - } } diff --git a/niucloud/app/api/controller/apiController/Statistics.php b/niucloud/app/api/controller/apiController/Statistics.php index 0ed9996e..1f9fa5be 100644 --- a/niucloud/app/api/controller/apiController/Statistics.php +++ b/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' => [ diff --git a/niucloud/app/common.php b/niucloud/app/common.php index 86381b34..c3e56fb4 100644 --- a/niucloud/app/common.php +++ b/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'; } \ No newline at end of file diff --git a/niucloud/app/service/api/apiService/ResourceSharingService.php b/niucloud/app/service/api/apiService/ResourceSharingService.php index 58a672f9..d8dff106 100644 --- a/niucloud/app/service/api/apiService/ResourceSharingService.php +++ b/niucloud/app/service/api/apiService/ResourceSharingService.php @@ -40,48 +40,51 @@ 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'); - //查当前用户校区下的全部员工id - $person_id_arr = CampusPersonRole::whereIn('campus_id',$campus_id) - ->distinct(true) - ->column('person_id'); + if ($campus_id) { + //查当前用户校区下的全部员工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){ - $query->append(['initial_intent_name']); + 'customerResource' => function ($query) { + $query->append(['initial_intent_name']); } ])->paginate([ 'list_rows' => $limit, @@ -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'])) {