You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
204 lines
12 KiB
204 lines
12 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Niucloud-admin 企业快速开发的多应用管理平台
|
|
// +----------------------------------------------------------------------
|
|
// | 官方网址:https://www.niucloud.com
|
|
// +----------------------------------------------------------------------
|
|
// | niucloud团队 版权所有 开源版本可自由商用
|
|
// +----------------------------------------------------------------------
|
|
// | Author: Niucloud Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\api\controller\apiController;
|
|
|
|
use app\Request;
|
|
use app\service\api\apiService\CommonService;
|
|
use core\base\BaseApiService;
|
|
use app\model\customer_resources\CustomerResources;
|
|
use think\facade\Db;
|
|
|
|
/**
|
|
* 统计控制器相关接口
|
|
* Class Personnel
|
|
* @package app\api\controller\apiController
|
|
*/
|
|
class Statistics extends BaseApiService
|
|
{
|
|
|
|
/**
|
|
* 员工端统计(销售)-获取销售首页数据统计
|
|
*/
|
|
public function marketHome(Request $request)
|
|
{
|
|
$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('缺少参数');
|
|
}
|
|
$firstDayOfMonth = date('m月01日'); // 获取本月第一天
|
|
$lastDayOfMonth = date('m月t日'); // 获取本月最后一天
|
|
$dateRange = "{$firstDayOfMonth}-{$lastDayOfMonth}"; // 拼接日期范围字符串
|
|
|
|
// $role_key_arr = ['sale'];//@todo 调试使用
|
|
|
|
if(in_array('market',$role_key_arr) || in_array('market_manager',$role_key_arr)){
|
|
//市场人员统计数据(地推拉人头的)
|
|
$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')
|
|
->whereIn('resource_id', function($query) {
|
|
$query->table('school_customer_resources')
|
|
->where('consultant', 1)
|
|
->field('id');
|
|
})
|
|
->where('user_id', '<>', 1)
|
|
->group('resource_id')
|
|
->count();
|
|
$data = [
|
|
'date_range'=>$dateRange,//拼接日期范围字符串
|
|
'role_type'=>'market_type',//角色类型|market_type=市场,sale_type=销售
|
|
// 本月总数
|
|
//本月
|
|
'month' => [
|
|
'new_total' => $monthtotal,//拉新总人数
|
|
'new_total_rate' => $alltotal ? round($monthtotal/$alltotal*100,2) : 0,//拉新总人数比例(不超过100%)
|
|
'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 / $alltotal * 100, 2)),//昨日拉新比例(不超过100%)
|
|
'today_new' => ($todayNew = rand(1, 20)),//今日拉新
|
|
'today_new_rate' => min(100, round($todayNew / $alltotal * 100, 2)),//今日拉新比例(不超过100%)
|
|
],
|
|
//上月
|
|
'last_month' => [
|
|
'new_total' => ($lastNewTotal = rand(80, 400)),//拉新总人数
|
|
'new_total_rate' => min(100, round($lastNewTotal / 800 * 100, 2)),//拉新总人数比例(不超过100%)
|
|
'assigned_sales' => ($lastAssignedSales = rand(40, 250)),//已分配给销售的人数
|
|
'assigned_sales_rate' => min(100, round($lastAssignedSales / $lastNewTotal * 100, 2)),//已分配给销售的人数比例(不超过100%)
|
|
'yesterday_new' => ($lastYesterdayNew = rand(3, 40)),//昨日拉新人数
|
|
'yesterday_new_rate' => min(100, round($lastYesterdayNew / $lastNewTotal * 100, 2)),//昨日拉新人数比例(不超过100%)
|
|
'today_new' => ($lastTodayNew = rand(1, 15)),//今日拉新人数
|
|
'today_new_rate' => min(100, round($lastTodayNew / $lastNewTotal * 100, 2)),//今日拉新人数比例(不超过100%)
|
|
]
|
|
];
|
|
}elseif(in_array('sale',$role_key_arr) || in_array('sale_manager',$role_key_arr)){
|
|
//销售人员统计数据(买课的)
|
|
$data = [
|
|
'date_range'=>$dateRange,//拼接日期范围字符串
|
|
'role_type'=>'sale_type',//角色类型|market_type=市场,sale_type=销售 infoData.month
|
|
//本月
|
|
'month' => [
|
|
'assigned_clients' => ($assigned = rand(50, 300)),//分配给我的客户人数
|
|
'contacted_clients' => ($contacted = rand(20, 150)),//已沟通的客户人数
|
|
'contact_rate' => min(100, round($contacted / $assigned * 100, 2)),//沟通率(不超过100%)
|
|
'unconverted_clients' => ($unconverted = rand(10, 50)),//已沟通但没成交的客户人数
|
|
'unconverted_rate' => min(100, round($unconverted / $contacted * 100, 2)),//未成交率(不超过100%)
|
|
'renewal_clients' => ($renewal = rand(5, 30)),//待续费的客户人数
|
|
'renewal_rate' => min(100, round($renewal / $assigned * 100, 2)),//待续费率(不超过100%)
|
|
'closed_clients' => ($closed = rand(1, 20)),//已关单的客户人数
|
|
'closed_rate' => min(100, round($closed / $contacted * 100, 2)),//关单率(不超过100%)
|
|
'conversion_rate' => min(100, round($closed / $assigned * 100, 2)),//整体转化率(不超过100%)
|
|
],
|
|
//上月
|
|
'last_month' => [
|
|
'assigned_clients' => ($lastAssigned = rand(40, 250)),//分配给我的客户人数
|
|
'contacted_clients' => ($lastContacted = rand(15, 120)),//已沟通的客户人数
|
|
'contact_rate' => min(100, round($lastContacted / $lastAssigned * 100, 2)),//沟通率(不超过100%)
|
|
'unconverted_clients' => ($lastUnconverted = rand(8, 40)),//已沟通但没成交的客户人数
|
|
'unconverted_rate' => min(100, round($lastUnconverted / $lastContacted * 100, 2)),//未成交率(不超过100%)
|
|
'renewal_clients' => ($lastRenewal = rand(3, 25)),//待续费的客户人数
|
|
'renewal_rate' => min(100, round($lastRenewal / $lastAssigned * 100, 2)),//待续费率(不超过100%)
|
|
'closed_clients' => ($lastClosed = rand(1, 15)),//已关单的客户人数
|
|
'closed_rate' => min(100, round($lastClosed / $lastContacted * 100, 2)),//关单率(不超过100%)
|
|
'conversion_rate' => min(100, round($lastClosed / $lastAssigned * 100, 2)),//整体转化率(不超过100%)
|
|
]
|
|
];
|
|
}else{
|
|
return fail('角色权限不正确');
|
|
}
|
|
|
|
|
|
return success($data);
|
|
}
|
|
|
|
/**
|
|
* 员工端统计(销售)-获取销售数据页统计
|
|
*/
|
|
public function marketData(Request $request)
|
|
{
|
|
$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('缺少参数');
|
|
}
|
|
|
|
// $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)],
|
|
],
|
|
];
|
|
}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);
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|