销售漏斗

pull/30/head
张萌 2 years ago
parent 8ba1c99540
commit f4e75bca13

@ -102,18 +102,18 @@ class Index extends ApiCommon
$userInfo = $this->userInfo; $userInfo = $this->userInfo;
$adminModel = new \app\admin\model\Admin(); $adminModel = new \app\admin\model\Admin();
$status = $param['label'] ?: 1; //1合同目标2回款目标 $status = $param['label'] ?: 1; //1合同目标2回款目标
$userWhere['type']=3; $userWhere['type'] = 3;
$userWhere['status']=$param['label']; $userWhere['status'] = $param['label'];
$userIds = []; $userIds = [];
if ($param['dataType'] == 3 || $param['dataType'] == 4) { if ($param['dataType'] == 3 || $param['dataType'] == 4) {
$param['structure_id'] = $userInfo['structure_id']; $param['structure_id'] = $userInfo['structure_id'];
$userWhere['type']=2; $userWhere['type'] = 2;
} }
$whereArr = $adminModel->getWhere($param, 1, ''); $whereArr = $adminModel->getWhere($param, 1, '');
if($param['user_id']){ if ($param['user_id']) {
$userWhere['type']=3; $userWhere['type'] = 3;
}elseif ($param['structure_id']){ } elseif ($param['structure_id']) {
$userWhere['type']=2; $userWhere['type'] = 2;
} }
$param['user_id'] = $param['user_id'] ?: $userInfo['id']; $param['user_id'] = $param['user_id'] ?: $userInfo['id'];
if ($param['dataType'] == 1) { if ($param['dataType'] == 1) {
@ -128,12 +128,12 @@ class Index extends ApiCommon
$end_time = $between_time[1]; $end_time = $between_time[1];
} else { } else {
//自定义时间 //自定义时间
$start_time = $param['start_time'] ?strtotime($param['start_time'].'00:00:00'): strtotime(date('Y-01-01', time())); $start_time = $param['start_time'] ? strtotime($param['start_time'] . '00:00:00') : strtotime(date('Y-01-01', time()));
$end_time = $param['end_time'] ? strtotime($param['end_time'].'23:59:59') : strtotime(date('Y-m-01', time()) . ' +1 month -1 day'); $end_time = $param['end_time'] ? strtotime($param['end_time'] . '23:59:59') : strtotime(date('Y-m-01', time()) . ' +1 month -1 day');
$between_time = array($start_time, $end_time); $between_time = array($start_time, $end_time);
} }
if($param['label']==1){ if ($param['label'] == 1) {
//合同金额 //合同金额
$where_contract = $where; $where_contract = $where;
$where_contract['order_date'] = array('between', [date('Y-m-d', $between_time[0]), date('Y-m-d', $between_time[1])]); $where_contract['order_date'] = array('between', [date('Y-m-d', $between_time[0]), date('Y-m-d', $between_time[1])]);
@ -144,7 +144,7 @@ class Index extends ApiCommon
->fetchSql() ->fetchSql()
->select(); ->select();
$contractMoney = queryCache($sql, 200); $contractMoney = queryCache($sql, 200);
}else{ } else {
//回款金额 //回款金额
$where_receivables = $where; $where_receivables = $where;
$where_receivables['return_time'] = array('between', [date('Y-m-d', $between_time[0]), date('Y-m-d', $between_time[1])]); $where_receivables['return_time'] = array('between', [date('Y-m-d', $between_time[0]), date('Y-m-d', $between_time[1])]);
@ -214,11 +214,21 @@ class Index extends ApiCommon
$param['user_id'] = $param['user_id'] ?: $userInfo['id'];; $param['user_id'] = $param['user_id'] ?: $userInfo['id'];;
$businessModel = new \app\crm\model\Business(); $businessModel = new \app\crm\model\Business();
$param['merge'] = 1; $param['merge'] = 1;
if($param['start_time'] && $param['end_time']){ if ($param['start_time'] && $param['end_time']) {
$param['start_time']=$param['start_time'].' 00:00:00'; $param['start_time'] = $param['start_time'] . ' 00:00:00';
$param['end_time']=$param['end_time'].' 23:59:59'; $param['end_time'] = $param['end_time'] . ' 23:59:59';
} }
$list = $businessModel->getFunnel($param); $list = $businessModel->getFunnel($param);
$list['list'][] = [
"name" => "赢单",
"status_id" => "10000",
"status_name" => "赢单",
];
$list['list'][] = [
"name" => "输单",
"status_id" => "10001",
"status_name" => "输单",
];
return resultArray(['data' => $list]); return resultArray(['data' => $list]);
} }
@ -234,27 +244,27 @@ class Index extends ApiCommon
//统计条件 //统计条件
$param = $this->param; $param = $this->param;
$userInfo = $this->userInfo; $userInfo = $this->userInfo;
$userWhere['status']=$param['label']; $userWhere['status'] = $param['label'];
if ($param['dataType'] == 3 || $param['dataType'] == 4) { if ($param['dataType'] == 3 || $param['dataType'] == 4) {
$userWhere['type']=2; $userWhere['type'] = 2;
}else{ } else {
$userWhere['type']=3; $userWhere['type'] = 3;
} }
if ($param['type']) { if ($param['type']) {
$last_where_contract = getTimeByType($param['type']); $last_where_contract = getTimeByType($param['type']);
$userWhere['year']=date('Y',$last_where_contract[0]); $userWhere['year'] = date('Y', $last_where_contract[0]);
$time = getTimeArray(); $time = getTimeArray();
} else { } else {
//自定义时间 //自定义时间
$param['start_time']=$param['start_time']?$param['start_time'].' 00:00:00':0; $param['start_time'] = $param['start_time'] ? $param['start_time'] . ' 00:00:00' : 0;
$param['end_time']=$param['end_time'].' 23:59:59'; $param['end_time'] = $param['end_time'] . ' 23:59:59';
$time = getTimeArray(strtotime($param['start_time']),strtotime($param['end_time'])); $time = getTimeArray(strtotime($param['start_time']), strtotime($param['end_time']));
} }
$whereArr = $adminModel->getWhere($param, 1, ''); $whereArr = $adminModel->getWhere($param, 1, '');
if($param['user_id']){ if ($param['user_id']) {
$userWhere['type']=3; $userWhere['type'] = 3;
}elseif ($param['structure_id']){ } elseif ($param['structure_id']) {
$userWhere['type']=2; $userWhere['type'] = 2;
} }
$userIds = $whereArr['userIds']; $userIds = $whereArr['userIds'];
if (!empty($param['user_id'])) { if (!empty($param['user_id'])) {
@ -271,7 +281,7 @@ class Index extends ApiCommon
$auth_customer_user_ids = $auth_customer_user_ids ? array_intersect($userIds, $auth_customer_user_ids) : []; //取交集 $auth_customer_user_ids = $auth_customer_user_ids ? array_intersect($userIds, $auth_customer_user_ids) : []; //取交集
$between_time = [date('Y-m-d', $whereArr['between_time'][0]), date('Y-m-d', $whereArr['between_time'][1])]; $between_time = [date('Y-m-d', $whereArr['between_time'][0]), date('Y-m-d', $whereArr['between_time'][1])];
if($param['label']==1){ if ($param['label'] == 1) {
$field_contract["SUBSTR(`order_date`, 1, " . $ax . ")"] = 'type'; $field_contract["SUBSTR(`order_date`, 1, " . $ax . ")"] = 'type';
$field_contract['SUM(`money`)'] = 'sum'; $field_contract['SUM(`money`)'] = 'sum';
$achievementData = CrmContractModel::field($field_contract) $achievementData = CrmContractModel::field($field_contract)
@ -286,7 +296,7 @@ class Index extends ApiCommon
$res_contract = queryCache($achievementData, 200); $res_contract = queryCache($achievementData, 200);
$res_money = array_column($res_contract, null, 'type'); $res_money = array_column($res_contract, null, 'type');
}else{ } else {
$field_receivables["SUBSTR(`return_time`, 1, " . $ax . ")"] = 'type'; $field_receivables["SUBSTR(`return_time`, 1, " . $ax . ")"] = 'type';
$field_receivables['SUM(`money`)'] = 'sum'; $field_receivables['SUM(`money`)'] = 'sum';
@ -309,20 +319,20 @@ class Index extends ApiCommon
foreach ($time['list'] as $val) { foreach ($time['list'] as $val) {
$item = []; $item = [];
$item['type'] = date('m-d',strtotime($val['type'])); $item['type'] = date('m-d', strtotime($val['type']));
$item['money'] = $res_money[$val['type']]['sum'] ?: 0; $item['money'] = $res_money[$val['type']]['sum'] ?: 0;
$money += $item['money']; $money += $item['money'];
$achievement=Db::name('crm_achievement')->where($userWhere)->select(); $achievement = Db::name('crm_achievement')->where($userWhere)->select();
$data_time=date('m',strtotime($val['type'])); $data_time = date('m', strtotime($val['type']));
$num=''; $num = '';
if($achievement){ if ($achievement) {
foreach ($achievement as $val){ foreach ($achievement as $val) {
$num+=(int)$val[$this->monthName[$data_time]]; $num += (int)$val[$this->monthName[$data_time]];
$item['achievement']=$num; $item['achievement'] = $num;
} }
}else{ } else {
$item['achievement']=0; $item['achievement'] = 0;
} }
$list[] = $item; $list[] = $item;
} }
@ -341,9 +351,9 @@ class Index extends ApiCommon
{ {
$param = $this->param; $param = $this->param;
$adminModel = new \app\admin\model\Admin(); $adminModel = new \app\admin\model\Admin();
if($param['start_time'] && $param['end_time']){ if ($param['start_time'] && $param['end_time']) {
$param['start_time']=$param['start_time'].'00:00:00'; $param['start_time'] = $param['start_time'] . '00:00:00';
$param['end_time']=$param['end_time'].'23:59:59'; $param['end_time'] = $param['end_time'] . '23:59:59';
} }
$whereArr = $adminModel->getWhere($param, '', ''); //统计条件 $whereArr = $adminModel->getWhere($param, '', ''); //统计条件
$userIds = $whereArr['userIds']; $userIds = $whereArr['userIds'];
@ -540,10 +550,10 @@ class Index extends ApiCommon
$label = $param['label']; $label = $param['label'];
$types = $param['types']; $types = $param['types'];
$userInfo = $this->userInfo; $userInfo = $this->userInfo;
$user_id = $param['user_id'] ? : $userInfo['id']; $user_id = $param['user_id'] ?: $userInfo['id'];
if($param['start_time'] && $param['end_time']){ if ($param['start_time'] && $param['end_time']) {
$param['start_time']=$param['start_time'].' 00:00:00'; $param['start_time'] = $param['start_time'] . ' 00:00:00';
$param['end_time']=$param['end_time'].' 23:59:59'; $param['end_time'] = $param['end_time'] . ' 23:59:59';
} }
$whereArr = $adminModel->getWhere($param, 1, ''); //统计条件 $whereArr = $adminModel->getWhere($param, 1, ''); //统计条件
$userIds = $whereArr['userIds']; $userIds = $whereArr['userIds'];
@ -599,8 +609,8 @@ class Index extends ApiCommon
if ($c != 'activity') { if ($c != 'activity') {
$where['owner_user_id']['value'] = $auth_user_ids; $where['owner_user_id']['value'] = $auth_user_ids;
if($types=='crm_contract' || $types=='crm_receivables'){ if ($types == 'crm_contract' || $types == 'crm_receivables') {
$where['check_status']=2; $where['check_status'] = 2;
} }
$data = $model->getDataList($where); $data = $model->getDataList($where);
} else { } else {
@ -613,21 +623,21 @@ class Index extends ApiCommon
foreach ($typesList as $k => $v) { foreach ($typesList as $k => $v) {
$where1['activity_type'] = $v; $where1['activity_type'] = $v;
$dataCount = db('crm_activity')->where($where1)->count(); $dataCount = db('crm_activity')->where($where1)->count();
if($v==1){ if ($v == 1) {
$arr[$k]['types'] ='crm_leads'; $arr[$k]['types'] = 'crm_leads';
$arr[$k]['activity_type'] =1; $arr[$k]['activity_type'] = 1;
}elseif ($v==2){ } elseif ($v == 2) {
$arr[$k]['types'] ='crm_customer'; $arr[$k]['types'] = 'crm_customer';
$arr[$k]['activity_type'] =2; $arr[$k]['activity_type'] = 2;
}elseif ($v==3){ } elseif ($v == 3) {
$arr[$k]['types'] ='crm_contacts'; $arr[$k]['types'] = 'crm_contacts';
$arr[$k]['activity_type'] =3; $arr[$k]['activity_type'] = 3;
}elseif ($v==5){ } elseif ($v == 5) {
$arr[$k]['types'] ='crm_business'; $arr[$k]['types'] = 'crm_business';
$arr[$k]['activity_type'] =5; $arr[$k]['activity_type'] = 5;
}elseif ($v==6){ } elseif ($v == 6) {
$arr[$k]['types'] ='crm_contract'; $arr[$k]['types'] = 'crm_contract';
$arr[$k]['activity_type'] =6; $arr[$k]['activity_type'] = 6;
} }
$arr[$k]['dataCount'] = $dataCount; $arr[$k]['dataCount'] = $dataCount;
$arr[$k]['create_user_id'] = implode(',', $userIds); $arr[$k]['create_user_id'] = implode(',', $userIds);
@ -673,7 +683,7 @@ class Index extends ApiCommon
{ {
$param = $this->param; $param = $this->param;
$userInfo = $this->userInfo; $userInfo = $this->userInfo;
$param['user_id'] = $param['user_id']?:$userInfo['id']; $param['user_id'] = $param['user_id'] ?: $userInfo['id'];
$indexModel = new IndexLogic; $indexModel = new IndexLogic;
$data = $indexModel->ranking($param); $data = $indexModel->ranking($param);
return resultArray(['data' => $data]); return resultArray(['data' => $data]);
@ -687,7 +697,7 @@ class Index extends ApiCommon
{ {
$param = $this->param; $param = $this->param;
$userInfo = $this->userInfo; $userInfo = $this->userInfo;
$param['user_id'] = $param['user_id']?:$userInfo['id']; $param['user_id'] = $param['user_id'] ?: $userInfo['id'];
$indexModel = new IndexLogic; $indexModel = new IndexLogic;
$data = $indexModel->queryDataInfo($param); $data = $indexModel->queryDataInfo($param);
return resultArray(['data' => $data]); return resultArray(['data' => $data]);
@ -702,7 +712,11 @@ class Index extends ApiCommon
$userInfo = $this->userInfo; $userInfo = $this->userInfo;
$param['user_id'] = $param['user_id'] ?: $userInfo['id']; $param['user_id'] = $param['user_id'] ?: $userInfo['id'];
$indexModel = new IndexLogic; $indexModel = new IndexLogic;
if ($param['status_id'] == "10000" || $param['status_id'] == "10001") {
$data['funnel'] = $param['status_id'];
}
$data = $indexModel->businessList($param); $data = $indexModel->businessList($param);
return resultArray(['data' => $data]); return resultArray(['data' => $data]);
} }
@ -754,12 +768,13 @@ class Index extends ApiCommon
* 跟进详情 * 跟进详情
* @return \think\response\Json * @return \think\response\Json
*/ */
public function activityList(){ public function activityList()
{
$param = $this->param; $param = $this->param;
$userInfo = $this->userInfo; $userInfo = $this->userInfo;
$param['id']=$userInfo['id']; $param['id'] = $userInfo['id'];
$indexLogic=new IndexLogic(); $indexLogic = new IndexLogic();
$data=$indexLogic->activityList($param); $data = $indexLogic->activityList($param);
return resultArray(['data'=>$data]); return resultArray(['data' => $data]);
} }
} }

@ -52,6 +52,7 @@ class Business extends Common
$overdue = $request['overdue']; // 待办事项下需联系商机(逾期) $overdue = $request['overdue']; // 待办事项下需联系商机(逾期)
$businessIdArray = $request['businessIdArray']; // 待办事项提醒参数 $businessIdArray = $request['businessIdArray']; // 待办事项提醒参数
$isMessage = !empty($request['isMessage']); $isMessage = !empty($request['isMessage']);
$funnelQuery = $request['funnel']; // 销售漏斗查询赢单输单
unset($request['scene_id']); unset($request['scene_id']);
unset($request['search']); unset($request['search']);
unset($request['user_id']); unset($request['user_id']);
@ -142,6 +143,18 @@ class Business extends Common
}; };
} }
} }
// 销售漏斗处理
if (!empty($funnelQuery)){
unset($map['business.status_id']);
unset($map['business.is_end']);
switch ($funnelQuery){
case '10000':// 赢单
$map['business.is_end']=1;
case "10001":// 输单
$map['business.is_end']=2;
}
}
//联系人商机 //联系人商机
if ($contacts_id) { if ($contacts_id) {
@ -439,7 +452,7 @@ class Business extends Common
//站内信 //站内信
$userInfo = db('admin_user')->where(['id' => $param['create_user_id']])->find(); $userInfo = db('admin_user')->where(['id' => $param['create_user_id']])->find();
$send_user_id = stringToArray(getUserSuperior($userInfo['structure_id'],0)); $send_user_id = stringToArray(getUserSuperior($userInfo['structure_id'], 0));
(new Message())->send( (new Message())->send(
Message::CUSTOMER_CHECK_TO_DO, Message::CUSTOMER_CHECK_TO_DO,
[ [

Loading…
Cancel
Save