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)){ $yesterdayStart = date('Y-m-d', strtotime('-1 day')); $lastMonthStart = date('Y-m', strtotime('-1 month')); $customer_list = $customerResources->where(['consultant' => $personnel_id])->select(); $newTotal = 0; $assignedSales = 0; $yesterdayNew = 0; $todayNew = 0; $yjsr = 0; $wfpsl = 0; $bytc = 0; $gdsl = 0; $lastNewTotal = 0; $lastAssignedSales = 0; foreach($customer_list as $item){ if($item['create_year_month'] == date("Y-m")){ $newTotal++; if($resourceSharing->where(['resource_id' => $item['id']])->find()){ $assignedSales++; } } if($item['create_year_month'] == $lastMonthStart){ $lastNewTotal++; if($resourceSharing->where(['resource_id' => $item['id']])->find()){ $lastAssignedSales++; } } if($item['create_date'] == $yesterdayStart){ $yesterdayNew++; } if($item['create_date'] == date("Y-m-d")){ $todayNew++; } if(!$resourceSharing->where(['resource_id' => $item['id']])->find()){ $wfpsl++; } if($order->where(['resource_id' => $item['id'],'order_type' => '1'])->find()){ if($six_speed->where(['resource_id' => $item['id'],'is_closed' => 1])->find()){ $gdsl++; } } } $yjsr = $market_performance->where([ 'performance_date' => date('Y-m-d'), 'personnel_id' => $personnel_id ])->Sum('performance_amount'); $bytc = $market_performance ->where(['personnel_id' => $personnel_id]) ->whereTime('performance_date', 'month') ->sum('performance_amount'); //市场人员统计数据(地推拉人头的) $data = [ 'date_range'=>$dateRange,//拼接日期范围字符串 'role_type'=>'market_type',//角色类型|market_type=市场,sale_type=销售 //本月 'month' => [ 'new_total' => $newTotal,//拉新总人数 'new_total_rate' => min(100, round($newTotal / 1000 * 100, 2)),//拉新总人数比例(不超过100%) 'assigned_sales' => $assignedSales,//已分配给销售的人数 'assigned_sales_rate' => $newTotal ? min(100, round($assignedSales / $newTotal * 100, 2)) : 0,//已分配给销售的人数比例(不超过100%) 'yesterday_new' => $yesterdayNew,//昨日拉新 'yesterday_new_rate' => $newTotal ? min(100, round($yesterdayNew / $newTotal * 100, 2)) : 0,//昨日拉新比例(不超过100%) 'today_new' => $todayNew,//今日拉新 'today_new_rate' => $newTotal ? min(100, round($todayNew / $newTotal * 100, 2)) : 0,//今日拉新比例(不超过100%) ], //上月 'last_month' => [ 'new_total' => $lastNewTotal,//拉新总人数 'new_total_rate' => min(100, round($lastNewTotal / 800 * 100, 2)),//拉新总人数比例(不超过100%) 'assigned_sales' => $lastAssignedSales,//已分配给销售的人数 'assigned_sales_rate' => $lastNewTotal ? min(100, round($lastAssignedSales / $lastNewTotal * 100, 2)) : 0,//已分配给销售的人数比例(不超过100%) 'yesterday_new' =>$yesterdayNew,//昨日拉新人数 'yesterday_new_rate' => $lastNewTotal ? min(100, round($yesterdayNew / $lastNewTotal * 100, 2)) : 0,//昨日拉新人数比例(不超过100%) 'today_new' => $todayNew,//今日拉新人数 'today_new_rate' => $lastNewTotal ? min(100, round($todayNew / $lastNewTotal * 100, 2)) : 0,//今日拉新人数比例(不超过100%) 'xzzy' => $todayNew, 'yjsr' => $yjsr, 'wfpsl' => $wfpsl, 'bytc' => $bytc, 'gdsl' => $gdsl ] ]; }elseif(in_array('sale',$role_key_arr) || in_array('sale_manager',$role_key_arr)){ $startTime = date('Y-m-01 00:00:00'); $endTime = date('Y-m-t 23:59:59'); $last_monthstartTime = date('Y-m-01 00:00:00', strtotime('first day of last month')); $last_monthendTime = date('Y-m-t 23:59:59', strtotime('last day of last month')); $resource_list = $resourceSharing->where(['shared_by' => $personnel_id])->select(); $assigned = 0; $contacted = 0; $unconverted = 0; $renewal = 0; $closed = 0; $lastAssigned = 0; $lastContacted = 0; $lastUnconverted = 0; $lastClosed = 0; foreach($resource_list as $item){ $sharedAt = strtotime($item['shared_at']); if ($sharedAt >= strtotime($startTime) && $sharedAt <= strtotime($endTime)) { $assigned++; $records = $communication_records->where(['resource_id' => $item['resource_id']])->order("id desc")->find(); if($records){ $contacted++; if($records['communication_result'] !== 'success'){ $unconverted++; } } if($six_speed->where(['resource_id' => $item['resource_id'],'is_closed' => 1])->find()){ $closed++; } } if ($sharedAt >= strtotime($last_monthstartTime) && $sharedAt <= strtotime($last_monthendTime)) { $lastAssigned++; $records = $communication_records->where(['resource_id' => $item['resource_id']])->order("id desc")->find(); if($records){ $lastContacted++; if($records['communication_result'] !== 'success'){ $lastUnconverted++; } } if($six_speed->where(['resource_id' => $item['resource_id'],'is_closed' => 1])->find()){ $lastClosed++; } } } //销售人员统计数据(买课的) $data = [ 'date_range'=>$dateRange,//拼接日期范围字符串 'role_type'=>'sale_type',//角色类型|market_type=市场,sale_type=销售 infoData.month //本月 'month' => [ 'assigned_clients' => $assigned,//分配给我的客户人数 'contacted_clients' => $contacted,//已沟通的客户人数 'contact_rate' => $assigned ? min(100, round($contacted / $assigned * 100, 2)) : 0,//沟通率(不超过100%) 'unconverted_clients' => $unconverted,//已沟通但没成交的客户人数 'unconverted_rate' => $contacted ? min(100, round($unconverted / $contacted * 100, 2)) : 0,//未成交率(不超过100%) 'renewal_clients' => ($renewal = rand(5, 30)),//待续费的客户人数 'renewal_rate' => $assigned ? min(100, round($renewal / $assigned * 100, 2)) : 0,//待续费率(不超过100%) 'closed_clients' => $closed,//已关单的客户人数 'closed_rate' => $contacted ? min(100, round($closed / $contacted * 100, 2)) : 0,//关单率(不超过100%) 'conversion_rate' => $assigned ? min(100, round($closed / $assigned * 100, 2)) : 0,//整体转化率(不超过100%) ], //上月 'last_month' => [ 'assigned_clients' => $lastAssigned,//分配给我的客户人数 'contacted_clients' => $lastContacted,//已沟通的客户人数 'contact_rate' => $lastAssigned ? min(100, round($lastContacted / $lastAssigned * 100, 2)) : 0,//沟通率(不超过100%) 'unconverted_clients' => $lastUnconverted,//已沟通但没成交的客户人数 'unconverted_rate' => $lastContacted ? min(100, round($lastUnconverted / $lastContacted * 100, 2)) : 0,//未成交率(不超过100%) 'renewal_clients' => ($lastRenewal = rand(3, 25)),//待续费的客户人数 'renewal_rate' => $lastAssigned ? min(100, round($lastRenewal / $lastAssigned * 100, 2)) : 0,//待续费率(不超过100%) 'closed_clients' => $lastClosed,//已关单的客户人数 'closed_rate' => $lastContacted ? min(100, round($lastClosed / $lastContacted * 100, 2)) : 0,//关单率(不超过100%) 'conversion_rate' => $lastAssigned ? min(100, round($lastClosed / $lastAssigned * 100, 2)) : 0,//整体转化率(不超过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); } }