Browse Source

refactor(app): 重构市场人员统计功能

- 移除了未使用的 marketMy 方法
- 优化了 marketData 方法,支持不同角色的统计需求
- 添加了参数验证和角色权限检查
-生成模拟数据以满足前端展示需求
master
liutong 10 months ago
parent
commit
69315fe694
  1. 92
      niucloud/app/api/controller/apiController/Statistics.php
  2. 2
      niucloud/app/api/route/route.php

92
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);
}
}

2
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');

Loading…
Cancel
Save