From 8ba1c99540f606c0167e9890cb31c43cec54bd08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E8=90=8C?= <494089941@qq.com> Date: Sun, 26 Mar 2023 12:11:33 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/crm/controller/Customer.php | 1 + 1 file changed, 1 insertion(+) diff --git a/application/crm/controller/Customer.php b/application/crm/controller/Customer.php index 063de9e..91d1623 100644 --- a/application/crm/controller/Customer.php +++ b/application/crm/controller/Customer.php @@ -129,6 +129,7 @@ class Customer extends ApiCommon $data['flow_id'] = $customerCheck['flow_id']; $data['owner_user_id']=$customerCheck['user_id']; $data['customer_check_id']=$customerCheck['customer_check_id']; + $data['apply_user_name']=db('admin_user')->where('id', $customerCheck['create_user_id'])->column("username"); } return resultArray(['data' => $data]); } From f4e75bca138bf692397cc72c08b145f3ae0ccd84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E8=90=8C?= <494089941@qq.com> Date: Sun, 26 Mar 2023 13:14:22 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E9=94=80=E5=94=AE=E6=BC=8F=E6=96=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/crm/controller/Index.php | 159 +++++++++++++++------------ application/crm/model/Business.php | 15 ++- 2 files changed, 101 insertions(+), 73 deletions(-) diff --git a/application/crm/controller/Index.php b/application/crm/controller/Index.php index a176772..bec0384 100644 --- a/application/crm/controller/Index.php +++ b/application/crm/controller/Index.php @@ -102,18 +102,18 @@ class Index extends ApiCommon $userInfo = $this->userInfo; $adminModel = new \app\admin\model\Admin(); $status = $param['label'] ?: 1; //1合同目标2回款目标 - $userWhere['type']=3; - $userWhere['status']=$param['label']; + $userWhere['type'] = 3; + $userWhere['status'] = $param['label']; $userIds = []; if ($param['dataType'] == 3 || $param['dataType'] == 4) { $param['structure_id'] = $userInfo['structure_id']; - $userWhere['type']=2; + $userWhere['type'] = 2; } $whereArr = $adminModel->getWhere($param, 1, ''); - if($param['user_id']){ - $userWhere['type']=3; - }elseif ($param['structure_id']){ - $userWhere['type']=2; + if ($param['user_id']) { + $userWhere['type'] = 3; + } elseif ($param['structure_id']) { + $userWhere['type'] = 2; } $param['user_id'] = $param['user_id'] ?: $userInfo['id']; if ($param['dataType'] == 1) { @@ -128,12 +128,12 @@ class Index extends ApiCommon $end_time = $between_time[1]; } else { //自定义时间 - $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'); + $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'); $between_time = array($start_time, $end_time); } - if($param['label']==1){ + if ($param['label'] == 1) { //合同金额 $where_contract = $where; $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() ->select(); $contractMoney = queryCache($sql, 200); - }else{ + } else { //回款金额 $where_receivables = $where; $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'];; $businessModel = new \app\crm\model\Business(); $param['merge'] = 1; - if($param['start_time'] && $param['end_time']){ - $param['start_time']=$param['start_time'].' 00:00:00'; - $param['end_time']=$param['end_time'].' 23:59:59'; + if ($param['start_time'] && $param['end_time']) { + $param['start_time'] = $param['start_time'] . ' 00:00:00'; + $param['end_time'] = $param['end_time'] . ' 23:59:59'; } $list = $businessModel->getFunnel($param); + $list['list'][] = [ + "name" => "赢单", + "status_id" => "10000", + "status_name" => "赢单", + ]; + $list['list'][] = [ + "name" => "输单", + "status_id" => "10001", + "status_name" => "输单", + ]; return resultArray(['data' => $list]); } @@ -234,27 +244,27 @@ class Index extends ApiCommon //统计条件 $param = $this->param; $userInfo = $this->userInfo; - $userWhere['status']=$param['label']; + $userWhere['status'] = $param['label']; if ($param['dataType'] == 3 || $param['dataType'] == 4) { - $userWhere['type']=2; - }else{ - $userWhere['type']=3; + $userWhere['type'] = 2; + } else { + $userWhere['type'] = 3; } if ($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(); } else { //自定义时间 - $param['start_time']=$param['start_time']?$param['start_time'].' 00:00:00':0; - $param['end_time']=$param['end_time'].' 23:59:59'; - $time = getTimeArray(strtotime($param['start_time']),strtotime($param['end_time'])); + $param['start_time'] = $param['start_time'] ? $param['start_time'] . ' 00:00:00' : 0; + $param['end_time'] = $param['end_time'] . ' 23:59:59'; + $time = getTimeArray(strtotime($param['start_time']), strtotime($param['end_time'])); } $whereArr = $adminModel->getWhere($param, 1, ''); - if($param['user_id']){ - $userWhere['type']=3; - }elseif ($param['structure_id']){ - $userWhere['type']=2; + if ($param['user_id']) { + $userWhere['type'] = 3; + } elseif ($param['structure_id']) { + $userWhere['type'] = 2; } $userIds = $whereArr['userIds']; 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) : []; //取交集 $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['SUM(`money`)'] = 'sum'; $achievementData = CrmContractModel::field($field_contract) @@ -286,7 +296,7 @@ class Index extends ApiCommon $res_contract = queryCache($achievementData, 200); $res_money = array_column($res_contract, null, 'type'); - }else{ + } else { $field_receivables["SUBSTR(`return_time`, 1, " . $ax . ")"] = 'type'; $field_receivables['SUM(`money`)'] = 'sum'; @@ -306,23 +316,23 @@ class Index extends ApiCommon } $list = array(); $money = '0.00'; - + foreach ($time['list'] as $val) { $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; $money += $item['money']; - $achievement=Db::name('crm_achievement')->where($userWhere)->select(); - $data_time=date('m',strtotime($val['type'])); - $num=''; - if($achievement){ - foreach ($achievement as $val){ - $num+=(int)$val[$this->monthName[$data_time]]; - $item['achievement']=$num; + $achievement = Db::name('crm_achievement')->where($userWhere)->select(); + $data_time = date('m', strtotime($val['type'])); + $num = ''; + if ($achievement) { + foreach ($achievement as $val) { + $num += (int)$val[$this->monthName[$data_time]]; + $item['achievement'] = $num; } - }else{ - $item['achievement']=0; + } else { + $item['achievement'] = 0; } $list[] = $item; } @@ -341,9 +351,9 @@ class Index extends ApiCommon { $param = $this->param; $adminModel = new \app\admin\model\Admin(); - if($param['start_time'] && $param['end_time']){ - $param['start_time']=$param['start_time'].'00:00:00'; - $param['end_time']=$param['end_time'].'23:59:59'; + if ($param['start_time'] && $param['end_time']) { + $param['start_time'] = $param['start_time'] . '00:00:00'; + $param['end_time'] = $param['end_time'] . '23:59:59'; } $whereArr = $adminModel->getWhere($param, '', ''); //统计条件 $userIds = $whereArr['userIds']; @@ -370,7 +380,7 @@ class Index extends ApiCommon { $param = $this->param; $adminModel = new \app\admin\model\Admin(); - + $whereArr = $adminModel->getWhere($param, '', ''); //统计条件 $userIds = $whereArr['userIds']; $where = []; @@ -540,14 +550,14 @@ class Index extends ApiCommon $label = $param['label']; $types = $param['types']; $userInfo = $this->userInfo; - $user_id = $param['user_id'] ? : $userInfo['id']; - if($param['start_time'] && $param['end_time']){ - $param['start_time']=$param['start_time'].' 00:00:00'; - $param['end_time']=$param['end_time'].' 23:59:59'; + $user_id = $param['user_id'] ?: $userInfo['id']; + if ($param['start_time'] && $param['end_time']) { + $param['start_time'] = $param['start_time'] . ' 00:00:00'; + $param['end_time'] = $param['end_time'] . ' 23:59:59'; } $whereArr = $adminModel->getWhere($param, 1, ''); //统计条件 $userIds = $whereArr['userIds']; - $between_time = $whereArr['between_time']; + $between_time = $whereArr['between_time']; $start_time = $between_time[0]; $end_time = $between_time[1]; @@ -599,8 +609,8 @@ class Index extends ApiCommon if ($c != 'activity') { $where['owner_user_id']['value'] = $auth_user_ids; - if($types=='crm_contract' || $types=='crm_receivables'){ - $where['check_status']=2; + if ($types == 'crm_contract' || $types == 'crm_receivables') { + $where['check_status'] = 2; } $data = $model->getDataList($where); } else { @@ -613,21 +623,21 @@ class Index extends ApiCommon foreach ($typesList as $k => $v) { $where1['activity_type'] = $v; $dataCount = db('crm_activity')->where($where1)->count(); - if($v==1){ - $arr[$k]['types'] ='crm_leads'; - $arr[$k]['activity_type'] =1; - }elseif ($v==2){ - $arr[$k]['types'] ='crm_customer'; - $arr[$k]['activity_type'] =2; - }elseif ($v==3){ - $arr[$k]['types'] ='crm_contacts'; - $arr[$k]['activity_type'] =3; - }elseif ($v==5){ - $arr[$k]['types'] ='crm_business'; - $arr[$k]['activity_type'] =5; - }elseif ($v==6){ - $arr[$k]['types'] ='crm_contract'; - $arr[$k]['activity_type'] =6; + if ($v == 1) { + $arr[$k]['types'] = 'crm_leads'; + $arr[$k]['activity_type'] = 1; + } elseif ($v == 2) { + $arr[$k]['types'] = 'crm_customer'; + $arr[$k]['activity_type'] = 2; + } elseif ($v == 3) { + $arr[$k]['types'] = 'crm_contacts'; + $arr[$k]['activity_type'] = 3; + } elseif ($v == 5) { + $arr[$k]['types'] = 'crm_business'; + $arr[$k]['activity_type'] = 5; + } elseif ($v == 6) { + $arr[$k]['types'] = 'crm_contract'; + $arr[$k]['activity_type'] = 6; } $arr[$k]['dataCount'] = $dataCount; $arr[$k]['create_user_id'] = implode(',', $userIds); @@ -673,7 +683,7 @@ class Index extends ApiCommon { $param = $this->param; $userInfo = $this->userInfo; - $param['user_id'] = $param['user_id']?:$userInfo['id']; + $param['user_id'] = $param['user_id'] ?: $userInfo['id']; $indexModel = new IndexLogic; $data = $indexModel->ranking($param); return resultArray(['data' => $data]); @@ -687,7 +697,7 @@ class Index extends ApiCommon { $param = $this->param; $userInfo = $this->userInfo; - $param['user_id'] = $param['user_id']?:$userInfo['id']; + $param['user_id'] = $param['user_id'] ?: $userInfo['id']; $indexModel = new IndexLogic; $data = $indexModel->queryDataInfo($param); return resultArray(['data' => $data]); @@ -702,7 +712,11 @@ class Index extends ApiCommon $userInfo = $this->userInfo; $param['user_id'] = $param['user_id'] ?: $userInfo['id']; $indexModel = new IndexLogic; + if ($param['status_id'] == "10000" || $param['status_id'] == "10001") { + $data['funnel'] = $param['status_id']; + } $data = $indexModel->businessList($param); + return resultArray(['data' => $data]); } @@ -754,12 +768,13 @@ class Index extends ApiCommon * 跟进详情 * @return \think\response\Json */ - public function activityList(){ + public function activityList() + { $param = $this->param; $userInfo = $this->userInfo; - $param['id']=$userInfo['id']; - $indexLogic=new IndexLogic(); - $data=$indexLogic->activityList($param); - return resultArray(['data'=>$data]); + $param['id'] = $userInfo['id']; + $indexLogic = new IndexLogic(); + $data = $indexLogic->activityList($param); + return resultArray(['data' => $data]); } } \ No newline at end of file diff --git a/application/crm/model/Business.php b/application/crm/model/Business.php index f7966aa..eedac18 100644 --- a/application/crm/model/Business.php +++ b/application/crm/model/Business.php @@ -52,6 +52,7 @@ class Business extends Common $overdue = $request['overdue']; // 待办事项下需联系商机(逾期) $businessIdArray = $request['businessIdArray']; // 待办事项提醒参数 $isMessage = !empty($request['isMessage']); + $funnelQuery = $request['funnel']; // 销售漏斗查询赢单输单 unset($request['scene_id']); unset($request['search']); 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) { @@ -439,7 +452,7 @@ class Business extends Common //站内信 $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( Message::CUSTOMER_CHECK_TO_DO, [