From 69315fe69437f4e6700bf7dd1f0604c805caf1c3 Mon Sep 17 00:00:00 2001 From: liutong <836164388@qq.com> Date: Fri, 30 May 2025 21:55:06 +0800 Subject: [PATCH] =?UTF-8?q?refactor(app):=20=E9=87=8D=E6=9E=84=E5=B8=82?= =?UTF-8?q?=E5=9C=BA=E4=BA=BA=E5=91=98=E7=BB=9F=E8=AE=A1=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除了未使用的 marketMy 方法 - 优化了 marketData 方法,支持不同角色的统计需求 - 添加了参数验证和角色权限检查 -生成模拟数据以满足前端展示需求 --- .../controller/apiController/Statistics.php | 92 ++++++++++++------- niucloud/app/api/route/route.php | 2 - 2 files changed, 61 insertions(+), 33 deletions(-) diff --git a/niucloud/app/api/controller/apiController/Statistics.php b/niucloud/app/api/controller/apiController/Statistics.php index 4e3ea205..ad4fe7d9 100644 --- a/niucloud/app/api/controller/apiController/Statistics.php +++ b/niucloud/app/api/controller/apiController/Statistics.php @@ -38,7 +38,7 @@ class Statistics extends BaseApiService $lastDayOfMonth = date('m月t日'); // 获取本月最后一天 $dateRange = "{$firstDayOfMonth}-{$lastDayOfMonth}"; // 拼接日期范围字符串 -// $role_key_arr = ['sale']; +// $role_key_arr = ['sale'];//@todo 调试使用 if(in_array('market',$role_key_arr) || in_array('market_manager',$role_key_arr)){ //市场人员统计数据(地推拉人头的) @@ -113,45 +113,75 @@ class Statistics extends BaseApiService */ public function marketData(Request $request) { - $userRole = 'sale';////sale=普通销售,sale_manager=销售主管,market=市场员工,market_manager=市场主管,teacher=教练员工,teacher_manager=教练主管 - if($userRole == 'sale'){ - //销售人员统计数据 - $data = [ - //本月 - 'month' => [], - //上月 - 'last_month' => [] - ]; - }else{ - //市场人员统计数据 - $data = [ - //本月 - 'month' => [], - //上月 - 'last_month' => [] - ]; + $personnel_id = $request->param('personnel_id','');//员工表id + $role_key_arr = $request->param('role_key_arr','');//array 角色key + $role_key_arr = explode(',',$role_key_arr); + if(empty($personnel_id)|| empty($role_key_arr)){ + return fail('缺少参数'); } - return success($data); - } - /** - * 员工端统计(销售)-获取个人中新页统计 - */ - public function marketMy(Request $request) - { - $userRole = 'sale';////sale=普通销售,sale_manager=销售主管,market=市场员工,market_manager=市场主管,teacher=教练员工,teacher_manager=教练主管 - if($userRole == 'sale'){ - //销售人员统计数据 +// $role_key_arr = ['sale'];//@todo 调试使用 + + if(in_array('market',$role_key_arr) || in_array('market_manager',$role_key_arr)){ + //市场人员统计数据(地推拉人头的) $data = [ + 'role_type'=>'market_type',//角色类型|market_type=市场,sale_type=销售 + 'num_1' => ($assigned = rand(20, 150)),//本周已分配 + 'num_2' => ($unassigned = rand(5, 50)),//本周未分配 + 'total_1' => ($newTotal = $assigned + $unassigned),//本周拉新总数 + 'total_2' => ($lastWeekNewTotal = rand(10, 100)),//上周拉新总数 + + 'num_1_rate' => min(100, round($assigned / $newTotal * 100, 2)),//已分配比例 + 'num_2_rate' => min(100, round($unassigned / $newTotal * 100, 2)),//未分配比例 + 'num_3_rate' => min(100, round($newTotal / max(1, $lastWeekNewTotal) * 100, 2)), // 本周拉新率(对比上周) + 'num_4_rate' => min(100, round($assigned / max(1, $lastWeekNewTotal) * 100, 2)), // 本周分配率(对比上周) + 'staff_list' => [ + ['name' => '张三', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '李四', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '王五', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '赵六', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '钱七', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '孙八', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '周九', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '吴十', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '郑十一', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '王十二', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ], ]; - }else{ - //市场人员统计数据 + }elseif(in_array('sale',$role_key_arr) || in_array('sale_manager',$role_key_arr)){ + //销售人员统计数据(买课的) $data = [ - //业绩单人数已签单人数已签 + 'role_type'=>'sale',//角色类型|market_type=市场,sale_type=销售 + + 'num_1' => ($assigned = rand(20, 150)),//本周已分配 + 'num_2' => ($unassigned = rand(5, 50)),//本周未分配 + 'total_1' => ($newTotal = $assigned + $unassigned),//本周拉新总数 + 'total_2' => ($lastWeekNewTotal = rand(10, 100)),//上周拉新总数 + + 'num_1_rate' => min(100, round($assigned / $newTotal * 100, 2)),//已分配比例 + 'num_2_rate' => min(100, round($unassigned / $newTotal * 100, 2)),//未分配比例 + 'num_3_rate' => min(100, round($newTotal / max(1, $lastWeekNewTotal) * 100, 2)), // 本周拉新率(对比上周) + 'num_4_rate' => min(100, round($assigned / max(1, $lastWeekNewTotal) * 100, 2)), // 本周分配率(对比上周) + 'staff_list' => [ + ['name' => '张三', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '李四', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '王五', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '赵六', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '钱七', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '孙八', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '周九', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '吴十', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '郑十一', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ['name' => '王十二', 'goal' => rand(50, 200), 'wx_yj' => rand(30, 180)], + ], ]; + }else{ + return fail('角色权限不正确'); } return success($data); } + + } diff --git a/niucloud/app/api/route/route.php b/niucloud/app/api/route/route.php index 195b92be..9b55b060 100644 --- a/niucloud/app/api/route/route.php +++ b/niucloud/app/api/route/route.php @@ -220,8 +220,6 @@ Route::group(function () { Route::get('statistics/marketHome', 'apiController.Statistics/marketHome'); //员工端统计(销售)-获取销售数据页统计 Route::get('statistics/marketData', 'apiController.Statistics/marketData'); - //员工端统计(销售)-获取个人中新页统计 - Route::get('statistics/marketMy', 'apiController.Statistics/marketMy'); //客户资源-添加 Route::post('customerResources/add', 'apiController.CustomerResources/add');